view class doc
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109/// FOURJS_START_COPYRIGHT(D,2015)
/// Property of Four Js*
/// (c) Copyright Four Js 2015, 2024. All Rights Reserved.
/// * Trademark of Four Js Development Tools Europe Ltd
///   in the United States and elsewhere
///
/// This file can be modified by licensees according to the
/// product manual.
/// FOURJS_END_COPYRIGHT

'use strict';

modulum('SpinEditWidget', ['SpinEditWidgetBase', 'WidgetFactory'],
  function(context, cls) {

    /**
     * SpinEdit widget.
     * @class SpinEditWidget
     * @memberOf classes
     * @extends classes.SpinEditWidgetBase
     * @publicdoc Widgets
     */
    cls.SpinEditWidget = context.oo.Class(cls.SpinEditWidgetBase, function($super) {
      return /** @lends classes.SpinEditWidget.prototype */ {
        __name: 'SpinEditWidget',

        /**
         * @inheritDoc
         */
        managePriorityKeyDown: function(keyString, domKeyEvent, repeat) {
          if (this.isEnabled()) {
            if (keyString === "home" && this.getMin() !== null) {
              return false; // don't process this key it will be processed in manageKeyDown function
            } else if (keyString === "end" && this.getMax() !== null) {
              return false; // don't process this key it will be processed in manageKeyDown function
            }
          }

          return $super.managePriorityKeyDown.call(this, keyString, domKeyEvent, repeat);
        },

        /**
         * @inheritDoc
         */
        manageKeyDown: function(keyString, domKeyEvent, repeat) {
          var keyProcessed = false;
          var widgetText = this.getValue().toString();
          var res = this._checkValue('', widgetText);
          //Save the last valid value
          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);
              //No autonext must be applied
              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);
  });