2018-03-26 19:04:02 +00:00
|
|
|
// Edit received, start, due & end dates
|
2018-07-03 23:57:05 +03:00
|
|
|
BlazeComponent.extendComponent({
|
2016-02-05 20:23:09 +01:00
|
|
|
template() {
|
|
|
|
return 'editCardDate';
|
|
|
|
},
|
|
|
|
|
|
|
|
onCreated() {
|
|
|
|
this.error = new ReactiveVar('');
|
|
|
|
this.card = this.data();
|
|
|
|
this.date = new ReactiveVar(moment.invalid());
|
|
|
|
},
|
|
|
|
|
|
|
|
onRendered() {
|
2016-02-11 15:02:26 +01:00
|
|
|
const $picker = this.$('.js-datepicker').datepicker({
|
2016-02-05 20:23:09 +01:00
|
|
|
todayHighlight: true,
|
|
|
|
todayBtn: 'linked',
|
2016-02-11 15:02:26 +01:00
|
|
|
language: TAPi18n.getLanguage(),
|
|
|
|
}).on('changeDate', function(evt) {
|
|
|
|
this.find('#date').value = moment(evt.date).format('L');
|
2016-02-05 20:23:09 +01:00
|
|
|
this.error.set('');
|
2016-02-11 15:02:26 +01:00
|
|
|
this.find('#time').focus();
|
2016-02-05 20:23:09 +01:00
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
if (this.date.get().isValid()) {
|
|
|
|
$picker.datepicker('update', this.date.get().toDate());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showDate() {
|
|
|
|
if (this.date.get().isValid())
|
|
|
|
return this.date.get().format('L');
|
2016-02-11 15:02:26 +01:00
|
|
|
return '';
|
2016-02-05 20:23:09 +01:00
|
|
|
},
|
|
|
|
showTime() {
|
|
|
|
if (this.date.get().isValid())
|
|
|
|
return this.date.get().format('LT');
|
2016-02-11 15:02:26 +01:00
|
|
|
return '';
|
2016-02-05 20:23:09 +01:00
|
|
|
},
|
|
|
|
dateFormat() {
|
|
|
|
return moment.localeData().longDateFormat('L');
|
|
|
|
},
|
|
|
|
timeFormat() {
|
|
|
|
return moment.localeData().longDateFormat('LT');
|
|
|
|
},
|
|
|
|
|
|
|
|
events() {
|
|
|
|
return [{
|
2016-02-11 15:02:26 +01:00
|
|
|
'keyup .js-date-field'() {
|
2016-02-05 20:23:09 +01:00
|
|
|
// parse for localized date format in strict mode
|
2016-02-11 15:02:26 +01:00
|
|
|
const dateMoment = moment(this.find('#date').value, 'L', true);
|
2016-02-05 20:23:09 +01:00
|
|
|
if (dateMoment.isValid()) {
|
|
|
|
this.error.set('');
|
|
|
|
this.$('.js-datepicker').datepicker('update', dateMoment.toDate());
|
|
|
|
}
|
|
|
|
},
|
2016-02-11 15:02:26 +01:00
|
|
|
'keyup .js-time-field'() {
|
2016-02-05 20:23:09 +01:00
|
|
|
// parse for localized time format in strict mode
|
2016-02-11 15:02:26 +01:00
|
|
|
const dateMoment = moment(this.find('#time').value, 'LT', true);
|
2016-02-05 20:23:09 +01:00
|
|
|
if (dateMoment.isValid()) {
|
|
|
|
this.error.set('');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'submit .edit-date'(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
// if no time was given, init with 12:00
|
2016-02-11 15:02:26 +01:00
|
|
|
const time = evt.target.time.value || moment(new Date().setHours(12, 0, 0)).format('LT');
|
|
|
|
|
|
|
|
const dateString = `${evt.target.date.value} ${time}`;
|
2016-02-05 22:35:56 +01:00
|
|
|
const newDate = moment(dateString, 'L LT', true);
|
2016-02-05 20:23:09 +01:00
|
|
|
if (newDate.isValid()) {
|
|
|
|
this._storeDate(newDate.toDate());
|
|
|
|
Popup.close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.error.set('invalid-date');
|
|
|
|
evt.target.date.focus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'click .js-delete-date'(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
this._deleteDate();
|
|
|
|
Popup.close();
|
|
|
|
},
|
|
|
|
}];
|
2017-03-18 18:49:39 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Template.dateBadge.helpers({
|
|
|
|
canModifyCard() {
|
|
|
|
return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
|
2016-02-05 20:23:09 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-26 19:04:02 +00:00
|
|
|
// editCardReceivedDatePopup
|
2018-05-25 19:44:49 +02:00
|
|
|
(class extends DatePicker {
|
2018-03-26 19:04:02 +00:00
|
|
|
onCreated() {
|
|
|
|
super.onCreated();
|
2018-04-17 23:17:44 -03:00
|
|
|
this.data().getReceived() && this.date.set(moment(this.data().getReceived()));
|
2018-03-26 19:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_storeDate(date) {
|
|
|
|
this.card.setReceived(date);
|
|
|
|
}
|
|
|
|
|
|
|
|
_deleteDate() {
|
2018-04-17 23:17:44 -03:00
|
|
|
this.card.setReceived(null);
|
2018-03-26 19:04:02 +00:00
|
|
|
}
|
|
|
|
}).register('editCardReceivedDatePopup');
|
|
|
|
|
|
|
|
|
2016-02-05 20:23:09 +01:00
|
|
|
// editCardStartDatePopup
|
2017-10-14 01:38:25 +02:00
|
|
|
(class extends DatePicker {
|
2016-02-05 20:23:09 +01:00
|
|
|
onCreated() {
|
2016-02-11 15:02:26 +01:00
|
|
|
super.onCreated();
|
2018-04-17 23:17:44 -03:00
|
|
|
this.data().getStart() && this.date.set(moment(this.data().getStart()));
|
2016-02-05 20:23:09 +01:00
|
|
|
}
|
|
|
|
|
2018-03-26 19:04:02 +00:00
|
|
|
onRendered() {
|
|
|
|
super.onRendered();
|
2018-04-17 23:17:44 -03:00
|
|
|
if (moment.isDate(this.card.getReceived())) {
|
|
|
|
this.$('.js-datepicker').datepicker('setStartDate', this.card.getReceived());
|
2018-03-26 19:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-05 20:23:09 +01:00
|
|
|
_storeDate(date) {
|
|
|
|
this.card.setStart(date);
|
|
|
|
}
|
|
|
|
|
|
|
|
_deleteDate() {
|
2018-04-17 23:17:44 -03:00
|
|
|
this.card.setStart(null);
|
2016-02-05 20:23:09 +01:00
|
|
|
}
|
|
|
|
}).register('editCardStartDatePopup');
|
|
|
|
|
|
|
|
// editCardDueDatePopup
|
2017-10-14 01:38:25 +02:00
|
|
|
(class extends DatePicker {
|
2016-02-05 20:23:09 +01:00
|
|
|
onCreated() {
|
2016-02-11 15:02:26 +01:00
|
|
|
super.onCreated();
|
2018-04-17 23:17:44 -03:00
|
|
|
this.data().getDue() && this.date.set(moment(this.data().getDue()));
|
2016-02-05 20:23:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onRendered() {
|
2016-02-11 15:02:26 +01:00
|
|
|
super.onRendered();
|
2018-04-17 23:17:44 -03:00
|
|
|
if (moment.isDate(this.card.getStart())) {
|
|
|
|
this.$('.js-datepicker').datepicker('setStartDate', this.card.getStart());
|
2016-02-05 20:23:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_storeDate(date) {
|
|
|
|
this.card.setDue(date);
|
|
|
|
}
|
|
|
|
|
|
|
|
_deleteDate() {
|
2018-04-17 23:17:44 -03:00
|
|
|
this.card.setDue(null);
|
2016-02-05 20:23:09 +01:00
|
|
|
}
|
|
|
|
}).register('editCardDueDatePopup');
|
|
|
|
|
2018-03-26 19:04:02 +00:00
|
|
|
// editCardEndDatePopup
|
2018-05-25 19:44:49 +02:00
|
|
|
(class extends DatePicker {
|
2018-03-26 19:04:02 +00:00
|
|
|
onCreated() {
|
|
|
|
super.onCreated();
|
2018-04-17 23:17:44 -03:00
|
|
|
this.data().getEnd() && this.date.set(moment(this.data().getEnd()));
|
2018-03-26 19:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onRendered() {
|
|
|
|
super.onRendered();
|
2018-04-17 23:17:44 -03:00
|
|
|
if (moment.isDate(this.card.getStart())) {
|
|
|
|
this.$('.js-datepicker').datepicker('setStartDate', this.card.getStart());
|
2018-03-26 19:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_storeDate(date) {
|
|
|
|
this.card.setEnd(date);
|
|
|
|
}
|
|
|
|
|
|
|
|
_deleteDate() {
|
2018-04-17 23:17:44 -03:00
|
|
|
this.card.setEnd(null);
|
2018-03-26 19:04:02 +00:00
|
|
|
}
|
|
|
|
}).register('editCardEndDatePopup');
|
|
|
|
|
2016-02-05 20:23:09 +01:00
|
|
|
|
2018-03-26 19:04:02 +00:00
|
|
|
// Display received, start, due & end dates
|
2016-02-05 20:23:09 +01:00
|
|
|
const CardDate = BlazeComponent.extendComponent({
|
|
|
|
template() {
|
|
|
|
return 'dateBadge';
|
|
|
|
},
|
|
|
|
|
|
|
|
onCreated() {
|
2016-02-11 15:02:26 +01:00
|
|
|
const self = this;
|
2016-02-05 22:35:56 +01:00
|
|
|
self.date = ReactiveVar();
|
|
|
|
self.now = ReactiveVar(moment());
|
2016-02-23 15:21:36 +01:00
|
|
|
window.setInterval(() => {
|
2016-02-05 22:35:56 +01:00
|
|
|
self.now.set(moment());
|
|
|
|
}, 60000);
|
2016-02-05 20:23:09 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
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, {
|
2016-02-11 15:02:26 +01:00
|
|
|
sameElse: 'llll',
|
2016-02-05 20:23:09 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
showISODate() {
|
|
|
|
return this.date.get().toISOString();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-26 19:04:02 +00:00
|
|
|
class CardReceivedDate extends CardDate {
|
|
|
|
onCreated() {
|
|
|
|
super.onCreated();
|
|
|
|
const self = this;
|
|
|
|
self.autorun(() => {
|
2018-04-17 23:17:44 -03:00
|
|
|
self.date.set(moment(self.data().getReceived()));
|
2018-03-26 19:04:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
classes() {
|
2018-06-27 16:25:57 +03:00
|
|
|
let classes = 'received-date ';
|
2018-04-17 23:17:44 -03:00
|
|
|
const dueAt = this.data().getDue();
|
|
|
|
const endAt = this.data().getEnd();
|
|
|
|
const startAt = this.data().getStart();
|
2018-07-31 22:01:14 +00:00
|
|
|
const theDate = this.date.get();
|
|
|
|
// if dueAt, endAt and startAt exist & are > receivedAt, receivedAt doesn't need to be flagged
|
|
|
|
if (((startAt) && (theDate.isAfter(dueAt))) ||
|
|
|
|
((endAt) && (theDate.isAfter(endAt))) ||
|
|
|
|
((dueAt) && (theDate.isAfter(dueAt))))
|
|
|
|
classes += 'long-overdue';
|
|
|
|
else
|
|
|
|
classes += 'current';
|
2018-03-26 19:04:02 +00:00
|
|
|
return classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
showTitle() {
|
|
|
|
return `${TAPi18n.__('card-received-on')} ${this.date.get().format('LLLL')}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
events() {
|
|
|
|
return super.events().concat({
|
|
|
|
'click .js-edit-date': Popup.open('editCardReceivedDate'),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CardReceivedDate.register('cardReceivedDate');
|
|
|
|
|
2016-02-05 21:01:43 +01:00
|
|
|
class CardStartDate extends CardDate {
|
2016-02-05 20:23:09 +01:00
|
|
|
onCreated() {
|
2016-02-11 15:02:26 +01:00
|
|
|
super.onCreated();
|
|
|
|
const self = this;
|
|
|
|
self.autorun(() => {
|
2018-04-17 23:17:44 -03:00
|
|
|
self.date.set(moment(self.data().getStart()));
|
2016-02-05 20:23:09 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-05 22:35:56 +01:00
|
|
|
classes() {
|
2018-01-04 18:34:39 +01:00
|
|
|
let classes = 'start-date' + ' ';
|
2018-08-11 00:50:20 +02:00
|
|
|
const dueAt = this.data().getDue();
|
|
|
|
const endAt = this.data().getEnd();
|
2018-07-31 22:01:14 +00:00
|
|
|
const theDate = this.date.get();
|
|
|
|
const now = this.now.get();
|
|
|
|
// if dueAt or endAt exist & are > startAt, startAt doesn't need to be flagged
|
|
|
|
if (((endAt) && (theDate.isAfter(endAt))) ||
|
|
|
|
((dueAt) && (theDate.isAfter(dueAt))))
|
|
|
|
classes += 'long-overdue';
|
|
|
|
else if (theDate.isBefore(now, 'minute'))
|
|
|
|
classes += 'almost-due';
|
|
|
|
else
|
|
|
|
classes += 'current';
|
2018-01-04 18:34:39 +01:00
|
|
|
return classes;
|
2016-02-05 22:35:56 +01:00
|
|
|
}
|
|
|
|
|
2016-02-10 15:51:55 +01:00
|
|
|
showTitle() {
|
2016-02-11 15:02:26 +01:00
|
|
|
return `${TAPi18n.__('card-start-on')} ${this.date.get().format('LLLL')}`;
|
2016-02-10 15:51:55 +01:00
|
|
|
}
|
|
|
|
|
2016-02-05 20:23:09 +01:00
|
|
|
events() {
|
|
|
|
return super.events().concat({
|
|
|
|
'click .js-edit-date': Popup.open('editCardStartDate'),
|
|
|
|
});
|
|
|
|
}
|
2016-02-05 21:01:43 +01:00
|
|
|
}
|
|
|
|
CardStartDate.register('cardStartDate');
|
2016-02-05 20:23:09 +01:00
|
|
|
|
2016-02-05 21:01:43 +01:00
|
|
|
class CardDueDate extends CardDate {
|
2016-02-05 20:23:09 +01:00
|
|
|
onCreated() {
|
2016-02-11 15:02:26 +01:00
|
|
|
super.onCreated();
|
|
|
|
const self = this;
|
|
|
|
self.autorun(() => {
|
2018-04-17 23:17:44 -03:00
|
|
|
self.date.set(moment(self.data().getDue()));
|
2016-02-05 20:23:09 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-05 22:35:56 +01:00
|
|
|
classes() {
|
2018-01-04 18:34:39 +01:00
|
|
|
let classes = 'due-date' + ' ';
|
2018-08-11 00:50:20 +02:00
|
|
|
const endAt = this.data().getEnd();
|
2018-06-27 16:25:57 +03:00
|
|
|
const theDate = this.date.get();
|
|
|
|
const now = this.now.get();
|
2018-07-31 22:01:14 +00:00
|
|
|
// if the due date is after the end date, green - done early
|
|
|
|
if ((endAt) && (theDate.isAfter(endAt)))
|
2018-06-13 22:18:00 +00:00
|
|
|
classes += 'current';
|
2018-07-31 22:01:14 +00:00
|
|
|
// if there is an end date, don't need to flag the due date
|
|
|
|
else if (endAt)
|
|
|
|
classes += '';
|
2018-06-27 16:25:57 +03:00
|
|
|
else if (now.diff(theDate, 'days') >= 2)
|
2018-01-04 18:34:39 +01:00
|
|
|
classes += 'long-overdue';
|
2018-06-27 16:25:57 +03:00
|
|
|
else if (now.diff(theDate, 'minute') >= 0)
|
2018-01-04 18:34:39 +01:00
|
|
|
classes += 'due';
|
2018-06-27 16:25:57 +03:00
|
|
|
else if (now.diff(theDate, 'days') >= -1)
|
2018-01-04 18:34:39 +01:00
|
|
|
classes += 'almost-due';
|
|
|
|
return classes;
|
2016-02-05 22:35:56 +01:00
|
|
|
}
|
|
|
|
|
2016-02-10 15:51:55 +01:00
|
|
|
showTitle() {
|
2016-02-11 15:02:26 +01:00
|
|
|
return `${TAPi18n.__('card-due-on')} ${this.date.get().format('LLLL')}`;
|
2016-02-10 15:51:55 +01:00
|
|
|
}
|
|
|
|
|
2016-02-05 20:23:09 +01:00
|
|
|
events() {
|
|
|
|
return super.events().concat({
|
|
|
|
'click .js-edit-date': Popup.open('editCardDueDate'),
|
|
|
|
});
|
|
|
|
}
|
2016-02-05 21:01:43 +01:00
|
|
|
}
|
|
|
|
CardDueDate.register('cardDueDate');
|
|
|
|
|
2018-03-26 19:04:02 +00:00
|
|
|
class CardEndDate extends CardDate {
|
|
|
|
onCreated() {
|
|
|
|
super.onCreated();
|
|
|
|
const self = this;
|
|
|
|
self.autorun(() => {
|
2018-04-17 23:17:44 -03:00
|
|
|
self.date.set(moment(self.data().getEnd()));
|
2018-03-26 19:04:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
classes() {
|
|
|
|
let classes = 'end-date' + ' ';
|
2018-08-11 00:50:20 +02:00
|
|
|
const dueAt = this.data().getDue();
|
2018-07-31 22:01:14 +00:00
|
|
|
const theDate = this.date.get();
|
2018-08-11 01:00:21 +02:00
|
|
|
if (theDate.diff(dueAt, 'days') >= 2)
|
2018-04-17 23:17:44 -03:00
|
|
|
classes += 'long-overdue';
|
2018-08-11 01:00:21 +02:00
|
|
|
else if (theDate.diff(dueAt, 'days') >= 0)
|
2018-04-17 23:17:44 -03:00
|
|
|
classes += 'due';
|
2018-08-11 01:00:21 +02:00
|
|
|
else if (theDate.diff(dueAt, 'days') >= -2)
|
2018-04-17 23:17:44 -03:00
|
|
|
classes += 'almost-due';
|
2018-03-26 19:04:02 +00:00
|
|
|
return classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
showTitle() {
|
|
|
|
return `${TAPi18n.__('card-end-on')} ${this.date.get().format('LLLL')}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
events() {
|
|
|
|
return super.events().concat({
|
|
|
|
'click .js-edit-date': Popup.open('editCardEndDate'),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CardEndDate.register('cardEndDate');
|
|
|
|
|
|
|
|
(class extends CardReceivedDate {
|
|
|
|
showDate() {
|
|
|
|
return this.date.get().format('l');
|
|
|
|
}
|
|
|
|
}).register('minicardReceivedDate');
|
|
|
|
|
2016-02-05 21:01:43 +01:00
|
|
|
(class extends CardStartDate {
|
|
|
|
showDate() {
|
|
|
|
return this.date.get().format('l');
|
|
|
|
}
|
|
|
|
}).register('minicardStartDate');
|
|
|
|
|
|
|
|
(class extends CardDueDate {
|
|
|
|
showDate() {
|
|
|
|
return this.date.get().format('l');
|
|
|
|
}
|
|
|
|
}).register('minicardDueDate');
|
2018-03-26 19:04:02 +00:00
|
|
|
|
|
|
|
(class extends CardEndDate {
|
|
|
|
showDate() {
|
|
|
|
return this.date.get().format('l');
|
|
|
|
}
|
|
|
|
}).register('minicardEndDate');
|