summaryrefslogtreecommitdiffstats
path: root/client/components/rules/rulesMain.js
blob: 5a4b612acf685e5d993dff37fe874a4006a5602b (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
BlazeComponent.extendComponent({
  onCreated() {
    this.rulesListVar = new ReactiveVar(true);
    this.rulesTriggerVar = new ReactiveVar(false);
    this.rulesActionVar = new ReactiveVar(false);
    this.ruleName = new ReactiveVar("");
    this.triggerIdVar = new ReactiveVar("");
  },

  setTrigger() {
    this.rulesListVar.set(false);
    this.rulesTriggerVar.set(true);
    this.rulesActionVar.set(false);
  },

  setRulesList() {
    this.rulesListVar.set(true);
    this.rulesTriggerVar.set(false);
    this.rulesActionVar.set(false);
  },

  setAction() {
    this.rulesListVar.set(false);
    this.rulesTriggerVar.set(false);
    this.rulesActionVar.set(true);
  },

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

    },
    'click .js-goto-trigger'(event) {
      event.preventDefault();
      const ruleTitle = this.find('#ruleTitle').value;
      this.find('#ruleTitle').value = "";
      this.ruleName.set(ruleTitle)
      this.setTrigger();
    },
    'click .js-goto-action'(event) {
      event.preventDefault();
      this.setAction();
    },
    'click .js-goto-rules'(event) {
      event.preventDefault();
      this.setRulesList();
    },


  }];
  },

}).register('rulesMain');