wekan/client/components/cards/labels.js

104 lines
2.8 KiB
JavaScript
Raw Normal View History

let labelColors;
Meteor.startup(() => {
2015-06-16 22:41:19 +02:00
labelColors = Boards.simpleSchema()._schema['labels.$.color'].allowedValues;
});
BlazeComponent.extendComponent({
onCreated() {
2015-06-16 22:41:19 +02:00
this.currentColor = new ReactiveVar(this.data().color);
},
labels() {
2019-06-28 12:52:09 -05:00
return labelColors.map(color => ({ color, name: '' }));
2015-06-16 22:41:19 +02:00
},
isSelected(color) {
2015-06-16 22:41:19 +02:00
return this.currentColor.get() === color;
},
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click .js-palette-color'() {
this.currentColor.set(this.currentData().color);
},
},
2019-06-28 12:52:09 -05:00
];
},
2015-06-16 22:41:19 +02:00
}).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() {
const labels = Boards.findOne(Session.get('currentBoard')).labels;
const usedColors = _.pluck(labels, 'color');
const availableColors = _.difference(labelColors, usedColors);
2015-06-16 22:41:19 +02:00
return availableColors.length > 1 ? availableColors[0] : labelColors[0];
},
2015-06-16 22:41:19 +02:00
});
Template.cardLabelsPopup.events({
2019-06-28 12:52:09 -05:00
'click .js-select-label'(event) {
const card = Cards.findOne(Session.get('currentCard'));
const labelId = this._id;
card.toggleLabel(labelId);
2019-06-28 12:52:09 -05:00
event.preventDefault();
},
'click .js-edit-label': Popup.open('editLabel'),
'click .js-add-label': Popup.open('createLabel'),
});
Template.formLabel.events({
2019-06-28 12:52:09 -05:00
'click .js-palette-color'(event) {
const $this = $(event.currentTarget);
// hide selected ll colors
$('.js-palette-select').addClass('hide');
// show select color
$this.find('.js-palette-select').removeClass('hide');
},
});
Template.createLabelPopup.events({
// Create the new label
2019-06-28 12:52:09 -05:00
'submit .create-label'(event, templateInstance) {
event.preventDefault();
const board = Boards.findOne(Session.get('currentBoard'));
2019-06-28 12:52:09 -05:00
const name = templateInstance
.$('#labelName')
.val()
.trim();
const color = Blaze.getData(templateInstance.find('.fa-check')).color;
board.addLabel(name, color);
Popup.back();
},
});
Template.editLabelPopup.events({
'click .js-delete-label': Popup.afterConfirm('deleteLabel', function() {
const board = Boards.findOne(Session.get('currentBoard'));
board.removeLabel(this._id);
Popup.back(2);
}),
2019-06-28 12:52:09 -05:00
'submit .edit-label'(event, templateInstance) {
event.preventDefault();
const board = Boards.findOne(Session.get('currentBoard'));
2019-06-28 12:52:09 -05:00
const name = templateInstance
.$('#labelName')
.val()
.trim();
const color = Blaze.getData(templateInstance.find('.fa-check')).color;
board.editLabel(this._id, name, color);
Popup.back();
},
});
Template.cardLabelsPopup.helpers({
isLabelSelected(cardId) {
return _.contains(Cards.findOne(cardId).labelIds, this._id);
},
});