1 | // ActionScript file |
---|
2 | import clarin.cmdi.componentregistry.browser.BrowserColumns; |
---|
3 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
4 | import clarin.cmdi.componentregistry.editor.model.CMDAttribute; |
---|
5 | import clarin.cmdi.componentregistry.editor.model.CMDComponent; |
---|
6 | import clarin.cmdi.componentregistry.editor.model.CMDComponentElement; |
---|
7 | import clarin.cmdi.componentregistry.editor.model.CMDModelFactory; |
---|
8 | import clarin.cmdi.componentregistry.editor.model.CMDSpec; |
---|
9 | import clarin.cmdi.componentregistry.importer.UploadCompleteEvent; |
---|
10 | import clarin.cmdi.componentregistry.services.ComponentInfoService; |
---|
11 | import clarin.cmdi.componentregistry.services.ComponentListService; |
---|
12 | import clarin.cmdi.componentregistry.services.ProfileInfoService; |
---|
13 | import clarin.cmdi.componentregistry.services.UploadService; |
---|
14 | |
---|
15 | import flash.events.Event; |
---|
16 | import flash.net.FileReference; |
---|
17 | |
---|
18 | import mx.controls.Alert; |
---|
19 | import mx.core.DragSource; |
---|
20 | import mx.core.UIComponent; |
---|
21 | import mx.managers.DragManager; |
---|
22 | |
---|
23 | |
---|
24 | private var currentDescription:ItemDescription; |
---|
25 | private var profileSrv:ProfileInfoService = new ProfileInfoService(); |
---|
26 | private var componentSrv:ComponentInfoService = new ComponentInfoService(); |
---|
27 | |
---|
28 | [Bindable] |
---|
29 | private var componentsSrv:ComponentListService = new ComponentListService(); //Don't create an instance we need a new one |
---|
30 | |
---|
31 | [Bindable] |
---|
32 | public var cmdComponent:XML; |
---|
33 | |
---|
34 | [Bindable] |
---|
35 | private var cmdSpec:CMDSpec = new CMDSpec(true); |
---|
36 | |
---|
37 | [Bindable] |
---|
38 | private var browserColumns:BrowserColumns = new BrowserColumns(); |
---|
39 | |
---|
40 | [Bindable] |
---|
41 | private var uploadService:UploadService = new UploadService(); |
---|
42 | |
---|
43 | |
---|
44 | public function init():void { |
---|
45 | profileSrv.addEventListener(ProfileInfoService.PROFILE_LOADED, profileLoaded); |
---|
46 | componentsSrv.load(); |
---|
47 | uploadService.init(uploadProgress); |
---|
48 | } |
---|
49 | |
---|
50 | private function profileLoaded(event:Event):void { |
---|
51 | var cmdComponent:XML = profileSrv.profile.profileSource; |
---|
52 | this.cmdSpec = CMDModelFactory.createModel(cmdComponent); |
---|
53 | } |
---|
54 | |
---|
55 | public function setDescription(itemDescription:ItemDescription):void { |
---|
56 | this.currentDescription = itemDescription; |
---|
57 | if (currentDescription.isProfile) { |
---|
58 | profileSrv.load(currentDescription); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | public function clearEditor():void { |
---|
63 | this.cmdSpec = new CMDSpec(true); |
---|
64 | } |
---|
65 | |
---|
66 | private var ref:FileReference = new FileReference(); |
---|
67 | |
---|
68 | private function saveSpec():void { |
---|
69 | // Alert.show(xmlEditor.cmdSpec.toXml()); |
---|
70 | var item:ItemDescription = new ItemDescription(); |
---|
71 | item.description = xmlEditor.cmdSpec.headerDescription; |
---|
72 | item.name = xmlEditor.cmdSpec.headerName; |
---|
73 | item.isProfile = xmlEditor.cmdSpec.isProfile; |
---|
74 | item.groupName = xmlEditor.cmdSpec.groupName; |
---|
75 | uploadService.addEventListener(UploadCompleteEvent.UPLOAD_COMPLETE, handleSaveComplete); |
---|
76 | if (item.isProfile) { |
---|
77 | uploadService.submitProfile(item, xmlEditor.cmdSpec.toXml()); |
---|
78 | } else { |
---|
79 | uploadService.submitComponent(item, xmlEditor.cmdSpec.toXml()); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | private function handleSaveComplete(event:UploadCompleteEvent):void { |
---|
84 | parentApplication.viewStack.switchToBrowse(event.itemDescription); |
---|
85 | } |
---|
86 | |
---|
87 | private function handleEditorChange(event:Event):void { |
---|
88 | errorMessageField.text = ""; |
---|
89 | uploadProgress.visible = false; |
---|
90 | uploadProgress.includeInLayout = false; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | private function enableComponentDrag(event:MouseEvent):void { |
---|
95 | var ds:DragSource = new DragSource(); |
---|
96 | ds.addHandler(function():CMDComponent { |
---|
97 | return new CMDComponent(); |
---|
98 | }, CMDComponentXMLEditor.DRAG_NEW_COMPONENT); |
---|
99 | DragManager.doDrag(UIComponent(event.currentTarget), ds, event); |
---|
100 | } |
---|
101 | |
---|
102 | private function enableElementDrag(event:MouseEvent):void { |
---|
103 | var ds:DragSource = new DragSource(); |
---|
104 | ds.addHandler(function():CMDComponentElement { |
---|
105 | return new CMDComponentElement(); |
---|
106 | }, CMDComponentXMLEditor.DRAG_NEW_ELEMENT); |
---|
107 | DragManager.doDrag(UIComponent(event.currentTarget), ds, event); |
---|
108 | } |
---|
109 | |
---|
110 | private function enableAttributeDrag(event:MouseEvent):void { |
---|
111 | var ds:DragSource = new DragSource(); |
---|
112 | ds.addHandler(function():CMDAttribute { |
---|
113 | return new CMDAttribute(); |
---|
114 | }, CMDComponentXMLEditor.DRAG_NEW_ATTRIBUTE); |
---|
115 | DragManager.doDrag(UIComponent(event.currentTarget), ds, event); |
---|
116 | } |
---|
117 | |
---|
118 | private function initPaletteOverview():void { |
---|
119 | componentsPaletteOverview.dataGrid.dragEnabled = true; |
---|
120 | componentsPaletteOverview.dataGrid.allowMultipleSelection = true; |
---|
121 | componentsPaletteOverview.dataGrid.horizontalScrollPolicy = "auto"; |
---|
122 | componentsPaletteOverview.dataGrid.resizableColumns = true; |
---|
123 | } |
---|
124 | |
---|