5fb732d853fb9c2bac0e20b6794f3d3ec20a6f69
[potlatch2.git] / net / systemeD / potlatch2 / save / SaveDialog.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:TitleWindow
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         layout="vertical"
5         horizontalAlign="center" title="Save Changes"
6         width="350" height="250" verticalGap="0">
7
8   <mx:ArrayCollection id="changesetTags">
9     <mx:Object k="created_by" v="Potlatch 2"/>
10     <mx:Object k="version" v="x.xx.x"/>
11     <mx:Object k="comment" v=""/>
12   </mx:ArrayCollection>
13   
14   <mx:ViewStack id="processSequence" width="100%" height="100%">
15   
16     <!-- section for entering tags -->
17     <mx:VBox width="100%" height="100%" verticalGap="0">
18       <mx:ViewStack id="tagStack" width="100%" height="100%">
19         <mx:VBox width="100%" height="100%" label="Simple">
20           <mx:Text width="100%">
21             <mx:text>
22                Please enter a description of your edits. This will be used to give other
23                mappers an idea of what changes you are making.
24             </mx:text>
25           </mx:Text>
26           <mx:Label text="Comment:"/>
27           <mx:TextArea id="comment" width="100%" height="100%"/>
28         </mx:VBox>
29         
30         <mx:VBox width="100%" height="100%" label="Advanced">
31           <mx:Label text="Changeset tags:"/>
32           <mx:DataGrid editable="true" width="100%" height="100%" id="advancedTagGrid"
33               dataProvider="{changesetTags}">
34             <mx:columns>
35                 <mx:DataGridColumn editable="true" dataField="k" headerText="Key"/>
36                 <mx:DataGridColumn editable="true" dataField="v" headerText="Value"/>
37             </mx:columns>
38           </mx:DataGrid>        
39         </mx:VBox>
40       </mx:ViewStack>
41       <mx:LinkBar dataProvider="{tagStack}"/>
42     </mx:VBox>
43     
44     <mx:VBox width="100%" height="100%" id="createChangesetTab">
45       <mx:VBox width="100%" height="100%" id="infoBox"/>
46       <mx:Spacer height="100%"/>
47       <mx:ProgressBar label="Creating changeset" labelPlacement="bottom" width="100%"
48           indeterminate="true" id="saveProgress"/>
49     </mx:VBox>
50     
51     <mx:VBox width="100%" height="100%" id="failureTab">
52       <mx:Text width="100%" styleName="failText" text="{failureText}"/>
53     </mx:VBox>
54
55     <mx:VBox width="100%" height="100%" id="successTab">
56       <mx:Text width="100%">
57         <mx:htmlText><![CDATA[<b>All data uploaded!</b>]]></mx:htmlText>
58       </mx:Text>
59     </mx:VBox>
60   </mx:ViewStack>
61
62   <mx:ControlBar>
63     <mx:Spacer width="100%"/>
64     <mx:Button id="cancelButton" label="Cancel" click="close();"/>
65     <mx:Button id="saveButton" label="Save >" click="startSave();"/>
66   </mx:ControlBar>
67   
68   <mx:Script><![CDATA[
69   
70     import mx.controls.*;
71     import mx.managers.PopUpManager;
72     
73     import net.systemeD.halcyon.connection.*;
74     
75     private var conn:Connection = Connection.getConnectionInstance();
76     
77     [Bindable]
78     private var failureText:String = "";
79     
80     private function startSave():void {
81     
82         // move to next sequence
83         processSequence.selectedChild = createChangesetTab;
84         saveButton.enabled = false;
85         
86         var tags:Object = new Object();
87         for each (var tag:Object in changesetTags) {
88            tags[tag['k']] = tag['v'];
89         }
90         
91         // add the listeners
92         conn.addEventListener(Connection.NEW_CHANGESET, changesetCreated);
93         conn.addEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
94         conn.createChangeset(tags);
95     }
96     
97     private function changesetCreated(event:EntityEvent):void {
98         var changeset:Changeset = conn.getActiveChangeset();
99         addStatus("Changeset created (id: "+changeset.id+")");
100         
101         saveProgress.label = "Uploading changes";
102         conn.addEventListener(Connection.SAVE_COMPLETED, saveCompleted);
103         conn.uploadChanges();
104     }
105     
106     private function changesetError(event:Event):void {
107         fail("Error creating changeset");
108     }
109     
110     private function saveCompleted(event:SaveCompleteEvent):void {
111         if ( event.saveOK )
112             succeed("All Data Saved!");
113         else
114             fail("Failure when uploading data");
115
116         saveButton.parent.removeChild(saveButton);
117         cancelButton.label = "Close";
118     }
119     
120     private function addStatus(text:String):void {
121         var label:Text = new Text();
122         label.text = text;
123         
124         infoBox.addChild(label);
125     }
126     
127     private function succeed(text:String):void {
128         processSequence.selectedChild = successTab;
129     }
130     
131     private function fail(text:String):void {
132         processSequence.selectedChild = failureTab;
133         failureText = text;
134     }
135     
136     private function close():void {
137         conn.removeEventListener(Connection.NEW_CHANGESET, changesetCreated);
138         conn.removeEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
139         conn.removeEventListener(Connection.SAVE_COMPLETED, saveCompleted);
140         PopUpManager.removePopUp(this);
141     }
142   ]]></mx:Script>
143 </mx:TitleWindow>
144