summaryrefslogtreecommitdiffstats
path: root/client/components/rules/rulesMain.js
blob: 373c7502b79fc253843337620c1432114e896b85 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
BlazeComponent.extendComponent({
  onCreated() {
    this.rulesCurrentTab = new ReactiveVar('rulesList');
    this.ruleName = new ReactiveVar('');
    this.triggerVar = new ReactiveVar();
    this.ruleId = new ReactiveVar();
  },

  setTrigger() {
    this.rulesCurrentTab.set('trigger');
  },

  setRulesList() {
    this.rulesCurrentTab.set('rulesList');
  },

  setAction() {
    this.rulesCurrentTab.set('action');
  },

  setRuleDetails() {
    this.rulesCurrentTab.set('ruleDetails');
  },

  events() {
    return [{
      'click .js-delete-rule' () {
        const rule = this.currentData();
        Rules.remove(rule._id);
        Actions.remove(rule.actionId);
        Triggers.remove(rule.triggerId);

      },
      'click .js-open-card-title-popup': Popup.open('boardCardTitle'),
      'click .js-goto-trigger' (event) {
        event.preventDefault();
        const ruleTitle = this.find('#ruleTitle').value;
        if(ruleTitle !== undefined && ruleTitle !== ''){
          this.find('#ruleTitle').value = '';
          this.ruleName.set(ruleTitle);
          this.setTrigger();
        }
      },
      'click .js-goto-action' (event) {
        event.preventDefault();
        // Add user to the trigger
        const username = $(event.currentTarget.offsetParent).find(".user-name").val();
        let trigger = this.triggerVar.get();
        const user = Users.findOne({"username":username});
        if(user != undefined){
          trigger["userId"] = user._id;
        }else{
          trigger["userId"] = "*";
        }
        this.triggerVar.set(trigger);
        this.setAction();
      },
      'click .js-show-user-field' (event) {
        event.preventDefault();
        console.log(event);
        console.log(event.currentTarget.offsetParent);
        console.log($(event.currentTarget.offsetParent));
        $(event.currentTarget.offsetParent).find(".user-details").removeClass("hide-element");


      },
      'click .js-goto-rules' (event) {
        event.preventDefault();
        this.setRulesList();
      },
      'click .js-goback' (event) {
        event.preventDefault();
        if(this.rulesCurrentTab.get() === 'trigger' || this.rulesCurrentTab.get() === 'ruleDetails' ){
          this.setRulesList();
        }
        if(this.rulesCurrentTab.get() === 'action'){
          this.setTrigger();
        }
      },
      'click .js-goto-details' (event) {
        event.preventDefault();
        const rule = this.currentData();
        this.ruleId.set(rule._id);
        this.setRuleDetails();
      },

    }];
  },

}).register('rulesMain');