123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
'use strict';
modulum('DateTimeEditMobileWidget', ['DateTimeEditWidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.DateTimeEditMobileWidget = context.oo.Class(cls.DateTimeEditWidgetBase, function($super) {
return {
__name: 'DateTimeEditMobileWidget',
__dataContentPlaceholderSelector: '.gbc_dataContentPlaceholder',
_showSeconds: false,
_displayFormat: null,
_maxLength: -1,
_pickerLabel: null,
_initElement: function() {
$super._initElement.call(this, true);
this._displayFormat = 'MM/DD/YYYY HH:mm:ss';
this._inputElement.on('touchstart.DateTimeEditWidgetBase', this._onRequestFocus.bind(this));
this._inputElement.setAttribute("id", this.getRootClassName() + "_input");
this._pickerLabel = this._element.getElementsByTagName("label")[0];
this._inputElement.on("change.DateTimeEditWidgetBase", function(event) {
this.setValue(event.target.value);
this.emit(context.constants.widgetEvents.change);
}.bind(this));
},
destroy: function() {
this._inputElement.off("change.DateTimeEditWidgetBase");
$super.destroy.call(this);
},
_onIconClick: function(event) {
event.stopPropagation();
if (this.hasVMFocus() && this.isEnabled() && !this.isModal()) {
this._inputElement.domFocus();
}
this._onRequestFocus(event);
},
setEnabled: function(enabled) {
$super.setEnabled.call(this, enabled);
if (enabled) {
this._pickerLabel.setAttribute("for", this.getRootClassName() + "_input");
} else {
this._pickerLabel.removeAttribute("for");
}
},
setValue: function(value, fromVM) {
var dateObj;
if (value) {
if (fromVM) {
dateObj = context.dayjs(value, this._displayFormat);
if (dateObj.isValid()) {
this._inputElement.value = dateObj.format("YYYY-MM-DDTHH:mm:ss");
}
} else {
dateObj = context.dayjs(value, "YYYY-MM-DDTHH:mm:ss");
}
this._inputElement.setAttribute("data-date", dateObj.format(this._displayFormat));
} else {
if (fromVM) {
this._inputElement.value = value;
}
this._inputElement.setAttribute("data-date", value);
}
},
getValue: function() {
return this._inputElement.getAttribute("data-date");
},
setFormat: function(format) {
$super.setFormat.call(this, format);
if (this._showSeconds) {
this.getInputElement().setAttribute("step", "1");
} else {
this.getInputElement().removeAttribute("step");
}
},
_verifyWidgetValue: function(domEvent) {}
};
});
});