client/js/controls/numerictextcontrol/numerictextcontrol.coffee in rsence-pre-3.0.0.8 vs client/js/controls/numerictextcontrol/numerictextcontrol.coffee in rsence-pre-3.0.0.9
- old
+ new
@@ -1,30 +1,37 @@
#### = Description
## HNumericTextControl is an extension of HTextControl that
## validates the input as a number. It supports value ranges.
##
- ## If you need decimal numbers (floating-point), pass the
+ ## If you need decimal numbers (floating-point), pass the
## decimalNumber: true option to the constructor.
####
HNumericTextControl = HTextControl.extend
-
+
defaultEvents:
mouseWheel: true
- textEnter: true
contextMenu: true
keyDown: true
+ textEnter: false
+ click: true
+ contextMenu: true
controlDefaults: HTextControl.prototype.controlDefaults.extend
numberIncrement: 1
decimalNumber: false
- decimalPlaces: -1
- decimalSeparator: '.'
+ decimalPlaces: null
+ decimalSeparator: null
withStepper: false
-
+ unit: false
+
+ customOptions: (_options)->
+ _options.decimalSeparator = HLocale.general.decimalSeparator unless _options.decimalSeparatator?
+
## Uses the mouseWheel event to step up/down the value.
mouseWheel: (_delta)->
_value = @value
+ _value = parseInt(_value,10) if @typeChr(_value) == 's'
if _delta < 0
_value = _value-@options.numberIncrement
else
_value = _value+@options.numberIncrement
_value = @validateNumber(_value)
@@ -41,11 +48,11 @@
_numbers: ['0','1','2','3','4','5','6','7','8','9']
validateNumber: (_value)->
if @options.decimalNumber
_value = parseFloat(_value)
- if @options.decimalPlaces != -1
+ if @options.decimalPlaces != null
_decPlaces = Math.pow(10,@options.decimalPlaces)
_value = Math.round(_value*_decPlaces)/_decPlaces
else
_value = parseInt( _value, 10 )
if isNaN( _value )
@@ -67,11 +74,11 @@
continue unless ~@_numbers.indexOf(_chr)
_value += _chr
@validateNumber( _value )
valueToField: (_value)->
_value = @validateNumber(_value)
- if @options.decimalNumber and @options.decimalPlaces != -1
+ if @options.decimalNumber and @options.decimalPlaces != null
if _value - Math.round(_value) == 0
_value = _value+@options.decimalSeparator
for n in [0...@options.decimalPlaces]
_value += '0'
else
@@ -84,17 +91,19 @@
### = Description
## Extends the validateText method to ensure the
## input is a number.
###
- validateText: (_value)-> _value
+ # validateText: (_value)-> _value
+ _extraLabelRight: 0
drawSubviews: ->
@base()
@setStyleOfPart('value','textAlign','right')
if @options.withStepper
- @setStyleOfPart('label','right','14px')
+ this._extraLabelRight += 14
+ @setStyleOfPart('label','right',this._extraLabelRight+'px')
_top = Math.round((@rect.height-22)/2)
@stepper = HStepper.extend(
refreshValue: ->
@base()
@parent.setValue(@value)
@@ -105,5 +114,18 @@
maxValue: @maxValue
stepSize: @options.numberIncrement
enabled: @enabled
)
@stepper.bringToFront()
+ if @options.unit
+ _unitRect = [null,null,4,@rect.height,4,0]
+ @unitSuffix = HLabel.new(_unitRect,@,
+ pack: true
+ label: @options.unit
+ style:
+ lineHeight: @rect.height+'px'
+ verticalAlign: 'middle'
+ )
+ @_extraLabelRight += @unitSuffix.rect.width
+ @setStyleOfPart('label','right',this._extraLabelRight+'px')
+
+HNumberField = HNumericTextControl