summaryrefslogtreecommitdiffstats
path: root/client/components/rules/actions/cardActions.js
blob: 0bf7428a64cfaef65a46e82d293f7e385a4ddee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
BlazeComponent.extendComponent({
  onCreated() {
    this.subscribe('allRules');
  },

  labels(){
    const labels = Boards.findOne(Session.get('currentBoard')).labels;
    for(let i = 0;i<labels.length;i++){
      if(labels[i].name == "" || labels[i].name == undefined){
        labels[i].name = labels[i].color.toUpperCase();
      }
    }
    console.log(labels);
    return labels;
  },



  events() {
    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);
      if(actionSelected == "add"){
       const triggerId = Triggers.insert(trigger);
       const actionId = Actions.insert({actionType: "addLabel","labelId":labelId,"boardId":boardId,"desc":desc});
       Rules.insert({title: ruleName, triggerId: triggerId, actionId: actionId,"boardId":boardId});  
     }
     if(actionSelected == "remove"){
       const triggerId = Triggers.insert(trigger);
       const actionId = Actions.insert({actionType: "removeLabel","labelId":labelId,"boardId":boardId,"desc":desc});
       Rules.insert({title: ruleName, triggerId: triggerId, actionId: actionId,"boardId":boardId});  
     }

   },
   '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 memberName = this.find('#member-name').value;
    const boardId = Session.get('currentBoard');
    const desc = Utils.getTriggerActionDesc(event,this);
    if(actionSelected == "add"){
     const triggerId = Triggers.insert(trigger);
     const actionId = Actions.insert({actionType: "addMember","memberName":memberName,"boardId":boardId,"desc":desc});
     Rules.insert({title: ruleName, triggerId: triggerId, actionId: actionId,"boardId":boardId,"desc":desc});  
   }
   if(actionSelected == "remove"){
     const triggerId = Triggers.insert(trigger);
     const actionId = Actions.insert({actionType: "removeMember","memberName":memberName,"boardId":boardId,"desc":desc});
     Rules.insert({title: ruleName, triggerId: triggerId, actionId: actionId,"boardId":boardId});  
   }
 },
 '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({actionType: "removeMember","memberName":"*","boardId":boardId,"desc":desc});
  Rules.insert({title: ruleName, triggerId: triggerId, actionId: actionId,"boardId":boardId});
},
}];
},

}).register('cardActions');