123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
'use strict';
modulum('TimeEditMobileWidget', ['TimeEditWidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.TimeEditMobileWidget = context.oo.Class(cls.TimeEditWidgetBase, function($super) {
return {
__name: 'TimeEditMobileWidget',
_pickerLabel: null,
_pickerIcon: null,
_initElement: function() {
$super._initElement.call(this);
this._pickerIcon = this._element.getElementsByClassName('widget-decoration')[0];
this._inputElement = this._element.getElementsByTagName('input')[0];
this.setValue('00:00:00');
this._inputElement.on("change.TimeEditMobileWidget", function(event) {
var val = this._inputElement.value;
if (window.isIOS() && this._useSeconds) {
val += ":00";
}
this._inputElement.setAttribute("data-time", val);
this.emit(context.constants.widgetEvents.change);
}.bind(this));
this._element.on('touchstart.TimeEditMobileWidget', this._onRequestFocus.bind(this));
this._inputElement.setAttribute("id", this.getRootClassName() + "_input");
this._pickerLabel = this._element.getElementsByTagName("label")[0];
},
setEnabled: function(enabled) {
$super.setEnabled.call(this, enabled);
if (enabled) {
this._pickerLabel.setAttribute("for", this.getRootClassName() + "_input");
} else {
this._pickerLabel.removeAttribute("for");
}
},
manageMouseClick: function(domEvent) {
var target = domEvent.target;
if (target.isElementOrChildOf(this._inputElement) || target.isElementOrChildOf(this._pickerIcon)) {
this._onRequestFocus(domEvent);
}
return true;
},
destroy: function() {
this._element.off('touchstart.TimeEditMobileWidget');
this._inputElement.off('change.TimeEditMobileWidget');
$super.destroy.call(this);
},
setDisplayFormat: function(format) {
$super.setDisplayFormat.call(this, format);
this._updateFormat();
},
setValue: function(value, fromVM) {
if (this.getValue() !== value) {
this._setTimeAccuracy(value);
if (fromVM) {
this._updateFormat();
}
$super.setValue.call(this, value, fromVM);
this._inputElement.setAttribute("data-time", value);
}
},
_updateFormat: function() {
if (this._useSeconds) {
this._inputElement.setAttribute("step", "1");
} else {
this._inputElement.removeAttribute("step");
}
},
getValue: function() {
return this._inputElement.getAttribute("data-time");
},
_verifyWidgetValue: function(domEvent) {}
};
});
});