123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
'use strict';
modulum('SpinEditWidget', ['SpinEditWidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.SpinEditWidget = context.oo.Class(cls.SpinEditWidgetBase, function($super) {
return {
__name: 'SpinEditWidget',
managePriorityKeyDown: function(keyString, domKeyEvent, repeat) {
if (this.isEnabled()) {
if (keyString === "home" && this.getMin() !== null) {
return false;
} else if (keyString === "end" && this.getMax() !== null) {
return false;
}
}
return $super.managePriorityKeyDown.call(this, keyString, domKeyEvent, repeat);
},
manageKeyDown: function(keyString, domKeyEvent, repeat) {
var keyProcessed = false;
var widgetText = this.getValue().toString();
var res = this._checkValue('', widgetText);
if (res === widgetText) {
this._elementState.backup(this._inputElement);
}
if (this.isEnabled() && !this.isReadOnly()) {
keyProcessed = true;
var updateValue = 0;
switch (keyString) {
case "down":
updateValue = -1;
break;
case "pagedown":
updateValue = -10;
break;
case "up":
updateValue = 1;
break;
case "pageup":
updateValue = 10;
break;
case "home":
var min = this.getMin();
if (min !== null) {
this.setEditing(this._oldValue !== min);
this.setValue(min);
this.emit(context.constants.widgetEvents.change, false);
}
break;
case "end":
var max = this.getMax();
if (max !== null) {
this.setEditing(this._oldValue !== max);
this.setValue(max);
this.emit(context.constants.widgetEvents.change, false);
}
break;
default:
keyProcessed = this._processKey(domKeyEvent, keyString);
}
if (updateValue !== 0) {
this._updateValue(updateValue);
this.emit(context.constants.widgetEvents.change, false, true);
}
}
if (keyProcessed) {
return true;
} else {
return $super.manageKeyDown.call(this, keyString, domKeyEvent, repeat);
}
},
};
});
cls.WidgetFactory.registerBuilder('SpinEdit', cls.SpinEditWidget);
});