more
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / CheckboxEditor.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <edit:SingleTagEditor
3         xmlns:fx="http://ns.adobe.com/mxml/2009"
4         xmlns:mx="library://ns.adobe.com/flex/mx"
5     xmlns:s="library://ns.adobe.com/flex/spark"
6         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
7         xmlns:flexlib="flexlib.controls.*"
8         verticalGap="0"
9         width="100%"
10         toolTip="{fieldDescription}"
11     direction="horizontal">
12
13     <s:FormItem label="{fieldName}">
14       <mx:CheckBox id="inputBox" creationComplete="initCheckbox()"
15                   labelPlacement="right" label=""
16                   change="value=toYesNo()" />
17     </s:FormItem>
18
19   <fx:Script><![CDATA[
20   
21         protected function initCheckbox():void {
22                 // ** FIXME - these should really be bindings (selected="{...}"). 
23                 //    500 bonus points if you can get them to work as such, because I can't.
24                 inputBox.selected=parseBoolean(value);
25                 inputBox.label=checkValidity(value);
26                 dispatchEvent(new Event("factory_set"));
27         }
28
29         [Bindable(event="factory_set")]
30         protected function checkValidity(value:String):String {
31                 if (_factory==null || value==null) { return CheckboxEditorFactory(_factory).notPresentText; }
32                 var cv:String=value.toLowerCase();
33                 if (cv=='yes' || cv=='no' || cv=='1' || cv=='0' || cv=='true' || cv=='false') { return null; }
34                 return CheckboxEditorFactory(_factory).notBooleanText;
35         }
36
37         [Bindable(event="factory_set")]
38         protected function parseBoolean(value:String):Boolean {
39                 if (!value) { return false; }
40                 var cv:String=value.toLowerCase();
41                 if (cv=='yes' || cv=='1' || cv=='true') { return true; }
42                 return false;
43         }
44         
45         protected function toYesNo():String {
46                 inputBox.label='';
47                 return inputBox.selected ? 'yes':'no';
48         }
49         
50   ]]></fx:Script>
51 </edit:SingleTagEditor>
52