0
1
Fork 0
hedera-web-mindshore/js/htk/date-chooser/index.js

74 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-06-06 08:53:59 +00:00
require('./style.scss');
var Calendar = require('../calendar');
2022-06-06 08:53:59 +00:00
module.exports = new Class({
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');
2022-06-06 17:13:57 +00:00
node.classList.add('input');
2022-05-25 18:04:16 +00:00
node.addEventListener('click', this._onClick.bind(this));
this.label = this.createElement('span');
node.appendChild(this.label);
2022-05-25 18:04:16 +00:00
const dropDown = new Htk.Icon({
name: 'expand_more'
});
node.appendChild(dropDown.node);
this.setEditable(this._editable);
}
2022-05-25 18:04:16 +00:00
,putValue: function(value) {
var dateString;
if (value instanceof Date)
2022-05-25 18:04:16 +00:00
dateString = Vn.Date.strftime(value, this.format);
else
dateString = '';
2022-05-25 18:04:16 +00:00
Vn.Node.setText(this.label, dateString);
}
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();
this.popup.child = this.calendar;
}
}
2022-05-25 18:04:16 +00:00
,_onCalendarChange: function(calendar) {
if (this.ignoreCalendarChange)
return;
2022-05-25 18:04:16 +00:00
this.popup.hide();
var newDate = calendar.value;
2022-05-25 18:04:16 +00:00
this.putValue(newDate);
this.valueChanged(newDate);
}
2022-05-25 18:04:16 +00:00
,_onClick: function() {
this.ignoreCalendarChange = true;
this.calendar.value = this._value;
2022-05-25 18:04:16 +00:00
this.calendar.goToSelectedMonth();
this.ignoreCalendarChange = false;
2015-03-06 23:33:54 +00:00
2022-05-25 18:04:16 +00:00
this.popup.show(this.node);
}
});