Implement notComplete calls and refactor snapshotconnection a little
[potlatch2.git] / net / systemeD / potlatch2 / panels / BackgroundPanel.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!--
4     Background Panel
5 -->
6
7 <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" height="100%">
8   <mx:Text id="backgroundPanelText" text="You have selected a Background Feature." width="100%" styleName="helpInfo" />
9   <mx:DataGrid editable="false" id="backgroundPanelDG" width="100%" height="50%">
10     <mx:columns>
11       <mx:DataGridColumn editable="false" dataField="key" headerText="key" />
12       <mx:DataGridColumn editable="false" dataField="value" headerText="value" />
13     </mx:columns>
14   </mx:DataGrid>
15   <mx:ViewStack id="statusStack" resizeToContent="true" width="100%">
16     <mx:VBox id="empty" />
17     <mx:VBox id="not_complete">
18       <mx:Text text="All the data copied to the main layer? Click 'complete'!" />
19       <mx:Button label="Complete" click="markComplete()"/>
20     </mx:VBox>
21     <mx:VBox id="complete">
22       <mx:Text text="This feature has been marked as complete. If this is wrong, press the button below." />
23       <mx:Button label="Not complete" click="markNotComplete()"/>
24     </mx:VBox>
25   </mx:ViewStack>
26   <mx:Script><![CDATA[
27
28       import net.systemeD.halcyon.connection.*;
29       import net.systemeD.halcyon.MapPaint;
30       import net.systemeD.potlatch2.utils.SnapshotConnection;
31       import mx.collections.*;
32
33       private var selectedEntity:Entity;
34       private var tagDataProvider:ArrayCollection;
35       private var layer:MapPaint;
36
37       public function init(entity:Entity, layer:MapPaint):void {
38           this.layer = layer;
39           if ( tagDataProvider == null ) {
40               tagDataProvider = new ArrayCollection();
41               backgroundPanelDG.dataProvider = tagDataProvider;
42           }
43
44           selectedEntity=entity;
45           selectedEntity.addEventListener(Connection.STATUS_CHANGED, statusEvent, false, 0, true);
46           setStatusStack();
47           updateTagDataProvider();
48       }
49
50       private function updateTagDataProvider():void {
51           tagDataProvider.removeAll();
52           if (selectedEntity==null) { return; }
53           var tags:Array = selectedEntity.getTagArray();
54           tags.sortOn("key");
55           for each(var tag:Tag in tags) { tagDataProvider.addItem(tag); }
56       }
57
58       private function statusEvent(e:Event):void {
59             setStatusStack();
60       }
61
62       private function setStatusStack():void {
63           switch (selectedEntity.status) {
64               case 'incomplete':
65                   statusStack.selectedChild = not_complete;
66                   break;
67               case 'complete':
68                   statusStack.selectedChild = complete;
69                   break;
70               default:
71                   statusStack.selectedChild = empty;
72           }
73       }
74
75       private function markComplete():void {
76           if (selectedEntity.connection is SnapshotConnection) {
77               SnapshotConnection(selectedEntity.connection).markComplete(selectedEntity);
78           }
79       }
80
81       private function markNotComplete():void {
82           if (selectedEntity.connection is SnapshotConnection) {
83               SnapshotConnection(selectedEntity.connection).markNotComplete(selectedEntity);
84           }
85       }
86       ]]>
87   </mx:Script>
88 </mx:VBox>