Merge branch 'master' into history
[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         width="100%"
9         toolTip="{fieldDescription}"
10         label="{fieldName}:">
11
12     <mx:CheckBox id="inputBox" creationComplete="initCheckbox()"
13                 labelPlacement="right" label=""
14                 change="value=toYesNo()" />
15
16
17   <fx:Script><![CDATA[
18   
19         protected function initCheckbox():void {
20                 // ** FIXME - these should really be bindings (selected="{...}"). 
21                 //    500 bonus points if you can get them to work as such, because I can't.
22                 inputBox.selected=parseBoolean(value);
23                 inputBox.label=checkValidity(value);
24                 dispatchEvent(new Event("factory_set"));
25         }
26
27         [Bindable(event="factory_set")]
28         protected function checkValidity(value:String):String {
29                 if (_factory==null || value==null) { return CheckboxEditorFactory(_factory).notPresentText; }
30                 var cv:String=value.toLowerCase();
31                 if (cv=='yes' || cv=='no' || cv=='1' || cv=='0' || cv=='true' || cv=='false') { return null; }
32                 return CheckboxEditorFactory(_factory).notBooleanText;
33         }
34
35         [Bindable(event="factory_set")]
36         protected function parseBoolean(value:String):Boolean {
37                 if (!value) { return false; }
38                 var cv:String=value.toLowerCase();
39                 if (cv=='yes' || cv=='1' || cv=='true') { return true; }
40                 return false;
41         }
42         
43         protected function toYesNo():String {
44                 inputBox.label='';
45                 return inputBox.selected ? 'yes':'no';
46         }
47         
48   ]]></fx:Script>
49 </edit:SingleTagEditor>
50