1 <?xml version="1.0" encoding="utf-8"?>
3 xmlns:mx="http://www.adobe.com/2006/mxml"
5 horizontalAlign="center" title="Save Changes"
6 width="350" height="330" verticalGap="0">
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="build" v="{Application.application.build_number}"/>
12 <mx:Object k="comment" v=""/>
15 <mx:ViewStack id="processSequence" width="100%" height="100%"
16 creationPolicy="all" creationComplete="if (doSkip) skipInput() else comment.setFocus()">
18 <!-- section for entering tags -->
19 <mx:VBox width="100%" height="100%" verticalGap="0">
20 <mx:ViewStack id="tagStack" width="100%" height="100%">
21 <mx:VBox width="100%" height="100%" label="Simple">
22 <mx:Text width="100%">
24 Please enter a description of your edits. This will be used to give other
25 mappers an idea of what changes you are making.
28 <mx:Label text="Comment:"/>
29 <mx:TextArea id="comment" width="100%" height="100%" change="commentChanged(event);" />
32 <mx:VBox width="100%" height="100%" label="Advanced">
33 <mx:Label text="Changeset tags:"/>
34 <mx:DataGrid editable="true" width="100%" id="advancedTagGrid"
35 dataProvider="{changesetTags}"
36 itemEditBeginning="allowForEdit(event)"
37 itemEditEnd="verifyInput(event)">
39 <mx:DataGridColumn editable="true" dataField="k" headerText="Key"/>
40 <mx:DataGridColumn editable="true" dataField="v" headerText="Value"/>
43 <mx:HBox horizontalAlign="right" width="100%">
44 <mx:LinkButton label="Delete" click="removeTag()" enabled="{advancedTagGrid.selectedItem != null? true : false}"/>
45 <mx:LinkButton label="Add" click="addNewTag()"/>
47 <mx:HRule width="100%" />
50 <mx:LinkBar dataProvider="{tagStack}"/>
53 <mx:VBox width="100%" height="100%" id="createChangesetTab">
54 <mx:VBox width="100%" height="100%" id="infoBox"/>
55 <mx:Spacer height="100%"/>
56 <mx:ProgressBar label="Creating changeset" labelPlacement="bottom" width="100%"
57 indeterminate="true" id="saveProgress"/>
60 <mx:VBox width="100%" height="100%" id="failureTab">
61 <mx:Text width="100%" styleName="failText" text="{failureText}"/>
64 <mx:VBox width="100%" height="100%" id="successTab">
65 <mx:Text width="100%">
66 <mx:htmlText><![CDATA[<b>All data uploaded!</b>]]></mx:htmlText>
72 <mx:Spacer width="100%"/>
73 <mx:Button id="cancelButton" label="Cancel" click="close();" styleName="titleWindowButton" />
74 <mx:Button id="saveButton" label="Save >" click="startSave();" styleName="titleWindowButton" />
80 import mx.managers.PopUpManager;
81 import mx.core.Application;
82 import mx.events.DataGridEvent;
83 import mx.events.DataGridEventReason;
85 import net.systemeD.halcyon.connection.*;
87 private var conn:Connection = Connection.getConnectionInstance();
88 private var doSkip:Boolean = false;
91 private var failureText:String = "";
93 public function dontPrompt():void {
94 if (processSequence.initialized) { skipInput(); } else { doSkip=true; }
97 private function skipInput():void {
98 processSequence.selectedChild = createChangesetTab;
99 saveButton.enabled = false;
103 private function commentChanged(event:Event):void {
104 for (var i:int=changesetTags.length-1; i>0; i--) {
105 if (changesetTags[i]['k']=='comment') { changesetTags.removeItemAt(i); }
107 changesetTags.addItem( { k:'comment', v: event.target.text } );
110 private function addNewTag():void {
111 changesetTags.addItem( { k:'(new key)', v:'(new value)' } );
112 advancedTagGrid.editedItemPosition = { rowIndex: changesetTags.length-1, columnIndex: 0 };
115 private function removeTag():void {
116 changesetTags.removeItemAt(advancedTagGrid.selectedIndex);
119 private function startSave():void {
121 // move to next sequence
122 processSequence.selectedChild = createChangesetTab;
123 saveButton.enabled = false;
125 var tags:Object = new Object();
126 for each (var tag:Object in changesetTags) {
127 tags[tag['k']] = tag['v'];
131 conn.addEventListener(Connection.NEW_CHANGESET, changesetCreated);
132 conn.addEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
133 conn.createChangeset(tags);
136 private function allowForEdit(event:DataGridEvent):void {
137 /* check before editing the tag grid that it's neither created_by nor version tags */
138 var item:Object = ((event.currentTarget as DataGrid).dataProvider as ArrayCollection)[event.rowIndex];
139 if(item.k == 'created_by' || item.k == 'version' || item.k == 'build') {
140 event.preventDefault();
144 private function verifyInput(event:DataGridEvent):void {
145 /* check before saving any change that the new key isn't created_by nor version */
146 // it is OK if the user cancels the edit
147 if( event.reason == DataGridEventReason.CANCELLED ) return;
149 var editor:TextInput = (event.currentTarget as DataGrid).itemEditorInstance as TextInput;
151 if( event.dataField == "k" ) {
152 if( editor.text == 'created_by' || editor.text == 'version' || editor.text == 'build') {
153 event.preventDefault();
158 private function changesetCreated(event:EntityEvent=null):void {
159 var changeset:Changeset = conn.getActiveChangeset();
160 addStatus("Saving to changeset "+changeset.id);
162 saveProgress.label = "Uploading changes";
163 conn.addEventListener(Connection.SAVE_COMPLETED, saveCompleted);
164 conn.uploadChanges();
167 private function changesetError(event:Event):void {
168 fail("Error creating changeset");
171 private function saveCompleted(event:SaveCompleteEvent):void {
173 succeed("All Data Saved!");
175 fail("Failure when uploading data");
177 saveButton.parent.removeChild(saveButton);
178 cancelButton.label = "Close";
181 private function addStatus(text:String):void {
182 var label:Text = new Text();
185 infoBox.addChild(label);
188 private function succeed(text:String):void {
189 processSequence.selectedChild = successTab;
192 private function fail(text:String):void {
193 processSequence.selectedChild = failureTab;
197 private function close():void {
198 conn.removeEventListener(Connection.NEW_CHANGESET, changesetCreated);
199 conn.removeEventListener(Connection.NEW_CHANGESET_ERROR, changesetError);
200 conn.removeEventListener(Connection.SAVE_COMPLETED, saveCompleted);
201 PopUpManager.removePopUp(this);