diff options
Diffstat (limited to 'js/io/document/document-controller.js')
-rwxr-xr-x | js/io/document/document-controller.js | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 15f026a3..c2a2dab6 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js | |||
@@ -87,8 +87,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
87 | handleExecuteFileOpen: { | 87 | handleExecuteFileOpen: { |
88 | value: function(event) { | 88 | value: function(event) { |
89 | var pickerSettings = event._event.settings || {}; | 89 | var pickerSettings = event._event.settings || {}; |
90 | pickerSettings.callback = this.openFileWithURI; | 90 | pickerSettings.callback = this.openFileWithURI.bind(this); |
91 | pickerSettings.callbackScope = this; | 91 | pickerSettings.pickerMode = "read"; |
92 | pickerSettings.inFileMode = true; | ||
92 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | 93 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); |
93 | } | 94 | } |
94 | }, | 95 | }, |
@@ -96,8 +97,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
96 | handleExecuteNewFile: { | 97 | handleExecuteNewFile: { |
97 | value: function(event) { | 98 | value: function(event) { |
98 | var newFileSettings = event._event.settings || {}; | 99 | var newFileSettings = event._event.settings || {}; |
99 | newFileSettings.callback = this.createNewFile; | 100 | newFileSettings.callback = this.createNewFile.bind(this); |
100 | newFileSettings.callbackScope = this; | ||
101 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | 101 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); |
102 | } | 102 | } |
103 | }, | 103 | }, |
@@ -132,9 +132,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
132 | */ | 132 | */ |
133 | openNewFileCallback:{ | 133 | openNewFileCallback:{ |
134 | value:function(doc){ | 134 | value:function(doc){ |
135 | var response = doc || {"uri":"/Users/xhdq84/Documents/test.js", "success":true};//default just for testing | 135 | var response = doc || null;//default just for testing |
136 | if(!!response && response.success && !!response.uri){ | 136 | if(!!response && response.success && !!response.uri){ |
137 | this.application.ninja.ioMediator.fileOpen({"uri":response.uri}, this.openFileCallback.bind(this)); | 137 | this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | }, | 140 | }, |
@@ -146,25 +146,56 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
146 | uri = uriArrayObj.uri[0]; | 146 | uri = uriArrayObj.uri[0]; |
147 | } | 147 | } |
148 | //console.log("URI is: ", uri); | 148 | //console.log("URI is: ", uri); |
149 | 149 | if(!!uri){ | |
150 | this.application.ninja.ioMediator.fileOpen({"uri":uri}, this.openFileCallback.bind(this)); | 150 | this.application.ninja.ioMediator.fileOpen(uri, this.openFileCallback.bind(this)); |
151 | } | ||
151 | } | 152 | } |
152 | }, | 153 | }, |
153 | 154 | ||
154 | /** | 155 | /** |
155 | * Public method | 156 | * Public method |
156 | * doc contains: | ||
157 | * type : file type, like js, css, etc | ||
158 | * name : file name | ||
159 | * source : file content | ||
160 | * uri : file uri | ||
161 | */ | 157 | */ |
162 | openFileCallback:{ | 158 | openFileCallback:{ |
163 | value:function(doc){ | 159 | value:function(response){ |
164 | this.openDocument(doc); | 160 | //Return Object Description |
161 | // Object.status (Always presents for handling) | ||
162 | // 204: File exists (Success) | ||
163 | // 404: File does not exists (Failure) | ||
164 | // 500: Unknown (Probably cloud API not running) | ||
165 | // | ||
166 | // (Below only present if succesfull 204) | ||
167 | // | ||
168 | // Object.content | ||
169 | // Object.extension | ||
170 | // Object.name | ||
171 | // Object.uri | ||
172 | // Object.creationDate | ||
173 | // Object.modifiedDate | ||
174 | // Object.readOnly | ||
175 | // Object.size | ||
176 | |||
177 | var fileDetails = {}; | ||
178 | if(!!response && (response.status === 204)){ | ||
179 | /** | ||
180 | * fileDetails format: | ||
181 | * {"type": "js", "name": "test", "source": fileContent, "uri": uri} | ||
182 | */ | ||
183 | fileDetails.type = response.extension; | ||
184 | fileDetails.source = response.content; | ||
185 | fileDetails.name = response.name; | ||
186 | fileDetails.uri = response.uri; | ||
187 | |||
188 | this.openDocument(fileDetails); | ||
189 | }else if(!!response && (response.status === 404)){ | ||
190 | alert("Unable to open file.\n [Error: File does not exist]"); | ||
191 | }else if(!!response && (response.status === 500)){ | ||
192 | alert("Unable to open file.\n Check if Ninja Local Cloud is running."); | ||
193 | }else{ | ||
194 | alert("Unable to open file."); | ||
165 | } | 195 | } |
166 | }, | ||
167 | 196 | ||
197 | } | ||
198 | }, | ||
168 | 199 | ||
169 | openProjectWithURI: { | 200 | openProjectWithURI: { |
170 | value: function(uri) { | 201 | value: function(uri) { |
@@ -371,7 +402,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
371 | this.application.ninja.stage.restoreScroll(); | 402 | this.application.ninja.stage.restoreScroll(); |
372 | this.application.ninja.stage.hideCanvas(false); | 403 | this.application.ninja.stage.hideCanvas(false); |
373 | this.application.ninja.stage.stageView.showRulers(); | 404 | this.application.ninja.stage.stageView.showRulers(); |
374 | } | 405 | }else{ |
406 | //hide the iframe when switching to code view | ||
407 | document.getElementById("iframeContainer").style.display="none"; | ||
408 | } | ||
375 | } | 409 | } |
376 | } | 410 | } |
377 | }, | 411 | }, |