2022-06-06 08:53:59 +00:00
|
|
|
require('./style.scss');
|
|
|
|
var Calendar = require('../calendar');
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
module.exports = new Class({
|
2015-01-23 13:09:30 +00:00
|
|
|
Extends: Htk.Field
|
|
|
|
,Tag: 'htk-date-chooser'
|
|
|
|
|
|
|
|
,format: _('%a, %e %b %Y')
|
|
|
|
,calendar: null
|
|
|
|
,ignoreCalendarChange: false
|
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
,render: function() {
|
|
|
|
const node = this.createRoot('button');
|
|
|
|
node.className = 'htk-date-chooser input';
|
|
|
|
node.addEventListener('click', this._onClick.bind(this));
|
|
|
|
|
|
|
|
this.label = this.createElement('span');
|
|
|
|
node.appendChild(this.label);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
const dropDown = new Htk.Icon({
|
|
|
|
name: 'expand_more'
|
|
|
|
});
|
|
|
|
node.appendChild(dropDown.node);
|
|
|
|
|
|
|
|
this.setEditable(this._editable);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
,putValue: function(value) {
|
2015-01-23 13:09:30 +00:00
|
|
|
var dateString;
|
|
|
|
|
|
|
|
if (value instanceof Date)
|
2022-05-25 18:04:16 +00:00
|
|
|
dateString = Vn.Date.strftime(value, this.format);
|
2015-01-23 13:09:30 +00:00
|
|
|
else
|
|
|
|
dateString = '';
|
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
Vn.Node.setText(this.label, dateString);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
,setEditable: function(editable) {
|
|
|
|
if (this.calendar) {
|
|
|
|
this.calendar.disconnectByInstance(this);
|
2015-12-10 13:48:43 +00:00
|
|
|
this.calendar = null;
|
|
|
|
}
|
2022-05-25 18:04:16 +00:00
|
|
|
if (editable) {
|
|
|
|
this.calendar = new Calendar();
|
|
|
|
this.calendar.on('changed', this._onCalendarChange.bind(this));
|
2015-03-06 23:33:54 +00:00
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
this.popup = new Htk.Popup();
|
2016-10-20 08:37:08 +00:00
|
|
|
this.popup.child = this.calendar;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
,_onCalendarChange: function(calendar) {
|
2015-01-23 13:09:30 +00:00
|
|
|
if (this.ignoreCalendarChange)
|
|
|
|
return;
|
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
this.popup.hide();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var newDate = calendar.value;
|
2022-05-25 18:04:16 +00:00
|
|
|
this.putValue(newDate);
|
|
|
|
this.valueChanged(newDate);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
,_onClick: function() {
|
2015-01-23 13:09:30 +00:00
|
|
|
this.ignoreCalendarChange = true;
|
|
|
|
this.calendar.value = this._value;
|
2022-05-25 18:04:16 +00:00
|
|
|
this.calendar.goToSelectedMonth();
|
2015-01-23 13:09:30 +00:00
|
|
|
this.ignoreCalendarChange = false;
|
2015-03-06 23:33:54 +00:00
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
this.popup.show(this.node);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|