summaryrefslogtreecommitdiffstats
path: root/client/components/sidebar/sidebarCustomFields.js
blob: 6ddd466eee8968010dfbd1dc8f692fa0bb176beb (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
BlazeComponent.extendComponent({

  customFields() {
    return CustomFields.find({
      boardId: Session.get('currentBoard'),
    });
  },

  events() {
    return [{
      'click .js-open-create-custom-field': Popup.open('createCustomField'),
      'click .js-edit-custom-field': Popup.open('editCustomField'),
    }];
  },

}).register('customFieldsSidebar');

Template.createCustomFieldPopup.helpers({
  types() {
    var currentType = this.type;
    return ['text', 'number', 'checkbox', 'date', 'dropdown'].
      map(type => {return {
        type: type,
        name: TAPi18n.__('custom-field-' + type),
        selected: type == currentType,
      }});
  },
});

Template.createCustomFieldPopup.events({
  'click .js-field-show-on-card'(event) {
    let $target = $(event.target);
    if(!$target.hasClass('js-field-show-on-card')){
      $target = $target.parent();
    }
    $target.find('.materialCheckBox').toggleClass('is-checked');
    $target.toggleClass('is-checked');
  },
  'submit'(evt, tpl) {
    evt.preventDefault();

    const name = tpl.find('.js-field-name').value.trim();
    const type = tpl.find('.js-field-type').value.trim();
    const showOnCard = tpl.find('.js-field-show-on-card.is-checked') != null;
    //console.log('Create',name,type,showOnCard);

    CustomFields.insert({
      boardId: Session.get('currentBoard'),
      name: name,
      type: type,
      showOnCard: showOnCard
    });

    Popup.back();
  },
  'click .js-delete-custom-field': Popup.afterConfirm('deleteCustomField', function() {
    const customFieldId = this._id;
    CustomFields.remove(customFieldId);
    Popup.close();
  }),
});

/*Template.deleteCustomFieldPopup.events({
  'submit'(evt) {
    const customFieldId = this._id;
    CustomFields.remove(customFieldId);
    Popup.close();
  }
});*/