Example #1
0
  function pagechange(url) {
    // restore page's original title
    title();

    // lock article's section
    locker.lock();

    // hide it from user
    classes(o('section.app-content')).add('hide');

    // once render, unlock and show
    bus.once('page:render', function() {
      locker.unlock();
      classes(o('section.app-content')).remove('hide');
    });

    // check if loading to same page
    // and if not, scroll to top
    if (url !== ctx.path) o('section#browser').scrollTop = 0;

    // don't remove 'browser-page' body class
    // if we still are in a browsing laws page
    if (/^\/law/.test(url)) return;
    classes(document.body).remove('browser-page');
  };
Example #2
0
File: view.js Project: 89berner/app
CommentsView.prototype.load = function(comments) {
  if (!comments.length) {
    var span = document.createElement('span');
    var text = citizen.id ? t('comments.no-citizen-comments') : t('comments.no-comments');
    span.innerHTML = text;
    classes(span).add('no-comments')
    var existing = o('.no-comments', this.el);
    if (existing) existing.remove();
    o('.main-list', this.el).insertBefore(span);
    return this.emit('no more comments');
  }

  log('load %o', comments);

  var els = o.all('ul.main-list li.comment-item', this.el);
  this.comments.push.apply(this.comments, comments);

  comments.forEach(function(comment) {
    this.add(comment);
  }, this);

  if (this.page == 0) {
    this.clearComments(els);
  }

  if (this.comments.length == this.count) {
    this.emit('no more comments');
  } else {
    this.emit('more comments')
  }

  this.page++;
  this.emit('load');
}
Example #3
0
File: view.js Project: 89berner/app
CommentsView.prototype.add = function(comment) {
  var blockEl = o('ul.media-list.comment-list.main-list', this.el);
  var deletedBlockEl = o('ul.media-list.comment-list.deleted-list', this.el);
  var commentEl = render.dom(item, { comment: comment, markdown: markdown });

  if (!comment.deleted) {
    blockEl.appendChild(commentEl);
    var el = o('.comment-text', commentEl);
    var oldLength = el.innerHTML.length;
    trunkata(el, { lines: 4 });
    var newLength = el.innerHTML.length;
    if (oldLength > newLength) {
      var a = document.createElement('a');
      classes(a).add('read-more');
      a.href = '#';
      a.innerHTML = t('read more');
      el.appendChild(a);
    }
  } else {
    classes(o('.toggle-deleted-comments', this.el)).remove('hide');
    if (deletedBlockEl.children.length) {
      deletedBlockEl.insertBefore(commentEl, blockEl.children[0]);
    } else {
      deletedBlockEl.appendChild(commentEl);
    }
  }
}
Example #4
0
File: view.js Project: 89berner/app
CommentsView.prototype.onsuccessedit = function(data) {
  var el = data.el;
  var data = data.data;

  var commentEl = el.parentNode;
  var id = commentEl.parentNode.getAttribute('data-id');
  var commentText = o('.comment-text', commentEl);
  var commentTime = o('.ago', commentEl);
  commentText.innerHTML = markdown(data.text);

  var edited = o('.edited', commentEl);
  if (!edited) {
    var small = document.createElement('small');
    classes(small).add('edited');
    small.innerHTML = ' · ' + t('comments.edited');
    commentTime.parentNode.insertBefore(small, commentTime.nextSibling);
  }

  var btn = o('.btn-edit', commentEl.parentNode);
  classes(btn).remove('hide');
  classes(el.parentNode).remove('edit');
  commentEl.removeChild(el);

  var comment = get(this.myArguments, 'id === "%id"'.replace('%id', id));
  comment.text = data.text;
  comment.editedAt = data.editedAt;
};
Example #5
0
CommentsRepliesView.prototype.onsuccessedit = function(data) {
  var el = data.el;
  var data = data.data;

  var replyContainer = el.parentNode;
  var replyEl = replyContainer.parentNode;
  var id = data.id;
  var replyText = o('.reply-text', replyEl);
  var replyTime = o('.ago', replyEl);
  replyText.innerHTML = markdown(data.text);

  var edited = o('.edited', replyEl);
  if (!edited) {
    var small = document.createElement('small');
    classes(small).add('edited');
    small.innerHTML = '· ' + t('comments.edited');
    replyTime.parentNode.insertBefore(small, replyTime.nextSibling);
  }

  var btn = o('.btn-reply-edit', replyEl);
  classes(btn).remove('hide');
  classes(el.parentNode).remove('edit');
  replyContainer.removeChild(el);

  var reply = get(this.replies, 'id === "%id"'.replace('%id', id));
  reply.text = data.text;
  reply.editedAt = data.editedAt;
};
Example #6
0
File: view.js Project: 89berner/app
CommentsView.prototype.cancelNewArgument = function(ev) {
  ev.preventDefault();

  var el = o('.comment-form', this.el);
  classes(el).toggle('hide');
  classes(o('.new-argument', this.el)).remove('hide');
};
Example #7
0
File: view.js Project: 3manuek/app
CommentsView.prototype.ondislike = function(ev) {
  ev.preventDefault();

  var target = ev.delegateTarget || closest(ev.target, 'a');
  var comment = closest(target,'li[data-id]');
  var id = comment.getAttribute('data-id');
  var liked = classes(o('a.like', comment)).has('selected');
  var disliked = classes(o('a.dislike', comment)).has('selected');

  classes(target).add('selected');
  classes(o('a.like', comment)).remove('selected');

  var counter = o('.comment-counter', comment);
  var count = parseInt(counter.innerHTML, 10) || 0;
  count -= liked ? 2 : (disliked ? 0 : 1);
  counter.innerHTML = count;
  
  request
  .post('/api/comment/:id/downvote'.replace(':id', id))
  .end(function(err, res) {
    if (err) return log('Fetch error: %s', err), classes(target).remove('selected');
    if (!res.ok) return log('Fetch error: %s', res.error), classes(target).remove('selected');
    if (res.body && res.body.error) return log('Fetch response error: %s', res.body.error), classes(target).remove('selected');
    log('successfull downvote %s', id);
  });
}
Example #8
0
ProposalOptions.prototype.onvote = function(value) {
  classes(o('.vote-options', this.el)).add('hide');
  var meta = o('.meta-data', this.el);
  var item = o('a.meta-item', this.el);
  classes(item).remove('hide');
  var el;
  
  this.unvote();
  
  switch (value) {
    case 'negative':
      this.proposal.downvotes.push(this.citizen.id);
      el = render.dom(negative);
      break;
    case 'positive':
      this.proposal.upvotes.push(this.citizen.id);
      el = render.dom(positive);
      break;
    case 'neutral':
      this.proposal.abstentions.push(this.citizen.id);
      el = render.dom(neutral);
      break;
  }
  var alert = o('.alert', meta);
  if (alert) {
    meta.removeChild(alert);
  }
  meta.insertBefore(el, meta.firstChild);
  var cast = o('.votes-cast em', this.el);
  var upvotes = this.proposal.upvotes || [];
  var downvotes = this.proposal.downvotes || [];
  var abstentions = this.proposal.abstentions || [];
  var census = abstentions.concat(downvotes).concat(upvotes) || [];
  cast.innerHTML = t(t('{num} votes cast', { num: census.length || "0" }))
}
Example #9
0
File: view.js Project: 89berner/app
 setTimeout(function () {
   commentEl.remove();
   if (!self.myArguments.length) {
     classes(o('.comment-form', self.el)).remove('hide');
     classes(o('.new-argument', self.el)).add('hide');
     classes(o('.cancel-new-argument', self.el)).add('hide');
   }
 }, 2500)
