summaryrefslogtreecommitdiffstats
path: root/client/components/lists/list.js
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-09-03 23:12:46 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-09-03 23:12:46 +0200
commitb3851817ecd59b039f2c2228d08a1c6fd8e60d60 (patch)
tree82a50f69788d5c20632f3ec9c7d3e136502b93b4 /client/components/lists/list.js
parent039cfe7edf8faf901069a94b3ca9b66f7973b26a (diff)
downloadwekan-b3851817ecd59b039f2c2228d08a1c6fd8e60d60.tar.gz
wekan-b3851817ecd59b039f2c2228d08a1c6fd8e60d60.tar.bz2
wekan-b3851817ecd59b039f2c2228d08a1c6fd8e60d60.zip
Enforce a consistent ES6 coding style
Replace the old (and broken) jshint + jscsrc by eslint and configure it to support some of the ES6 features. The command `eslint` currently has one error which is a bug that was discovered by its static analysis and should be fixed (usage of a dead object).
Diffstat (limited to 'client/components/lists/list.js')
-rw-r--r--client/components/lists/list.js83
1 files changed, 42 insertions, 41 deletions
diff --git a/client/components/lists/list.js b/client/components/lists/list.js
index 3b602f43..1b54741c 100644
--- a/client/components/lists/list.js
+++ b/client/components/lists/list.js
@@ -1,14 +1,16 @@
+const { calculateIndex } = Utils;
+
BlazeComponent.extendComponent({
- template: function() {
+ template() {
return 'list';
},
- // Proxies
- openForm: function(options) {
+ // Proxy
+ openForm(options) {
this.componentChildren('listBody')[0].openForm(options);
},
- onCreated: function() {
+ onCreated() {
this.newCardFormIsVisible = new ReactiveVar(true);
},
@@ -19,28 +21,27 @@ BlazeComponent.extendComponent({
// By calling asking the sortable library to cancel its move on the `stop`
// callback, we basically solve all issues related to reactive updates. A
// comment below provides further details.
- onRendered: function() {
- var self = this;
- if (! Meteor.user() || ! Meteor.user().isBoardMember())
+ onRendered() {
+ if (!Meteor.user() || !Meteor.user().isBoardMember())
return;
- var boardComponent = self.componentParent();
- var itemsSelector = '.js-minicard:not(.placeholder, .js-card-composer)';
- var $cards = self.$('.js-minicards');
+ const boardComponent = this.componentParent();
+ const itemsSelector = '.js-minicard:not(.placeholder, .js-card-composer)';
+ const $cards = this.$('.js-minicards');
$cards.sortable({
connectWith: '.js-minicards',
tolerance: 'pointer',
appendTo: 'body',
- helper: function(evt, item) {
- var helper = item.clone();
+ helper(evt, item) {
+ const helper = item.clone();
if (MultiSelection.isActive()) {
- var andNOthers = $cards.find('.js-minicard.is-checked').length - 1;
+ const andNOthers = $cards.find('.js-minicard.is-checked').length - 1;
if (andNOthers > 0) {
helper.append($(Blaze.toHTML(HTML.DIV(
// XXX Super bad class name
{'class': 'and-n-other'},
// XXX Need to translate
- 'and ' + andNOthers + ' other cards.'
+ `and ${andNOthers} other cards.`
))));
}
}
@@ -50,19 +51,19 @@ BlazeComponent.extendComponent({
items: itemsSelector,
scroll: false,
placeholder: 'minicard-wrapper placeholder',
- start: function(evt, ui) {
+ start(evt, ui) {
ui.placeholder.height(ui.helper.height());
EscapeActions.executeUpTo('popup');
boardComponent.setIsDragging(true);
},
- stop: function(evt, ui) {
+ stop(evt, ui) {
// To attribute the new index number, we need to get the DOM element
// of the previous and the following card -- if any.
- var prevCardDom = ui.item.prev('.js-minicard').get(0);
- var nextCardDom = ui.item.next('.js-minicard').get(0);
- var nCards = MultiSelection.isActive() ? MultiSelection.count() : 1;
- var sortIndex = Utils.calculateIndex(prevCardDom, nextCardDom, nCards);
- var listId = Blaze.getData(ui.item.parents('.list').get(0))._id;
+ const prevCardDom = ui.item.prev('.js-minicard').get(0);
+ const nextCardDom = ui.item.next('.js-minicard').get(0);
+ const nCards = MultiSelection.isActive() ? MultiSelection.count() : 1;
+ const sortIndex = calculateIndex(prevCardDom, nextCardDom, nCards);
+ const listId = Blaze.getData(ui.item.parents('.list').get(0))._id;
// Normally the jquery-ui sortable library moves the dragged DOM element
// to its new position, which disrupts Blaze reactive updates mechanism
@@ -74,53 +75,53 @@ BlazeComponent.extendComponent({
$cards.sortable('cancel');
if (MultiSelection.isActive()) {
- Cards.find(MultiSelection.getMongoSelector()).forEach(function(c, i) {
+ Cards.find(MultiSelection.getMongoSelector()).forEach((c, i) => {
Cards.update(c._id, {
$set: {
- listId: listId,
- sort: sortIndex.base + i * sortIndex.increment
- }
+ listId,
+ sort: sortIndex.base + i * sortIndex.increment,
+ },
});
});
} else {
- var cardDomElement = ui.item.get(0);
- var cardId = Blaze.getData(cardDomElement)._id;
+ const cardDomElement = ui.item.get(0);
+ const cardId = Blaze.getData(cardDomElement)._id;
Cards.update(cardId, {
$set: {
- listId: listId,
- sort: sortIndex.base
- }
+ listId,
+ sort: sortIndex.base,
+ },
});
}
boardComponent.setIsDragging(false);
- }
+ },
});
// We want to re-run this function any time a card is added.
- self.autorun(function() {
- var currentBoardId = Tracker.nonreactive(function() {
+ this.autorun(() => {
+ const currentBoardId = Tracker.nonreactive(() => {
return Session.get('currentBoard');
});
Cards.find({ boardId: currentBoardId }).fetch();
- Tracker.afterFlush(function() {
+ Tracker.afterFlush(() => {
$cards.find(itemsSelector).droppable({
hoverClass: 'draggable-hover-card',
accept: '.js-member,.js-label',
- drop: function(event, ui) {
- var cardId = Blaze.getData(this)._id;
- var addToSet;
+ drop(event, ui) {
+ const cardId = Blaze.getData(this)._id;
+ let addToSet;
if (ui.draggable.hasClass('js-member')) {
- var memberId = Blaze.getData(ui.draggable.get(0)).userId;
+ const memberId = Blaze.getData(ui.draggable.get(0)).userId;
addToSet = { members: memberId };
} else {
- var labelId = Blaze.getData(ui.draggable.get(0))._id;
+ const labelId = Blaze.getData(ui.draggable.get(0))._id;
addToSet = { labelIds: labelId };
}
Cards.update(cardId, { $addToSet: addToSet });
- }
+ },
});
});
});
- }
+ },
}).register('list');