1 | <?xml version="1.0" encoding="utf-8"?> |
---|
2 | <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" |
---|
3 | xmlns:local="clarin.cmdi.componentregistry.services.*" |
---|
4 | width="100%" |
---|
5 | height="100%" |
---|
6 | label="Import..." |
---|
7 | implements="clarin.cmdi.componentregistry.common.components.RegistryView"> |
---|
8 | |
---|
9 | <mx:Script> |
---|
10 | <![CDATA[ |
---|
11 | import clarin.cmdi.componentregistry.services.Config; |
---|
12 | import mx.events.ValidationResultEvent; |
---|
13 | import mx.collections.ArrayCollection; |
---|
14 | import mx.validators.Validator; |
---|
15 | import clarin.cmdi.componentregistry.editor.InputValidators; |
---|
16 | import clarin.cmdi.componentregistry.common.LabelConstants; |
---|
17 | import clarin.cmdi.componentregistry.common.Credentials; |
---|
18 | import mx.core.Application; |
---|
19 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
20 | |
---|
21 | private static const BTN_PROFILE_LABEL:String = "Select profile xml..."; |
---|
22 | private static const BTN_COMPONENT_LABEL:String = "Select component xml..."; |
---|
23 | |
---|
24 | private var validators:ArrayCollection = new ArrayCollection(); |
---|
25 | |
---|
26 | [Bindable] |
---|
27 | private var isProfile:Boolean = true; |
---|
28 | [Bindable] |
---|
29 | private var btnLabel:String = BTN_PROFILE_LABEL; |
---|
30 | |
---|
31 | private function submit(event:Event):void { |
---|
32 | if (validate()) { |
---|
33 | var item:ItemDescription = new ItemDescription(); |
---|
34 | item.description = description.text; |
---|
35 | item.name = nameInput.text; |
---|
36 | item.groupName = groupName.text; |
---|
37 | if (domainName.selectedIndex != -1) |
---|
38 | item.domainName = domainName.selectedItem.data; |
---|
39 | item.isProfile = isProfile; |
---|
40 | item.isInUserSpace = true; //We only allow import into workspace it can be published from there. |
---|
41 | uploadSrv.upload(UploadService.NEW, item); |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | private function validate():Boolean { |
---|
46 | var result:Boolean = true; |
---|
47 | for (var i:int; i < validators.length; i++) { |
---|
48 | var val:Validator = validators.getItemAt(i) as Validator; |
---|
49 | if (val.listener.visible) { |
---|
50 | var event:ValidationResultEvent = val.validate(); |
---|
51 | if (event.type != ValidationResultEvent.VALID) { |
---|
52 | result = false; |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | return result; |
---|
57 | } |
---|
58 | |
---|
59 | private function setIsProfile(isProfileValue:Boolean):void { |
---|
60 | isProfile = isProfileValue; |
---|
61 | if (isProfile) { |
---|
62 | btnLabel = BTN_PROFILE_LABEL; |
---|
63 | } else { |
---|
64 | btnLabel = BTN_COMPONENT_LABEL; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | private function registryChange(event:UploadCompleteEvent):void { |
---|
69 | parentApplication.viewStack.switchToBrowse(event.itemDescription); |
---|
70 | } |
---|
71 | |
---|
72 | private function registerNameValidator(event:Event):void { |
---|
73 | var validator:Validator = InputValidators.getNameValidator(); |
---|
74 | validator.listener = event.currentTarget; |
---|
75 | validator.source = event.currentTarget; |
---|
76 | validator.property = "text"; |
---|
77 | validators.addItem(validator); |
---|
78 | } |
---|
79 | |
---|
80 | private function registerIsRequiredValidator(event:Event, source:Object = null):void { |
---|
81 | var validator:Validator = InputValidators.getIsRequiredValidator(); |
---|
82 | validator.listener = event.currentTarget; |
---|
83 | if (!source) { |
---|
84 | validator.source = event.currentTarget; |
---|
85 | } else { |
---|
86 | validator.source = source; |
---|
87 | } |
---|
88 | validator.property = "text"; |
---|
89 | validators.addItem(validator); |
---|
90 | } |
---|
91 | |
---|
92 | public function getType():String { |
---|
93 | return Config.VIEW_IMPORT; |
---|
94 | } |
---|
95 | ]]> |
---|
96 | </mx:Script> |
---|
97 | |
---|
98 | <local:UploadService id="uploadSrv" |
---|
99 | uploadComplete="registryChange(event)"/> |
---|
100 | <mx:VBox> |
---|
101 | <mx:Form> |
---|
102 | <mx:HBox> |
---|
103 | <mx:FormHeading label="Import"/> |
---|
104 | <mx:RadioButton groupName="importType" |
---|
105 | id="profileType" |
---|
106 | label="Profile" |
---|
107 | click="setIsProfile(true)" |
---|
108 | selected="true"/> |
---|
109 | <mx:RadioButton groupName="importType" |
---|
110 | id="componentType" |
---|
111 | label="Component" |
---|
112 | click="setIsProfile(false)"/> |
---|
113 | </mx:HBox> |
---|
114 | <mx:HBox> |
---|
115 | <mx:Button label="{btnLabel}" |
---|
116 | id="btnSelect" |
---|
117 | click="uploadSrv.selectXmlFile(event)" |
---|
118 | creationComplete="registerIsRequiredValidator(event, txtSelectedFile)"/> |
---|
119 | <mx:Text id="txtSelectedFile" |
---|
120 | text="{uploadSrv.selectedFile}"/> |
---|
121 | </mx:HBox> |
---|
122 | |
---|
123 | <mx:FormItem label="Name"> |
---|
124 | <mx:TextInput id="nameInput" |
---|
125 | creationComplete="registerNameValidator(event)"/> |
---|
126 | </mx:FormItem> |
---|
127 | <mx:FormItem label="Description"> |
---|
128 | <mx:TextArea id="description" |
---|
129 | creationComplete="registerIsRequiredValidator(event)"/> |
---|
130 | </mx:FormItem> |
---|
131 | <mx:FormItem label="Creator Name"> |
---|
132 | <mx:Text id="creatorName" |
---|
133 | text="{Credentials.instance.userName}"/> |
---|
134 | </mx:FormItem> |
---|
135 | <mx:FormItem label="Domain Name"> |
---|
136 | <mx:ComboBox id="domainName" |
---|
137 | selectedIndex="-1" |
---|
138 | prompt="{LabelConstants.DOMAIN_NAME_PROMPT}" |
---|
139 | dataProvider="{LabelConstants.DOMAIN_NAME_DATA}"/> |
---|
140 | </mx:FormItem> |
---|
141 | <mx:FormItem label="Group Name"> |
---|
142 | <mx:TextInput id="groupName" |
---|
143 | creationComplete="registerIsRequiredValidator(event)"/> |
---|
144 | </mx:FormItem> |
---|
145 | <mx:Button label="Submit" |
---|
146 | click="submit(event)"/> |
---|
147 | <mx:ProgressBar id="uploadProgress" |
---|
148 | label="" |
---|
149 | mode="manual" |
---|
150 | creationComplete="uploadSrv.init(uploadProgress)" |
---|
151 | visible="false"/> |
---|
152 | </mx:Form> |
---|
153 | |
---|
154 | <mx:Text id="errorMessageField" |
---|
155 | text="{uploadSrv.message}"/> |
---|
156 | |
---|
157 | </mx:VBox> |
---|
158 | |
---|
159 | </mx:Canvas> |
---|
160 | |
---|