a3fa522e9089941eeacc5aa3c0b7b28c95869d02
[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="330" verticalGap="0">
7
8   <mx:ArrayCollection id="changesetTags">
9     <mx:Object k="created_by" v="Potlatch 2"/>
10     <mx:Object k="version" v="{Application.application.version}"/>
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%" change="commentChanged(event);" />
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%" 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:HBox horizontalAlign="right" width="100%">
40                     <mx:LinkButton label="Delete" click="removeTag()" enabled="{advancedTagGrid.selectedItem != null? true : false}"/>
41                     <mx:LinkButton label="Add" click="addNewTag()"/>
42                   </mx:HBox>
43                   <mx:HRule width="100%" />
44         </mx:VBox>
45       </mx:ViewStack>
46       <mx:LinkBar dataProvider="{tagStack}"/>
47     </mx:VBox>
48     
49     <mx:VBox width="100%" height="100%" id="createChangesetTab">
50       <mx:VBox width="100%" height="100%" id="infoBox"/>
51       <mx:Spacer height="100%"/>
52       <mx:ProgressBar label="Creating changeset" labelPlacement="bottom" width="100%"
53           indeterminate="true" id="saveProgress"/>
54     </mx:VBox>
55     
56     <mx:VBox width="100%" height="100%" id="failureTab">
57       <mx:Text width="100%" styleName="failText" text="{failureText}"/>
58     </mx:VBox>
59
60     <mx:VBox width="100%" height="100%" id="successTab">
61       <mx:Text width="100%">
62         <mx:htmlText><![CDATA[<b>All data uploaded!</b>]]></mx:htmlText>
63       </mx:Text>
64     </mx:VBox>
65   </mx:ViewStack>
66
67   <mx:ControlBar>
68     <mx:Spacer width="100%"/>
69     <mx:Button id="cancelButton" label="Cancel" click="close();"/>
70     <mx:Button id="saveButton" label="Save >" click="startSave();"/>
71   </mx:ControlBar>
72   
73   <mx:Script><![CDATA[
74   
75     import mx.controls.*;
76     import mx.managers.PopUpManager;
77         import mx.core.Application;
78     
79     import net.systemeD.halcyon.connection.*;
80     
81     private var conn:Connection = Connection.getConnectionInstance();
82     
83     [Bindable]
84     private var failureText:String = "";
85
86         private function commentChanged(event:Event):void {
87                 for (var i:int=changesetTags.length-1; i>0; i--) {
88                         if (changesetTags[i]['k']=='comment') { changesetTags.removeItemAt(i); }
89                 }
90                 changesetTags.addItem( { k:'comment', v: event.target.text } );
91     }
92
93         private function addNewTag():void {
94                 changesetTags.addItem( { k:'(new key)', v:'(new value)' } );
95                 advancedTagGrid.editedItemPosition = { rowIndex: changesetTags.length-1, columnIndex: 0 };
96         }
97
98         private function removeTag():void {
99                 changesetTags.removeItemAt(advancedTagGrid.selectedIndex);
100         }
101     
102     private function startSave():void {
103     
104         // move to next sequence
105         processSequence.selectedChild = createChangesetTab;
106         saveButton.enabled = false;
107         
108         var tags:Object = new Object();
109         for each (var tag:Object in changesetTags) {
110            tags[tag['k']] = tag['v'];
111         }
112         
113         // add the listeners
114         conn.addEventListener(Connection.NEW_CHANGESET, changesetCreated);
115         conn.addEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
116         conn.createChangeset(tags);
117     }
118
119     private function changesetCreated(event:EntityEvent):void {
120         var changeset:Changeset = conn.getActiveChangeset();
121         addStatus("Changeset created (id: "+changeset.id+")");
122         
123         saveProgress.label = "Uploading changes";
124         conn.addEventListener(Connection.SAVE_COMPLETED, saveCompleted);
125         conn.uploadChanges();
126     }
127     
128     private function changesetError(event:Event):void {
129         fail("Error creating changeset");
130     }
131     
132     private function saveCompleted(event:SaveCompleteEvent):void {
133         if ( event.saveOK )
134             succeed("All Data Saved!");
135         else
136             fail("Failure when uploading data");
137
138         saveButton.parent.removeChild(saveButton);
139         cancelButton.label = "Close";
140     }
141     
142     private function addStatus(text:String):void {
143         var label:Text = new Text();
144         label.text = text;
145         
146         infoBox.addChild(label);
147     }
148     
149     private function succeed(text:String):void {
150         processSequence.selectedChild = successTab;
151     }
152     
153     private function fail(text:String):void {
154         processSequence.selectedChild = failureTab;
155         failureText = text;
156     }
157     
158     private function close():void {
159         conn.removeEventListener(Connection.NEW_CHANGESET, changesetCreated);
160         conn.removeEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
161         conn.removeEventListener(Connection.SAVE_COMPLETED, saveCompleted);
162         PopUpManager.removePopUp(this);
163     }
164   ]]></mx:Script>
165 </mx:TitleWindow>
166