Example #10
0
function Table (collection, renderer, scope, head) {
  this.el = domify(template);
  this.headEl = query('thead', this.el);
  this.bodyEl = query('tbody', this.el);
  this.reactiveTable = reactiveTable(collection, this.bodyEl, renderer, scope);
  this.setHead(head);
  return this;
};
Example #11
0
function Funnel(){
  this.el = domify(funnelTemplate);
  this.nameEl = query('.js-funnel-name', this.el);
  this.listEl = query('.js-funnel-list', this.el);
  this.completionEl = query('.js-funnel-item-completion', this.el);
  this.conversionEl = query('.js-funnel-conversion', this.el);
  this.stepsCollection = new StepsCollection();
  this._name = '';
  this.stepViews = [];
}
Example #12
0
 LawForm.prototype.renderDateTimePickers = function() {
  this.closingAt = o('[name=closingAt]', this.el);
  var closingAtTime = this.closingAtTime = o('[name=closingAtTime]', this.el);
  Datepicker(this.closingAt);
  Timepicker(this.closingAtTime)
    .on('change', function(v) {
      closingAtTime.value = (v.hour || '0') + ':' + (v.minute || '00');
    });
  return this;
};
Example #13
0
File: view.js Project: 89berner/app
CommentsView.prototype.newreply = function(reply) {
  var replyEl = o('li[data-id=' + reply.id + ']', this.el);
  var commentEl = closest(replyEl, 'li.comment-item');
  var replyCounter = o('.reply-counter', commentEl);
  var counter = replyCounter.innerHTML != '' ? parseInt(replyCounter.innerHTML) : 0;
  var btnRemove = o('.comment-action.btn-remove', commentEl);
  classes(btnRemove).add('hide');
  counter++;
  replyCounter.innerHTML = counter;
}
Example #14
0
Combo.prototype.group = function (name) {
  var template = require('./templates/group');
  var el = domify(template)[0];
  var label = query('.group-label', el);
  
  label.innerHTML = name;
  this._group = query('.options', el);
  this.list.appendChild(el);
  
  return this.emit('group', name);
};
Example #15
0
File: view.js Project: 89berner/app
CommentsView.prototype.onremove = function(ev) {
  ev.preventDefault();

  var target = ev.delegateTarget || closest(ev.target, 'a');
  var comment = closest(target, 'li[data-id]');
  classes(comment).add('remove');
  var btnEdit = o('.btn-edit', comment);
  classes(btnEdit).remove('hide');
  var mediaBody = o('.media-body', comment);
  classes(mediaBody).remove('edit');
};
Example #16
0
File: view.js Project: 89berner/app
CommentsView.prototype.errors = function(errors) {
  var span = o('span.help-text.form-errors', this.el);
  errors = errors || [];
  classes(o('form.comment-form', this.el)).remove('has-error');

  span.innerHTML = '';
  errors.forEach(function(err) {
    span.innerHTML += t(err);
  });

  classes(o('form.comment-form', this.el)).add('has-error');
}
Example #17
0
/**
 * Init tree with parent node
 * @param {Node} parent
 * @api public
 */
