a80dd14f787f8c0dd70997aebff057fb110ffaa0
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / NumberEditor.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <edit:SingleTagEditor
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
5         xmlns:flexlib="flexlib.controls.*"
6         verticalGap="0"
7         width="100%"
8         toolTip="{fieldDescription}"
9     direction="{fieldDirection}" styleName="titledEditor">
10
11         <mx:Label text="{fieldName}:"/>
12     <mx:HBox horizontalGap="3" verticalAlign="middle">
13             <mx:NumericStepper id="input"
14                  minimum="{minimum}" maximum="{maximum}"
15                  stepSize="{stepSize}"
16                  value="{translatedValue}"
17                  enabled="{isValueValid}"
18                                  change="value = input.value.toString()" />
19         <mx:Label text="{prompt}" visible="{value == null || value == ''}"/>
20     </mx:HBox>
21
22   <mx:Script><![CDATA[
23     [Bindable(event="factory_set")]
24     protected function get prompt():String {
25         return _factory == null ? null : NumberEditorFactory(_factory).notPresentText;
26     }
27
28     [Bindable(event="factory_set")]
29     public function get minimum():Number {
30         return NumberEditorFactory(_factory) == null ? 0 : NumberEditorFactory(_factory).minimum;
31     }
32
33     [Bindable(event="factory_set")]
34     public function get maximum():Number {
35         return NumberEditorFactory(_factory) == null ? 100 : NumberEditorFactory(_factory).maximum;
36     }
37
38     [Bindable(event="factory_set")]
39     public function get stepSize():Number {
40         return NumberEditorFactory(_factory) == null ? 1 : NumberEditorFactory(_factory).stepSize;
41     }
42
43     [Bindable(event="tag_changed")]
44     private function get translatedValue():Number {
45         var validatedValue:Number = getValidatedValue();
46         return validatedValue;
47     }
48
49     [Bindable(event="tag_changed")]
50     private function get isValueValid():Boolean {
51         var validatedValue:Number = getValidatedValue();
52         return !(isNaN(validatedValue) && value != null && value != "");
53     }
54
55     private function getValidatedValue():Number {
56         var valueStr:String = value;
57         if ( valueStr == null || valueStr == "" )
58             return Number.NaN;
59
60         var parsed:Number = parseFloat(value);
61         if ( isNaN(parsed) || parsed < minimum || parsed > maximum )
62             return Number.NaN;
63         return parsed;
64     }
65         
66   ]]></mx:Script>
67 </edit:SingleTagEditor>
68