summaryrefslogtreecommitdiffstats
path: root/client/components/cards/cardCustomFields.js
blob: f9fa760cbc79d6ab4167e175e546131fd23356f0 (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
Template.cardCustomFieldsPopup.helpers({
    hasCustomField() {
        const card = Cards.findOne(Session.get('currentCard'));
        const customFieldId = this._id;
        return card.customFieldIndex(customFieldId) > -1;
    },
});

Template.cardCustomFieldsPopup.events({
    'click .js-select-field'(evt) {
        const card = Cards.findOne(Session.get('currentCard'));
        const customFieldId = this._id;
        card.toggleCustomField(customFieldId);
        evt.preventDefault();
    },
    'click .js-settings'(evt) {
        EscapeActions.executeUpTo('detailsPane');
        Sidebar.setView('customFields');
        evt.preventDefault();
    }
});

const CardCustomField = BlazeComponent.extendComponent({

    getTemplate() {
        return 'cardCustomField-' + this.data().definition.type;
    },

    onCreated() {
        const self = this;
    },

    canModifyCard() {
        return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
    },
});
CardCustomField.register('cardCustomField');

(class extends CardCustomField {

    onCreated() {
    }

    events() {
        return [{
            'submit .js-card-customfield-text'(evt) {
                evt.preventDefault();
                const card = Cards.findOne(Session.get('currentCard'));
                const customFieldId = this.data()._id;
                const value = this.currentComponent().getValue();
                card.setCustomField(customFieldId,value);
            },
        }];
    }

}).register('cardCustomField-text');

(class extends CardCustomField {

    onCreated() {
        this._items = this.data().definition.settings.dropdownItems;
        this.items = this._items.slice(0);
        this.items.unshift({
            _id: "",
            name: TAPi18n.__('custom-field-dropdown-none')
        });
    }

    selectedItem() {
        const selected = this._items.find((item) => {
            return item._id == this.data().value;
        });
        return (selected) ? selected.name : TAPi18n.__('custom-field-dropdown-unknown');
    }

    events() {
        return [{
            'submit .js-card-customfield-dropdown'(evt) {
                evt.preventDefault();
                const card = Cards.findOne(Session.get('currentCard'));
                const customFieldId = this.data()._id;
                const value = this.find('select').value;
                card.setCustomField(customFieldId,value);
            },
        }];
    }

}).register('cardCustomField-dropdown');