|
@@ -1,3 +1,5 @@
|
|
|
|
+import moment from 'moment';
|
|
|
|
+
|
|
// Helper function to replace HH with H for 24 hours format, because H allows also single-digit hours
|
|
// Helper function to replace HH with H for 24 hours format, because H allows also single-digit hours
|
|
function adjustedTimeFormat() {
|
|
function adjustedTimeFormat() {
|
|
return moment
|
|
return moment
|
|
@@ -6,17 +8,17 @@ function adjustedTimeFormat() {
|
|
.replace(/HH/i, 'H');
|
|
.replace(/HH/i, 'H');
|
|
}
|
|
}
|
|
|
|
|
|
-DatePicker = BlazeComponent.extendComponent({
|
|
|
|
|
|
+export class DatePicker extends BlazeComponent {
|
|
template() {
|
|
template() {
|
|
return 'datepicker';
|
|
return 'datepicker';
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
onCreated(defaultTime = '1970-01-01 08:00:00') {
|
|
onCreated(defaultTime = '1970-01-01 08:00:00') {
|
|
this.error = new ReactiveVar('');
|
|
this.error = new ReactiveVar('');
|
|
this.card = this.data();
|
|
this.card = this.data();
|
|
this.date = new ReactiveVar(moment.invalid());
|
|
this.date = new ReactiveVar(moment.invalid());
|
|
this.defaultTime = defaultTime;
|
|
this.defaultTime = defaultTime;
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
startDayOfWeek() {
|
|
startDayOfWeek() {
|
|
const currentUser = Meteor.user();
|
|
const currentUser = Meteor.user();
|
|
@@ -25,7 +27,7 @@ DatePicker = BlazeComponent.extendComponent({
|
|
} else {
|
|
} else {
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
onRendered() {
|
|
onRendered() {
|
|
const $picker = this.$('.js-datepicker')
|
|
const $picker = this.$('.js-datepicker')
|
|
@@ -42,7 +44,7 @@ DatePicker = BlazeComponent.extendComponent({
|
|
this.error.set('');
|
|
this.error.set('');
|
|
const timeInput = this.find('#time');
|
|
const timeInput = this.find('#time');
|
|
timeInput.focus();
|
|
timeInput.focus();
|
|
- if (!timeInput.value) {
|
|
|
|
|
|
+ if (!timeInput.value && this.defaultTime) {
|
|
const currentHour = evt.date.getHours();
|
|
const currentHour = evt.date.getHours();
|
|
const defaultMoment = moment(
|
|
const defaultMoment = moment(
|
|
currentHour > 0 ? evt.date : this.defaultTime,
|
|
currentHour > 0 ? evt.date : this.defaultTime,
|
|
@@ -55,22 +57,22 @@ DatePicker = BlazeComponent.extendComponent({
|
|
if (this.date.get().isValid()) {
|
|
if (this.date.get().isValid()) {
|
|
$picker.datepicker('update', this.date.get().toDate());
|
|
$picker.datepicker('update', this.date.get().toDate());
|
|
}
|
|
}
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
showDate() {
|
|
showDate() {
|
|
if (this.date.get().isValid()) return this.date.get().format('L');
|
|
if (this.date.get().isValid()) return this.date.get().format('L');
|
|
return '';
|
|
return '';
|
|
- },
|
|
|
|
|
|
+ }
|
|
showTime() {
|
|
showTime() {
|
|
if (this.date.get().isValid()) return this.date.get().format('LT');
|
|
if (this.date.get().isValid()) return this.date.get().format('LT');
|
|
return '';
|
|
return '';
|
|
- },
|
|
|
|
|
|
+ }
|
|
dateFormat() {
|
|
dateFormat() {
|
|
return moment.localeData().longDateFormat('L');
|
|
return moment.localeData().longDateFormat('L');
|
|
- },
|
|
|
|
|
|
+ }
|
|
timeFormat() {
|
|
timeFormat() {
|
|
return moment.localeData().longDateFormat('LT');
|
|
return moment.localeData().longDateFormat('LT');
|
|
- },
|
|
|
|
|
|
+ }
|
|
|
|
|
|
events() {
|
|
events() {
|
|
return [
|
|
return [
|
|
@@ -106,7 +108,7 @@ DatePicker = BlazeComponent.extendComponent({
|
|
const dateString = `${evt.target.date.value} ${time}`;
|
|
const dateString = `${evt.target.date.value} ${time}`;
|
|
const newCompleteDate = moment(
|
|
const newCompleteDate = moment(
|
|
dateString,
|
|
dateString,
|
|
- 'L ' + adjustedTimeFormat(),
|
|
|
|
|
|
+ `L ${adjustedTimeFormat()}`,
|
|
true,
|
|
true,
|
|
);
|
|
);
|
|
if (!newTime.isValid()) {
|
|
if (!newTime.isValid()) {
|
|
@@ -120,10 +122,8 @@ DatePicker = BlazeComponent.extendComponent({
|
|
if (newCompleteDate.isValid()) {
|
|
if (newCompleteDate.isValid()) {
|
|
this._storeDate(newCompleteDate.toDate());
|
|
this._storeDate(newCompleteDate.toDate());
|
|
Popup.close();
|
|
Popup.close();
|
|
- } else {
|
|
|
|
- if (!this.error) {
|
|
|
|
- this.error.set('invalid');
|
|
|
|
- }
|
|
|
|
|
|
+ } else if (!this.error) {
|
|
|
|
+ this.error.set('invalid');
|
|
}
|
|
}
|
|
},
|
|
},
|
|
'click .js-delete-date'(evt) {
|
|
'click .js-delete-date'(evt) {
|
|
@@ -133,5 +133,5 @@ DatePicker = BlazeComponent.extendComponent({
|
|
},
|
|
},
|
|
},
|
|
},
|
|
];
|
|
];
|
|
- },
|
|
|
|
-});
|
|
|
|
|
|
+ }
|
|
|
|
+}
|