wekan/client/components/rules/actions/cardActions.js

187 lines
5.5 KiB
JavaScript
Raw Normal View History

let cardColors;
Meteor.startup(() => {
cardColors = Cards.simpleSchema()._schema.color.allowedValues;
});
2018-08-19 18:53:50 +02:00
BlazeComponent.extendComponent({
onCreated() {
this.subscribe('allRules');
},
2018-09-14 17:39:37 +02:00
labels() {
2018-08-19 18:53:50 +02:00
const labels = Boards.findOne(Session.get('currentBoard')).labels;
2018-09-14 17:39:37 +02:00
for (let i = 0; i < labels.length; i++) {
2018-09-16 01:50:36 +03:00
if (labels[i].name === '' || labels[i].name === undefined) {
2018-08-19 18:53:50 +02:00
labels[i].name = labels[i].color.toUpperCase();
}
}
return labels;
},
events() {
2018-09-14 17:39:37 +02:00
return [{
'click .js-add-label-action' (event) {
const ruleName = this.data().ruleName.get();
const trigger = this.data().triggerVar.get();
const actionSelected = this.find('#label-action').value;
const labelId = this.find('#label-id').value;
const boardId = Session.get('currentBoard');
const desc = Utils.getTriggerActionDesc(event, this);
2018-09-16 01:50:36 +03:00
if (actionSelected === 'add') {
2018-09-14 17:39:37 +02:00
const triggerId = Triggers.insert(trigger);
const actionId = Actions.insert({
2018-09-16 01:50:36 +03:00
actionType: 'addLabel',
labelId,
boardId,
desc,
2018-09-14 17:39:37 +02:00
});
Rules.insert({
title: ruleName,
2018-09-16 01:50:36 +03:00
triggerId,
actionId,
boardId,
2018-09-14 17:39:37 +02:00
});
}
2018-09-16 01:50:36 +03:00
if (actionSelected === 'remove') {
2018-09-14 17:39:37 +02:00
const triggerId = Triggers.insert(trigger);
const actionId = Actions.insert({
2018-09-16 01:50:36 +03:00
actionType: 'removeLabel',
labelId,
boardId,
desc,
2018-09-14 17:39:37 +02:00
});
Rules.insert({
title: ruleName,
2018-09-16 01:50:36 +03:00
triggerId,
actionId,
boardId,
2018-09-14 17:39:37 +02:00
});
}
2018-08-19 18:53:50 +02:00
2018-09-14 17:39:37 +02:00
},
'click .js-add-member-action' (event) {
const ruleName = this.data().ruleName.get();
const trigger = this.data().triggerVar.get();
const actionSelected = this.find('#member-action').value;
const username = this.find('#member-name').value;
2018-09-14 17:39:37 +02:00
const boardId = Session.get('currentBoard');
const desc = Utils.getTriggerActionDesc(event, this);
2018-09-16 01:50:36 +03:00
if (actionSelected === 'add') {
2018-09-14 17:39:37 +02:00
const triggerId = Triggers.insert(trigger);
const actionId = Actions.insert({
2018-09-16 01:50:36 +03:00
actionType: 'addMember',
username,
2018-09-16 01:50:36 +03:00
boardId,
desc,
2018-09-14 17:39:37 +02:00
});
Rules.insert({
title: ruleName,
2018-09-16 01:50:36 +03:00
triggerId,
actionId,
boardId,
desc,
2018-09-14 17:39:37 +02:00
});
}
2018-09-16 01:50:36 +03:00
if (actionSelected === 'remove') {
2018-09-14 17:39:37 +02:00
const triggerId = Triggers.insert(trigger);
const actionId = Actions.insert({
2018-09-16 01:50:36 +03:00
actionType: 'removeMember',
username,
2018-09-16 01:50:36 +03:00
boardId,
desc,
2018-09-14 17:39:37 +02:00
});
Rules.insert({
title: ruleName,
2018-09-16 01:50:36 +03:00
triggerId,
actionId,
boardId,
2018-09-14 17:39:37 +02:00
});
}
},
'click .js-add-removeall-action' (event) {
const ruleName = this.data().ruleName.get();
const trigger = this.data().triggerVar.get();
const triggerId = Triggers.insert(trigger);
const desc = Utils.getTriggerActionDesc(event, this);
const boardId = Session.get('currentBoard');
const actionId = Actions.insert({
2018-09-16 01:50:36 +03:00
actionType: 'removeMember',
'username': '*',
2018-09-16 01:50:36 +03:00
boardId,
desc,
2018-09-14 17:39:37 +02:00
});
Rules.insert({
title: ruleName,
2018-09-16 01:50:36 +03:00
triggerId,
actionId,
boardId,
2018-09-14 17:39:37 +02:00
});
},
'click .js-show-color-palette'(event){
const funct = Popup.open('setCardActionsColor');
const colorButton = this.find('#color-action');
if (colorButton.value === '') {
colorButton.value = 'green';
}
funct.call(this, event);
},
2019-01-22 10:39:30 +01:00
'click .js-set-color-action' (event) {
const ruleName = this.data().ruleName.get();
const trigger = this.data().triggerVar.get();
const colorButton = this.find('#color-action');
if (colorButton.value === '') {
colorButton.value = 'green';
}
const selectedColor = colorButton.value;
2019-01-22 10:39:30 +01:00
const boardId = Session.get('currentBoard');
const desc = Utils.getTriggerActionDesc(event, this);
const triggerId = Triggers.insert(trigger);
const actionId = Actions.insert({
actionType: 'setColor',
selectedColor,
boardId,
desc,
});
Rules.insert({
title: ruleName,
triggerId,
actionId,
boardId,
});
},
2018-09-14 17:39:37 +02:00
}];
},
2018-08-19 18:53:50 +02:00
2018-09-16 01:50:36 +03:00
}).register('cardActions');
BlazeComponent.extendComponent({
onCreated() {
this.currentAction = this.currentData();
this.colorButton = Popup.getOpenerComponent().find('#color-action');
this.currentColor = new ReactiveVar(this.colorButton.value);
},
colors() {
return cardColors.map((color) => ({ color, name: '' }));
},
isSelected(color) {
return this.currentColor.get() === color;
},
events() {
return [{
'click .js-palette-color'() {
this.currentColor.set(this.currentData().color);
},
'click .js-submit' () {
this.colorButton.classList.remove(`card-details-${ this.colorButton.value }`);
this.colorButton.value = this.currentColor.get();
this.colorButton.innerText = `${TAPi18n.__(`color-${ this.currentColor.get() }`)}`;
this.colorButton.classList.add(`card-details-${ this.colorButton.value }`);
Popup.close();
},
}];
},
}).register('setCardActionsColorPopup');