summaryrefslogtreecommitdiffstats
path: root/client/components/boards/events.js
blob: 6f9d7fc62248c7298aed4e1c7d0c91c0b2595230 (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
91
92
93
94
95
96
var toggleBoardStar = function(boardId) {
  var queryType = Meteor.user().hasStarred(boardId) ? '$pull' : '$addToSet';
  var query = {};
  query[queryType] = {
    'profile.starredBoards': boardId
  };
  Meteor.users.update(Meteor.userId(), query);
};

Template.boards.events({
  'click .js-star-board': function(evt) {
    toggleBoardStar(this._id);
    evt.preventDefault();
  }
});

Template.headerBoard.events({
  'click .js-star-board': function() {
    toggleBoardStar(this._id);
  },
  'click .js-open-board-menu': Popup.open('boardMenu'),
  'click #permission-level:not(.no-edit)': Popup.open('boardChangePermission'),
  'click .js-filter-cards-indicator': function(evt) {
    Session.set('currentWidget', 'filter');
    evt.preventDefault();
  },
  'click .js-filter-card-clear': function(evt) {
    Filter.reset();
    evt.stopPropagation();
  }
});

Template.boardMenuPopup.events({
  'click .js-rename-board': Popup.open('boardChangeTitle'),
  'click .js-change-board-color': Popup.open('boardChangeColor')
});

Template.createBoardPopup.events({
  'submit #CreateBoardForm': function(evt, t) {
    var title = t.$('#boardNewTitle');

    // trim value title
    if ($.trim(title.val())) {
      // İnsert Board title
      var boardId = Boards.insert({
        title: title.val(),
        permission: 'public'
      });

      // Go to Board _id
      Utils.goBoardId(boardId);
    }
    evt.preventDefault();
  }
});

Template.boardChangeTitlePopup.events({
  'submit #ChangeBoardTitleForm': function(evt, t) {
    var title = t.$('.js-board-name').val().trim();
    if (title) {
      Boards.update(this._id, {
        $set: {
          title: title
        }
      });
      Popup.close();
    }
    evt.preventDefault();
  }
});

Template.boardChangePermissionPopup.events({
  'click .js-select': function(evt) {
    var $this = $(evt.currentTarget);
    var permission = $this.attr('name');

    Boards.update(this._id, {
      $set: {
        permission: permission
      }
    });
    Popup.close();
  }
});

Template.boardChangeColorPopup.events({
  'click .js-select-background': function(evt) {
    var currentBoardId = Session.get('currentBoard');
    Boards.update(currentBoardId, {
      $set: {
        color: this.toString()
      }
    });
    evt.preventDefault();
  }
});