wekan/client/components/cards/cardCustomFields.js

236 lines
5.4 KiB
JavaScript
Raw Normal View History

Template.cardCustomFieldsPopup.helpers({
2018-05-18 10:24:51 +02:00
hasCustomField() {
const card = Cards.findOne(Session.get('currentCard'));
const customFieldId = this._id;
return card.customFieldIndex(customFieldId) > -1;
},
});
Template.cardCustomFieldsPopup.events({
2019-06-28 12:52:09 -05:00
'click .js-select-field'(event) {
2018-05-18 10:24:51 +02:00
const card = Cards.findOne(Session.get('currentCard'));
const customFieldId = this._id;
card.toggleCustomField(customFieldId);
2019-06-28 12:52:09 -05:00
event.preventDefault();
2018-05-18 10:24:51 +02:00
},
2019-06-28 12:52:09 -05:00
'click .js-settings'(event) {
2018-05-18 10:24:51 +02:00
EscapeActions.executeUpTo('detailsPane');
Sidebar.setView('customFields');
2019-06-28 12:52:09 -05:00
event.preventDefault();
2018-05-18 10:24:51 +02:00
},
});
2017-10-14 01:38:25 +02:00
// cardCustomField
const CardCustomField = BlazeComponent.extendComponent({
2018-05-18 10:24:51 +02:00
getTemplate() {
2018-05-18 10:43:43 +02:00
return `cardCustomField-${this.data().definition.type}`;
2018-05-18 10:24:51 +02:00
},
2018-05-18 10:24:51 +02:00
onCreated() {
const self = this;
self.card = Cards.findOne(Session.get('currentCard'));
self.customFieldId = this.data()._id;
},
2018-05-18 10:24:51 +02:00
canModifyCard() {
2019-06-28 12:52:09 -05:00
return (
Meteor.user() &&
Meteor.user().isBoardMember() &&
!Meteor.user().isCommentOnly()
);
2018-05-18 10:24:51 +02:00
},
2017-09-18 00:46:17 +02:00
});
CardCustomField.register('cardCustomField');
2017-10-14 01:38:25 +02:00
// cardCustomField-text
2017-09-18 00:46:17 +02:00
(class extends CardCustomField {
2018-05-18 10:24:51 +02:00
onCreated() {
super.onCreated();
}
2018-05-18 10:24:51 +02:00
events() {
2019-06-28 12:52:09 -05:00
return [
{
'submit .js-card-customfield-text'(event) {
event.preventDefault();
const value = this.currentComponent().getValue();
this.card.setCustomField(this.customFieldId, value);
},
2018-05-18 10:24:51 +02:00
},
2019-06-28 12:52:09 -05:00
];
2018-05-18 10:24:51 +02:00
}
2019-06-28 12:52:09 -05:00
}.register('cardCustomField-text'));
2017-09-18 00:46:17 +02:00
2017-10-14 01:38:25 +02:00
// cardCustomField-number
2017-09-18 00:46:17 +02:00
(class extends CardCustomField {
2018-05-18 10:24:51 +02:00
onCreated() {
super.onCreated();
}
2017-10-14 01:38:25 +02:00
2018-05-18 10:24:51 +02:00
events() {
2019-06-28 12:52:09 -05:00
return [
{
'submit .js-card-customfield-number'(event) {
event.preventDefault();
const value = parseInt(this.find('input').value, 10);
this.card.setCustomField(this.customFieldId, value);
},
2018-05-18 10:24:51 +02:00
},
2019-06-28 12:52:09 -05:00
];
2018-05-18 10:24:51 +02:00
}
}.register('cardCustomField-number'));
// cardCustomField-checkbox
(class extends CardCustomField {
onCreated() {
super.onCreated();
}
toggleItem() {
this.card.setCustomField(this.customFieldId, !this.data().value);
}
events() {
return [
{
'click .js-checklist-item .check-box-container': this.toggleItem,
},
];
}
}.register('cardCustomField-checkbox'));
2017-10-14 01:38:25 +02:00
// cardCustomField-currency
(class extends CardCustomField {
onCreated() {
super.onCreated();
this.currencyCode = this.data().definition.settings.currencyCode;
}
formattedValue() {
const locale = TAPi18n.getLanguage();
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: this.currencyCode,
}).format(this.data().value);
}
events() {
return [
{
'submit .js-card-customfield-currency'(event) {
event.preventDefault();
const value = Number(this.find('input').value, 10);
this.card.setCustomField(this.customFieldId, value);
},
},
];
}
}.register('cardCustomField-currency'));
2017-10-14 01:38:25 +02:00
// cardCustomField-date
(class extends CardCustomField {
2018-05-18 10:24:51 +02:00
onCreated() {
super.onCreated();
const self = this;
self.date = ReactiveVar();
self.now = ReactiveVar(moment());
window.setInterval(() => {
self.now.set(moment());
}, 60000);
self.autorun(() => {
self.date.set(moment(self.data().value));
});
}
showDate() {
2018-05-18 11:13:01 +02:00
// this will start working once mquandalle:moment
// is updated to at least moment.js 2.10.5
// until then, the date is displayed in the "L" format
2018-05-18 10:24:51 +02:00
return this.date.get().calendar(null, {
sameElse: 'llll',
});
}
2017-10-14 01:38:25 +02:00
2018-05-18 10:24:51 +02:00
showISODate() {
return this.date.get().toISOString();
}
2017-10-14 01:38:25 +02:00
2018-05-18 10:24:51 +02:00
classes() {
2019-06-28 12:52:09 -05:00
if (
this.date.get().isBefore(this.now.get(), 'minute') &&
this.now.get().isBefore(this.data().value)
) {
2018-05-18 10:24:51 +02:00
return 'current';
2017-10-14 01:38:25 +02:00
}
2018-05-18 10:24:51 +02:00
return '';
}
2017-10-14 01:38:25 +02:00
2018-05-18 10:24:51 +02:00
showTitle() {
return `${TAPi18n.__('card-start-on')} ${this.date.get().format('LLLL')}`;
}
2017-10-14 01:38:25 +02:00
2018-05-18 10:24:51 +02:00
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click .js-edit-date': Popup.open('cardCustomField-date'),
},
];
2018-05-18 10:24:51 +02:00
}
2019-06-28 12:52:09 -05:00
}.register('cardCustomField-date'));
2017-10-14 01:38:25 +02:00
// cardCustomField-datePopup
(class extends DatePicker {
2018-05-18 10:24:51 +02:00
onCreated() {
super.onCreated();
const self = this;
self.card = Cards.findOne(Session.get('currentCard'));
self.customFieldId = this.data()._id;
this.data().value && this.date.set(moment(this.data().value));
}
_storeDate(date) {
this.card.setCustomField(this.customFieldId, date);
}
_deleteDate() {
this.card.setCustomField(this.customFieldId, '');
}
2019-06-28 12:52:09 -05:00
}.register('cardCustomField-datePopup'));
2017-10-14 01:38:25 +02:00
// cardCustomField-dropdown
(class extends CardCustomField {
2018-05-18 10:24:51 +02:00
onCreated() {
super.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() {
2019-06-28 12:52:09 -05:00
const selected = this._items.find(item => {
2018-05-18 10:24:51 +02:00
return item._id === this.data().value;
});
2019-06-28 12:52:09 -05:00
return selected
? selected.name
: TAPi18n.__('custom-field-dropdown-unknown');
2018-05-18 10:24:51 +02:00
}
events() {
2019-06-28 12:52:09 -05:00
return [
{
'submit .js-card-customfield-dropdown'(event) {
event.preventDefault();
const value = this.find('select').value;
this.card.setCustomField(this.customFieldId, value);
},
2018-05-18 10:24:51 +02:00
},
2019-06-28 12:52:09 -05:00
];
2018-05-18 10:24:51 +02:00
}
2019-06-28 12:52:09 -05:00
}.register('cardCustomField-dropdown'));