diff options
Diffstat (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js')
-rw-r--r-- | js/io/ui/save-as-dialog.reel/save-as-dialog.js | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.js b/js/io/ui/save-as-dialog.reel/save-as-dialog.js new file mode 100644 index 00000000..de5266a5 --- /dev/null +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.js | |||
@@ -0,0 +1,196 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component; | ||
9 | //nj= ("js/lib/NJUtils.js").NJUtils; | ||
10 | |||
11 | var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { | ||
12 | |||
13 | hasReel: { | ||
14 | value: true | ||
15 | }, | ||
16 | |||
17 | fileName : { | ||
18 | enumerable: true, | ||
19 | writable: true, | ||
20 | value: "" | ||
21 | }, | ||
22 | |||
23 | folderUri:{ | ||
24 | enumerable: true, | ||
25 | writable: true, | ||
26 | value: "" | ||
27 | }, | ||
28 | |||
29 | callback : { | ||
30 | enumerable: true, | ||
31 | writable: true, | ||
32 | value: null | ||
33 | }, | ||
34 | |||
35 | callbackScope : { | ||
36 | enumerable: true, | ||
37 | writable: true, | ||
38 | value: null | ||
39 | }, | ||
40 | |||
41 | willDraw: { | ||
42 | enumerable: false, | ||
43 | value: function() {} | ||
44 | }, | ||
45 | draw: { | ||
46 | enumerable: false, | ||
47 | value: function() {} | ||
48 | }, | ||
49 | didDraw: { | ||
50 | enumerable: false, | ||
51 | value: function() { | ||
52 | var self = this; | ||
53 | this.fileInputField.selectDirectory = true; | ||
54 | this.fileInputField.pickerName = "saveAsDirectoryPicker"; | ||
55 | this.newFileName.value = this.fileName; | ||
56 | this.fileInputField.newFileDirectory.value = this.folderUri; | ||
57 | |||
58 | this.newFileName.addEventListener("blur", function(evt){self.handleNewFileNameOnblur(evt);}, false); | ||
59 | this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false); | ||
60 | |||
61 | this.enableOk(); | ||
62 | } | ||
63 | }, | ||
64 | |||
65 | handleNewFileDirectorySet:{ | ||
66 | value:function(evt){ | ||
67 | if(!!evt._event.newFileDirectory){ | ||
68 | this.folderUri = evt._event.newFileDirectory; | ||
69 | if(this.folderUri !== ""){ | ||
70 | this.enableOk(); | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | }, | ||
75 | |||
76 | handleNewFileNameOnblur:{ | ||
77 | value:function(evt){ | ||
78 | this.fileName = this.newFileName.value; | ||
79 | if(this.fileName !== ""){ | ||
80 | if(this.fileName !== ""){ | ||
81 | this.enableOk(); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | }, | ||
86 | |||
87 | |||
88 | enableOk:{ | ||
89 | value: function(){ | ||
90 | if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){ | ||
91 | this.okButton.removeAttribute("disabled"); | ||
92 | this.error.innerHTML=""; | ||
93 | } | ||
94 | } | ||
95 | }, | ||
96 | |||
97 | handleCancelButtonAction :{ | ||
98 | value:function(evt){ | ||
99 | //clean up memory | ||
100 | //this.cleanup(); | ||
101 | |||
102 | if(this.popup){ | ||
103 | this.popup.hide(); | ||
104 | } | ||
105 | |||
106 | } | ||
107 | }, | ||
108 | |||
109 | handleOkButtonAction:{ | ||
110 | value: function(evt){ | ||
111 | var filename = this.fileName, | ||
112 | newFileDirectory = this.newFileDirectory, | ||
113 | success = true; | ||
114 | if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){ | ||
115 | try{ | ||
116 | //validate file name and folder path | ||
117 | //check if file already exists | ||
118 | if(!!this.callback && !!this.callbackScope){//inform document-controller if save successful | ||
119 | this.callback.call(this.callbackScope, {"filename":filename, "destination": newFileDirectory});//document-controller api | ||
120 | }else{ | ||
121 | //send save as event | ||
122 | var saveAsEvent = document.createEvent("Events"); | ||
123 | saveAsEvent.initEvent("saveAsFile", false, false); | ||
124 | saveAsEvent.saveAsOptions = {"filename":filename, "destination": newFileDirectory}; | ||
125 | this.eventManager.dispatchEvent(saveAsEvent); | ||
126 | } | ||
127 | }catch(e){ | ||
128 | success = false; | ||
129 | console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ this.newFileDirectory); | ||
130 | console.log(e.stack); | ||
131 | } | ||
132 | |||
133 | if(success){ | ||
134 | //clean up memory | ||
135 | //this.cleanup(); | ||
136 | |||
137 | if(this.popup){ | ||
138 | this.popup.hide(); | ||
139 | } | ||
140 | } | ||
141 | }else{ | ||
142 | if(this.error.innerHTML !== ""){ | ||
143 | this.showError("! Name and Location should be valid."); | ||
144 | } | ||
145 | //disable ok | ||
146 | if(!this.okButton.hasAttribute("disabled")){ | ||
147 | this.okButton.setAttribute("disabled", "true"); | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | }, | ||
152 | |||
153 | isValidUri:{ | ||
154 | value: function(uri){ | ||
155 | var status= this.application.ninja.coreIoApi.isValidUri(uri); | ||
156 | if(uri !== ""){ | ||
157 | if(!status){ | ||
158 | this.showError("! Invalid directory."); | ||
159 | } | ||
160 | } | ||
161 | return status; | ||
162 | } | ||
163 | }, | ||
164 | isValidFileName:{ | ||
165 | value: function(fileName){ | ||
166 | var status = nj.isValidFileName(fileName); | ||
167 | if(fileName !== ""){ | ||
168 | if(!status){ | ||
169 | this.showError("! Invalid file name."); | ||
170 | } | ||
171 | } | ||
172 | return status; | ||
173 | } | ||
174 | }, | ||
175 | checkFileExists:{ | ||
176 | value: function(fileUri, folderUri, fileType){ | ||
177 | var status= this.application.ninja.coreIoApi.checkFileExists(fileUri, folderUri, fileType); | ||
178 | if(status){ | ||
179 | this.showError("! File already exists."); | ||
180 | } | ||
181 | return status; | ||
182 | } | ||
183 | }, | ||
184 | |||
185 | showError:{ | ||
186 | value:function(errorString){ | ||
187 | this.error.innerHTML = ""; | ||
188 | this.error.innerHTML=errorString; | ||
189 | //disable ok | ||
190 | if(!this.okButton.hasAttribute("disabled")){ | ||
191 | this.okButton.setAttribute("disabled", "true"); | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | |||
196 | }); \ No newline at end of file | ||