summaryrefslogtreecommitdiffstats
path: root/client/components/cards/cardCustomFields.js
diff options
context:
space:
mode:
authorPouyan Savoli <papoola@hotmail.com>2017-10-14 01:38:25 +0200
committerPouyan Savoli <papoola@hotmail.com>2017-10-14 01:38:25 +0200
commit8b16955cc27b29ae507be084adccc4fad61b05ef (patch)
treef701626bd102ec088bee7c6f6707f008645e2f30 /client/components/cards/cardCustomFields.js
parent3753337d60e17e5e72ec071aa4a1b28e36297d15 (diff)
downloadwekan-8b16955cc27b29ae507be084adccc4fad61b05ef.tar.gz
wekan-8b16955cc27b29ae507be084adccc4fad61b05ef.tar.bz2
wekan-8b16955cc27b29ae507be084adccc4fad61b05ef.zip
number + date fields
Diffstat (limited to 'client/components/cards/cardCustomFields.js')
-rw-r--r--client/components/cards/cardCustomFields.js103
1 files changed, 97 insertions, 6 deletions
diff --git a/client/components/cards/cardCustomFields.js b/client/components/cards/cardCustomFields.js
index f9fa760c..e014de4a 100644
--- a/client/components/cards/cardCustomFields.js
+++ b/client/components/cards/cardCustomFields.js
@@ -20,6 +20,7 @@ Template.cardCustomFieldsPopup.events({
}
});
+// cardCustomField
const CardCustomField = BlazeComponent.extendComponent({
getTemplate() {
@@ -28,6 +29,8 @@ const CardCustomField = BlazeComponent.extendComponent({
onCreated() {
const self = this;
+ self.card = Cards.findOne(Session.get('currentCard'));
+ self.customFieldId = this.data()._id;
},
canModifyCard() {
@@ -36,28 +39,118 @@ const CardCustomField = BlazeComponent.extendComponent({
});
CardCustomField.register('cardCustomField');
+// cardCustomField-text
(class extends CardCustomField {
onCreated() {
+ super.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);
+ this.card.setCustomField(this.customFieldId, value);
},
}];
}
}).register('cardCustomField-text');
+// cardCustomField-number
(class extends CardCustomField {
onCreated() {
+ super.onCreated();
+ }
+
+ events() {
+ return [{
+ 'submit .js-card-customfield-number'(evt) {
+ evt.preventDefault();
+ const value = parseInt(this.find('input').value);
+ this.card.setCustomField(this.customFieldId, value);
+ },
+ }];
+ }
+
+}).register('cardCustomField-number');
+
+// cardCustomField-date
+(class extends CardCustomField {
+
+ 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() {
+ // 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
+ return this.date.get().calendar(null, {
+ sameElse: 'llll',
+ });
+ }
+
+ showISODate() {
+ return this.date.get().toISOString();
+ }
+
+ classes() {
+ if (this.date.get().isBefore(this.now.get(), 'minute') &&
+ this.now.get().isBefore(this.data().value)) {
+ return 'current';
+ }
+ return '';
+ }
+
+ showTitle() {
+ return `${TAPi18n.__('card-start-on')} ${this.date.get().format('LLLL')}`;
+ }
+
+ events() {
+ return [{
+ 'click .js-edit-date': Popup.open('cardCustomField-date'),
+ }];
+ }
+
+}).register('cardCustomField-date');
+
+// cardCustomField-datePopup
+(class extends DatePicker {
+ 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, '');
+ }
+}).register('cardCustomField-datePopup');
+
+// cardCustomField-dropdown
+(class extends CardCustomField {
+
+ onCreated() {
+ super.onCreated();
this._items = this.data().definition.settings.dropdownItems;
this.items = this._items.slice(0);
this.items.unshift({
@@ -77,10 +170,8 @@ CardCustomField.register('cardCustomField');
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);
+ this.card.setCustomField(this.customFieldId, value);
},
}];
}