|
@@ -1,3 +1,49 @@
|
|
|
|
+
|
|
|
|
+var labelColors;
|
|
|
|
+Meteor.startup(function() {
|
|
|
|
+ labelColors = Boards.simpleSchema()._schema['labels.$.color'].allowedValues;
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+BlazeComponent.extendComponent({
|
|
|
|
+ template: function() {
|
|
|
|
+ return 'formLabel';
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ onCreated: function() {
|
|
|
|
+ this.currentColor = new ReactiveVar(this.data().color);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ labels: function() {
|
|
|
|
+ return _.map(labelColors, function(color) {
|
|
|
|
+ return { color: color, name: '' };
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ isSelected: function(color) {
|
|
|
|
+ return this.currentColor.get() === color;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ events: function() {
|
|
|
|
+ return [{
|
|
|
|
+ 'click .js-palette-color': function() {
|
|
|
|
+ this.currentColor.set(this.currentData().color);
|
|
|
|
+ }
|
|
|
|
+ }];
|
|
|
|
+ }
|
|
|
|
+}).register('formLabel');
|
|
|
|
+
|
|
|
|
+Template.createLabelPopup.helpers({
|
|
|
|
+ // This is the default color for a new label. We search the first color that
|
|
|
|
+ // is not already used in the board (although it's not a problem if two
|
|
|
|
+ // labels have the same color).
|
|
|
|
+ defaultColor: function() {
|
|
|
|
+ var labels = this.labels || this.card.board().labels;
|
|
|
|
+ var usedColors = _.pluck(labels, 'color');
|
|
|
|
+ var availableColors = _.difference(labelColors, usedColors);
|
|
|
|
+ return availableColors.length > 1 ? availableColors[0] : labelColors[0];
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
Template.cardLabelsPopup.events({
|
|
Template.cardLabelsPopup.events({
|
|
'click .js-select-label': function(evt) {
|
|
'click .js-select-label': function(evt) {
|
|
var cardId = Template.parentData(2).data._id;
|
|
var cardId = Template.parentData(2).data._id;
|
|
@@ -36,17 +82,18 @@ Template.createLabelPopup.events({
|
|
'submit .create-label': function(evt, tpl) {
|
|
'submit .create-label': function(evt, tpl) {
|
|
var name = tpl.$('#labelName').val().trim();
|
|
var name = tpl.$('#labelName').val().trim();
|
|
var boardId = Session.get('currentBoard');
|
|
var boardId = Session.get('currentBoard');
|
|
- var selectLabelDom = tpl.$('.js-palette-select').get(0);
|
|
|
|
- var selectLabel = Blaze.getData(selectLabelDom);
|
|
|
|
|
|
+ var color = Blaze.getData(tpl.find('.fa-check')).color;
|
|
|
|
+
|
|
Boards.update(boardId, {
|
|
Boards.update(boardId, {
|
|
$push: {
|
|
$push: {
|
|
labels: {
|
|
labels: {
|
|
_id: Random.id(6),
|
|
_id: Random.id(6),
|
|
name: name,
|
|
name: name,
|
|
- color: selectLabel.color
|
|
|
|
|
|
+ color: color
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
Popup.back();
|
|
Popup.back();
|
|
evt.preventDefault();
|
|
evt.preventDefault();
|
|
}
|
|
}
|
|
@@ -62,35 +109,23 @@ Template.editLabelPopup.events({
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
Popup.back(2);
|
|
Popup.back(2);
|
|
}),
|
|
}),
|
|
'submit .edit-label': function(evt, tpl) {
|
|
'submit .edit-label': function(evt, tpl) {
|
|
|
|
+ evt.preventDefault();
|
|
var name = tpl.$('#labelName').val().trim();
|
|
var name = tpl.$('#labelName').val().trim();
|
|
var boardId = Session.get('currentBoard');
|
|
var boardId = Session.get('currentBoard');
|
|
var getLabel = Utils.getLabelIndex(boardId, this._id);
|
|
var getLabel = Utils.getLabelIndex(boardId, this._id);
|
|
- var selectLabelDom = tpl.$('.js-palette-select').get(0);
|
|
|
|
- var selectLabel = Blaze.getData(selectLabelDom);
|
|
|
|
- var $set = {};
|
|
|
|
|
|
+ var color = Blaze.getData(tpl.find('.fa-check')).color;
|
|
|
|
|
|
- // set label index
|
|
|
|
|
|
+ var $set = {};
|
|
$set[getLabel.key('name')] = name;
|
|
$set[getLabel.key('name')] = name;
|
|
|
|
+ $set[getLabel.key('color')] = color;
|
|
|
|
|
|
- // set color
|
|
|
|
- $set[getLabel.key('color')] = selectLabel.color;
|
|
|
|
-
|
|
|
|
- // update
|
|
|
|
Boards.update(boardId, { $set: $set });
|
|
Boards.update(boardId, { $set: $set });
|
|
|
|
|
|
- // return to the previous popup view trigger
|
|
|
|
Popup.back();
|
|
Popup.back();
|
|
-
|
|
|
|
- evt.preventDefault();
|
|
|
|
- },
|
|
|
|
- 'click .js-select-label': function() {
|
|
|
|
- Cards.remove(this.cardId);
|
|
|
|
-
|
|
|
|
- // redirect board
|
|
|
|
- Utils.goBoardId(this.boardId);
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
@@ -99,28 +134,3 @@ Template.cardLabelsPopup.helpers({
|
|
return _.contains(Cards.findOne(cardId).labelIds, this._id);
|
|
return _.contains(Cards.findOne(cardId).labelIds, this._id);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
-var labelColors;
|
|
|
|
-Meteor.startup(function() {
|
|
|
|
- labelColors = Boards.simpleSchema()._schema['labels.$.color'].allowedValues;
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
-Template.createLabelPopup.helpers({
|
|
|
|
- // This is the default color for a new label. We search the first color that
|
|
|
|
- // is not already used in the board (although it's not a problem if two
|
|
|
|
- // labels have the same color).
|
|
|
|
- defaultColor: function() {
|
|
|
|
- var labels = this.labels || this.card.board().labels;
|
|
|
|
- var usedColors = _.pluck(labels, 'color');
|
|
|
|
- var availableColors = _.difference(labelColors, usedColors);
|
|
|
|
- return availableColors.length > 1 ? availableColors[0] : labelColors[0];
|
|
|
|
- }
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
-Template.formLabel.helpers({
|
|
|
|
- labels: function() {
|
|
|
|
- return _.map(labelColors, function(color) {
|
|
|
|
- return { color: color, name: '' };
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-});
|
|
|