more turn restriction stuff, and checkboxes, and a bunch of little fixes
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / CheckboxEditor.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
10         <mx:HBox>
11         <mx:Label text="{fieldName}:"/>
12         <mx:CheckBox id="inputBox" creationComplete="initCheckbox()"
13                                  labelPlacement="right" label=""
14                                  change="value=toYesNo()" />
15         </mx:HBox>
16   <mx:Script><![CDATA[
17   
18         protected function initCheckbox():void {
19                 // ** FIXME - these should really be bindings (selected="{...}"). 
20                 //    500 bonus points if you can get them to work as such, because I can't.
21                 inputBox.selected=parseBoolean(value);
22                 inputBox.label=checkValidity(value);
23                 dispatchEvent(new Event("factory_set"));
24         }
25
26         [Bindable(event="factory_set")]
27         protected function checkValidity(value:String):String {
28                 if (_factory==null || value==null) { return CheckboxEditorFactory(_factory).notPresentText; }
29                 var cv:String=value.toLowerCase();
30                 if (cv=='yes' || cv=='no' || cv=='1' || cv=='0' || cv=='true' || cv=='false') { return null; }
31                 return CheckboxEditorFactory(_factory).notBooleanText;
32         }
33
34         [Bindable(event="factory_set")]
35         protected function parseBoolean(value:String):Boolean {
36                 if (!value) { return false; }
37                 var cv:String=value.toLowerCase();
38                 if (cv=='yes' || cv=='1' || cv=='true') { return true; }
39                 return false;
40         }
41         
42         protected function toYesNo():String {
43                 inputBox.label='';
44                 return inputBox.selected ? 'yes':'no';
45         }
46         
47   ]]></mx:Script>
48 </edit:SingleTagEditor>
49