function Tree(parent) {
  if (! this instanceof Tree) return new Tree(parent);
  this.el = parent;
  this.events = events(this.el, this);
  this.events.bind('click', 'onclick');
  var el = domify(tmpl);
  parent.appendChild(el);
  this.root = query('.tree', parent);
  this.leafNode = query('.tree-leaf', parent);
  this.branchNode = query('.tree-branch', parent);
  var list = query('.tree-list', this.root);
  clear(list);
}
Example #18
0
File: view.js Project: 89berner/app
CommentsView.prototype.removereply = function(data) {
  var commentEl = o('li[data-id=' + data.commentId + ']', this.el);
  var replyCounter = o('.reply-counter', commentEl);
  var counter = replyCounter.innerHTML != '' ? parseInt(replyCounter.innerHTML) : 0;
  var btnRemove = o('.comment-action.btn-remove', commentEl);
  counter--;
  if (counter == 0) {
    classes(btnRemove).remove('hide');
    replyCounter.innerHTML = '';
  } else {
    replyCounter.innerHTML = counter;
  }
}
Example #19
0
function ConfirmationPopover(msg, title) {
  this.actions = domify(require('./template'))[0];
  Popover.call(this, this.actions, title);
  this.classname = 'popover confirmation-popover';

  var cancel = query('.cancel', this.actions);
  events.bind(cancel, 'click', bind(this, this.oncancel));

  var ok = query('.ok', this.actions);
  events.bind(ok, 'click', bind(this, this.onok));

  this.message(msg);
}
Example #20
0
File: view.js Project: 89berner/app
CommentsView.prototype.loadMyArguments = function(comments) {
  if (comments.length) {
    var el = o('.comment-form', this.el);
    classes(el).add('hide');
    classes(o('.new-argument', this.el)).remove('hide');
  } else {
    classes(o('.cancel-new-argument', this.el)).add('hide');
  }

  comments.forEach(function (comment) {
    this.addMyArgument(comment);
  }, this);
};
Example #21
0
function Select(){
  if (!(this instanceof Select)) return new Select;
  this.el = tpl.cloneNode(true);
  this.classes = classes(this.el);
  this.opts = query('.select-options', this.el);
  this.dropdown = query('.select-dropdown', this.el);
  this.input = query('.select-input', this.el);
  this.inputEvents = events(this.input, this);
  this.docEvents = events(document, this);
  this.events = events(this.el, this);
  this._selected = [];
  this.options = {};
  this.bind();
}
Example #22
0
Combo.prototype.render = function () {
  var template = require('./templates/combo');
  this.el = domify(template)[0];
  this.list = query('.options', this.el);
  this.input = query('.search', this.el);
  this.classes = classes(this.el);
  
  this.label = query('.label', this.el);
  this.label.innerHTML = this.placeholder;
  
  if (this.searchable)
    this.addClass('searchable');
  
  return this.bind();
};
Example #23
0
fn.render = function () {
  var template = require('./templates/select.html');
  this.el = domify(template);
  this.list = query('.ui-select-options', this.el);
  this.input = query('.ui-select-search', this.el);
  this.classes = classes(this.el);

  this.label = query('.ui-select-label', this.el);
  this.label.innerHTML = this.placeholder;

  if (this.searchable)
    this.addClass('ui-select-searchable');

  return this;
};
Example #24
0
Tip.prototype.show = function(el){
  var self = this;
  if ('string' == typeof el) el = query(el);

  // show it
  this.target = el;
  document.body.appendChild(this.el);
  this.classes.add('tip-' + this._position.replace(/\s+/g, '-'));

  raf(function(){
    self.classes.remove('tip-hide');
  });

  // x,y
  if ('number' == typeof el) {
    var x = arguments[0];
    var y = arguments[1];
    this.emit('show');
    css(this.el, {
      top: y,
      left: x
    });
    return this;
  }

  // el
  this.reposition();
  this.el.offsetHeight;
  this.emit('show', this.target);

  this.winEvents.bind('resize', 'reposition');
  this.winEvents.bind('scroll', 'reposition');

  return this;
};
Example #25
0
function ProposalArticle (proposal) {
  if (!(this instanceof ProposalArticle)) {
    return new ProposalArticle(proposal);
  };

  this.proposal = proposal;
  this.clauses = proposal.clauses.sort(function(a, b) {
      var sort = a.order - b.order;
      sort = sort > 0 ? 1 : -1;
      return sort;
    })
  this.clausesContent = this.clauses.map(function(c) {
      if (c.text) return (c.clauseName ? c.clauseName + ': ' : '') + c.text;
  });

  var baseUrl = config.protocol + "://" + config.host + (config.publicPort ? (":" + config.publicPort) : "");
  this.el = render.dom(article, {
    proposal: proposal,
    clauses: this.clauses,
    clausesContent: this.clausesContent,
    baseUrl: baseUrl,
    truncate: truncate,
    config: config
  });

  this.events = events(this.el, this);

  this.participants = new Participants(proposal.participants || []);
  this.participants.render(o('.participants', this.el));
  this.participants.fetch();

  this.switchOn();
}
Example #26
0
File: view.js Project: 3manuek/app
View.prototype.onsubmit = function(ev) {
  ev.preventDefault();
  
  // Clean errors list
  this.errors();

  var form = this.el.querySelector('form');
  // Serialize form
  var data = serialize.object(form);
  
  // Check for errors in data
  var errors = this.validate(data);

  // If errors, show and exit
  if (errors.length) {
    this.errors(errors);
    return;
  };

  var submit = o('input[type="submit"]', this.el);
  submit.disabled = true;

  // Deliver form submit
  this.emit('submit', data);
}
Example #27
0
// template:
//  - either the string of html, or an element which will be used
// parentDiv: selector OR element
// app: string or list - passed to angular.boostrap
// placement:
//  - int: index at which to insert
//  - "first": at the start
//  - "last": append
//  - el: before this element
function bootstrap(template, parentDiv, app, placement) {
  var div = document.createElement('div')
    , sel;
  if (typeof (template) !== 'string' && template.innerHTML) {
    div = template;
  } else {
    div.innerHTML = template;
    div = div.firstElementChild;
  }
  if (typeof (parentDiv) === 'string') {
    sel = parentDiv;
    parentDiv = query(parentDiv);
    if (!parentDiv) {
      console.error('Failed to find node:', sel, 'aborting bootstrap');
      return;
    }
  }
  if (placement == 'first') placement = 0;
  if (placement == 'last' || placement >= parentDiv.children.length) {
    parentDiv.appendChild(div);
  } else if (typeof(placement) === 'number') {
    parentDiv.insertBefore(div, parentDiv.children[placement]);
  } else {
    parentDiv.insertBefore(div, placement);
  }
  if (typeof(app) == 'string') {
    app = [app];
  }
  angular.bootstrap(div, app);
  return div;
}
Example #28
0
File: view.js Project: 89berner/app
CommentsView.prototype.initializeArguments = function() {
  this.page = 0;
  this.comments = [];
  classes(o('btn.load-arguments', this.el)).add('hide');
  var view = this;
  request
  .get(this.url() + '/comments')
  .query({ count: true })
  .query({ sort: this.sort })
  .query({ exclude_user: citizen.id || null })
  .end(function(err, res) {
    if (err) {
      log('Fetch error: %s', err);
      return;
    };
    if (!res.ok) {
      log('Fetch error: %s', res.error);
      return;
    };
    if (res.body && res.body.error) {
      log('Fetch response error: %s', res.body.error);
      return;
    };
    view.count = res.body;
    view.fetch();
  });
};
Example #29
0
File: view.js Project: 3manuek/app
ProfileView.prototype.onsubmit = function(ev) {
  ev.preventDefault();
  
  // Clean errors list
  this.messages();

  // Serialize form
  var form = o('form', this.el);
  var data = serialize.object(form);
  // Temporarily disable email submission, until we fix the whole flow
  // Also check ./settings/index.js
  // Fixes https://github.com/DemocracyOS/app/issues/223
  if (data.email) delete data.email;

  // Check for errors in data
  var errors = this.validate(data);

  // If errors, show and exit
  if (errors.length) {
    this.messages(errors);
    return;
  };

  // Sanitize data before submitting
  this.sanitize(data);

  // Deliver form submit
  this.emit('submit', data);
}
Example #30
0
ProposalOptions.prototype.vote = function(ev) {
  ev.preventDefault();

  var target = ev.delegateTarget || closest(ev.target, '[data-proposal]')
  var id = target.getAttribute('data-proposal');
  var self = this;
  var value;

  if (classes(target).has('vote-no')) {
    value = 'negative';
  } else if (classes(target).has('vote-yes')) {
    value = 'positive';
  } else if (classes(target).has('vote-abstain')) {
    value = 'neutral';
  }

  if (this.citizen.id) {
    log('casting vote %s for %s', value, id);
    this.post(
      '/api/law/:id/vote'.replace(':id', id),
      { value: value },
      function (err, res) {
        if (err || !res.ok) return log('Failed cast %s for %s with error: %j', value, id, err || res.error);
        bus.emit('vote', id, value);
        self.emit('vote', value);
      }
    );    
  } else {
    classes(o('.proposal-options p.text-mute', this.el)).remove('hide');
  }
}