2018-02-14 18:20:56 +05:30
|
|
|
const flatpickr = require('flatpickr');
|
|
|
|
const BaseControl = require('./base');
|
2018-02-21 15:08:56 +05:30
|
|
|
const frappe = require('frappejs');
|
2018-02-14 18:20:56 +05:30
|
|
|
|
|
|
|
class DateControl extends BaseControl {
|
|
|
|
make() {
|
2018-02-21 15:08:56 +05:30
|
|
|
let dateFormat = {
|
|
|
|
'yyyy-mm-dd': 'Y-m-d',
|
|
|
|
'dd/mm/yyyy': 'd/m/Y',
|
|
|
|
'dd-mm-yyyy': 'd-m-Y',
|
|
|
|
'mm/dd/yyyy': 'm/d/Y',
|
|
|
|
'mm-dd-yyyy': 'm-d-Y'
|
|
|
|
}
|
2018-04-24 13:26:28 +05:30
|
|
|
let altFormat = frappe.SystemSettings ?
|
|
|
|
dateFormat[frappe.SystemSettings.dateFormat] :
|
|
|
|
dateFormat['yyyy-mm-dd'];
|
2018-02-21 15:08:56 +05:30
|
|
|
|
2018-02-14 18:20:56 +05:30
|
|
|
super.make();
|
|
|
|
this.input.setAttribute('type', 'text');
|
2018-05-08 12:48:47 +05:30
|
|
|
this.flatpickr = flatpickr(this.input, {
|
2018-02-21 15:08:56 +05:30
|
|
|
altInput: true,
|
|
|
|
altFormat: altFormat,
|
|
|
|
dateFormat:'Y-m-d'
|
2018-02-14 18:20:56 +05:30
|
|
|
});
|
|
|
|
}
|
2018-02-21 15:08:56 +05:30
|
|
|
|
2018-02-27 21:59:14 +05:30
|
|
|
setDisabled() {
|
|
|
|
this.input.disabled = this.isDisabled();
|
|
|
|
if (this.flatpickr && this.flatpickr.altInput) {
|
|
|
|
this.flatpickr.altInput.disabled = this.isDisabled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 15:08:56 +05:30
|
|
|
setInputValue(value) {
|
|
|
|
super.setInputValue(value);
|
|
|
|
this.flatpickr.setDate(value);
|
|
|
|
}
|
2018-02-14 18:20:56 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = DateControl;
|