1 | <?xml version="1.0" encoding="utf-8"?> |
---|
2 | |
---|
3 | <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" |
---|
4 | xmlns:comp="clarin.cmdi.componentregistry.common.components.*" |
---|
5 | xmlns:common="clarin.cmdi.componentregistry.common.*" |
---|
6 | xmlns:rictus="com.rictus.controls.*" |
---|
7 | creationComplete="scrollToSelected()"> |
---|
8 | |
---|
9 | <mx:Metadata> |
---|
10 | [Event(name="browserItemSelected",type="clarin.cmdi.componentregistry.browser.BrowserSelectionEvent")] |
---|
11 | [Event(name="createNew", type="clarin.cmdi.componentregistry.browser.CreateNewComponentEvent")] |
---|
12 | </mx:Metadata> |
---|
13 | |
---|
14 | <mx:Array id="browserColumns"/> |
---|
15 | |
---|
16 | <mx:Script> |
---|
17 | <![CDATA[ |
---|
18 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
19 | import clarin.cmdi.componentregistry.common.components.BrowseContextMenu; |
---|
20 | import clarin.cmdi.componentregistry.common.components.RegistryViewStack; |
---|
21 | import clarin.cmdi.componentregistry.common.components.RssDescriptionsContextMenu; |
---|
22 | import clarin.cmdi.componentregistry.services.Config; |
---|
23 | import clarin.cmdi.componentregistry.common.StyleConstants; |
---|
24 | |
---|
25 | import flash.events.ContextMenuEvent; |
---|
26 | import flash.ui.ContextMenu; |
---|
27 | import flash.ui.ContextMenuItem; |
---|
28 | |
---|
29 | import mx.collections.ArrayCollection; |
---|
30 | import mx.controls.Text; |
---|
31 | import mx.core.UIComponent; |
---|
32 | |
---|
33 | private var defaultColor:Object; |
---|
34 | private var currentSelectedItem:ItemDescription; |
---|
35 | |
---|
36 | [Bindable] |
---|
37 | private var menu:BrowseContextMenu; |
---|
38 | |
---|
39 | private var _itemToScrollTo:ItemDescription; |
---|
40 | |
---|
41 | public var typeOfDescription:String; |
---|
42 | |
---|
43 | [Bindable] |
---|
44 | public var viewStack:RegistryViewStack; |
---|
45 | |
---|
46 | [Bindable] |
---|
47 | public var buttonsEnabled:Boolean = true; |
---|
48 | |
---|
49 | [Bindable] |
---|
50 | public var spaceSwitchEnabled:Boolean = false; |
---|
51 | |
---|
52 | public function set browserDataProvider(dataProvider:ArrayCollection):void { |
---|
53 | if (dataProvider) { |
---|
54 | var data:ArrayCollection = new ArrayCollection(dataProvider.toArray().slice()); |
---|
55 | this.dataGrid.dataProvider = data |
---|
56 | dataGrid.doFiltering(); |
---|
57 | scrollToSelected(); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | private function dispatchBrowserSelectionEvent():void { |
---|
62 | if (this.dataGrid.selectedItem != null) { |
---|
63 | var item:ItemDescription = dataGrid.selectedItem as ItemDescription |
---|
64 | if (currentSelectedItem == null || currentSelectedItem.id != item.id) { //Only update when the item selected is different. |
---|
65 | currentSelectedItem = item; |
---|
66 | var event:BrowserSelectionEvent = new BrowserSelectionEvent(item); |
---|
67 | dispatchEvent(event); |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | public function set itemToScrollTo(itemToScrollTo:ItemDescription):void { |
---|
73 | _itemToScrollTo = itemToScrollTo; |
---|
74 | scrollToSelected(); |
---|
75 | } |
---|
76 | |
---|
77 | private function scrollToSelected():void { |
---|
78 | if (_itemToScrollTo && dataGrid.dataProvider) { |
---|
79 | for (var i:int; i < dataGrid.dataProvider.length; i++) { |
---|
80 | var item:ItemDescription = dataGrid.dataProvider.getItemAt(i) as ItemDescription; |
---|
81 | if (item.id == _itemToScrollTo.id) { |
---|
82 | dataGrid.selectedItem = item; |
---|
83 | dispatchBrowserSelectionEvent(); |
---|
84 | dataGrid.setFocus(); |
---|
85 | dataGrid.scrollToIndex(i); |
---|
86 | break; |
---|
87 | } |
---|
88 | } |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | public function set browseMenu(browseMenu:BrowseContextMenu):void { |
---|
93 | this.menu = browseMenu; |
---|
94 | menu.dataGrid = dataGrid; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | |
---|
100 | private function handleKeyUp(event:KeyboardEvent):void { |
---|
101 | if (event.keyCode == Keyboard.DELETE) { |
---|
102 | menu.deleteSelectedItems(); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | private function editItem():void { |
---|
107 | var item:ItemDescription = dataGrid.selectedItem as ItemDescription; |
---|
108 | viewStack.switchToEditor(item); |
---|
109 | } |
---|
110 | |
---|
111 | private function importItem():void{ |
---|
112 | viewStack.switchToImport(); |
---|
113 | } |
---|
114 | |
---|
115 | private function dispatchCreateNewEvent():void{ |
---|
116 | dispatchEvent(new CreateNewComponentEvent()); |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | private function goToFeed():void{ |
---|
121 | var request:URLRequest = new URLRequest(Config.getRssUriDescriptions(typeOfDescription)); |
---|
122 | navigateToURL(request, "_blank"); |
---|
123 | } |
---|
124 | ]]> |
---|
125 | </mx:Script> |
---|
126 | |
---|
127 | <mx:HBox paddingLeft="5" |
---|
128 | paddingRight="5" |
---|
129 | width="100%"> |
---|
130 | |
---|
131 | <mx:Box paddingTop="5" paddingLeft="5" |
---|
132 | visible="{spaceSwitchEnabled}" |
---|
133 | includeInLayout="{spaceSwitchEnabled}"> |
---|
134 | <comp:SpaceSwitch id="userSpaceCB" /> |
---|
135 | </mx:Box> |
---|
136 | |
---|
137 | <mx:HBox horizontalAlign="left" |
---|
138 | verticalAlign="middle" |
---|
139 | width="70%" |
---|
140 | visible="{buttonsEnabled}"> |
---|
141 | |
---|
142 | |
---|
143 | <mx:Button label="Create new" |
---|
144 | toolTip="Create a new item in the private workspace" |
---|
145 | click="dispatchCreateNewEvent()" |
---|
146 | /> |
---|
147 | <mx:Button label="Edit" |
---|
148 | toolTip="Edit the selected item in the editor" |
---|
149 | visible="{Config.instance.userSpace}" |
---|
150 | includeInLayout="{Config.instance.userSpace}" |
---|
151 | enabled="{Config.instance.userSpace && dataGrid.selectedItem != null}" |
---|
152 | click="editItem()" /> |
---|
153 | <mx:Button label="Edit as new" |
---|
154 | toolTip="Edit the selected item as a new item in the private workspace" |
---|
155 | visible="{!Config.instance.userSpace}" |
---|
156 | includeInLayout="{!Config.instance.userSpace}" |
---|
157 | enabled="{!Config.instance.userSpace && dataGrid.selectedItem != null}" |
---|
158 | click="editItem()" /> |
---|
159 | <mx:Button label="Import" |
---|
160 | toolTip="Import an item from a local file" |
---|
161 | click="importItem()" /> |
---|
162 | |
---|
163 | </mx:HBox> |
---|
164 | |
---|
165 | <mx:HBox horizontalAlign="right" |
---|
166 | verticalAlign="middle" |
---|
167 | width="30%"> |
---|
168 | |
---|
169 | <rictus:SearchBox id="searchBox" |
---|
170 | label="filter..."/> |
---|
171 | <mx:Label text="Showing {dataGrid.dataProvider.length} of {dataGrid.unfilteredLength}"/> |
---|
172 | |
---|
173 | |
---|
174 | <comp:RssLinkButton |
---|
175 | contextMenu = "{(new RssDescriptionsContextMenu(typeOfDescription)).cm}" |
---|
176 | click="goToFeed()" |
---|
177 | /> |
---|
178 | </mx:HBox> |
---|
179 | </mx:HBox> |
---|
180 | |
---|
181 | <comp:FilteringDataGrid id="dataGrid" |
---|
182 | x="0" |
---|
183 | y="112" |
---|
184 | width="100%" |
---|
185 | height="100%" |
---|
186 | click="dispatchBrowserSelectionEvent()" |
---|
187 | columns="{browserColumns}" |
---|
188 | contextMenu="{menu.cm}" |
---|
189 | allowMultipleSelection="true" |
---|
190 | searchInput="{searchBox}" |
---|
191 | keyUp="handleKeyUp(event)" |
---|
192 | useRollOver="false" |
---|
193 | showDataTips="true"> |
---|
194 | </comp:FilteringDataGrid> |
---|
195 | </mx:VBox> |
---|