diff options
author | Eric Guzman | 2012-02-29 16:13:19 -0800 |
---|---|---|
committer | Eric Guzman | 2012-02-29 16:13:19 -0800 |
commit | 53bdb1e7773069c4cca59e88d6da91cd0f58c94a (patch) | |
tree | 44a2147fcbb43ea483f78a1e2e082919f9c81970 /js/controllers/document-controller.js | |
parent | b2c60efb9c6f5dfa7b0fc5c2b9feebebc805ed97 (diff) | |
parent | b09956e4a9a35c5588cc7cd1f01efb617cbe0884 (diff) | |
download | ninja-53bdb1e7773069c4cca59e88d6da91cd0f58c94a.tar.gz |
Merge branch 'refs/heads/master' into CSSPanelUpdates
Conflicts:
js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-x | js/controllers/document-controller.js | 76 |
1 files changed, 58 insertions, 18 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 1c9d9d59..64ff2c7e 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -58,6 +58,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
58 | this.eventManager.addEventListener("executeFileOpen", this, false); | 58 | this.eventManager.addEventListener("executeFileOpen", this, false); |
59 | this.eventManager.addEventListener("executeNewFile", this, false); | 59 | this.eventManager.addEventListener("executeNewFile", this, false); |
60 | this.eventManager.addEventListener("executeSave", this, false); | 60 | this.eventManager.addEventListener("executeSave", this, false); |
61 | this.eventManager.addEventListener("executeSaveAs", this, false); | ||
62 | this.eventManager.addEventListener("executeSaveAll", this, false); | ||
61 | 63 | ||
62 | this.eventManager.addEventListener("recordStyleChanged", this, false); | 64 | this.eventManager.addEventListener("recordStyleChanged", this, false); |
63 | 65 | ||
@@ -87,11 +89,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
87 | //Checking for app to be loaded through extension | 89 | //Checking for app to be loaded through extension |
88 | var check; | 90 | var check; |
89 | if (chrome && chrome.app) { | 91 | if (chrome && chrome.app) { |
90 | check = chrome.app.getDetails(); | 92 | check = chrome.app.getDetails(); |
91 | } | 93 | } |
92 | if (check !== null) { | 94 | if (check !== null) { |
93 | //Adding an intercept to resources loaded to ensure user assets load from cloud simulator | 95 | //Adding an intercept to resources loaded to ensure user assets load from cloud simulator |
94 | chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]); | 96 | chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]); |
95 | } | 97 | } |
96 | } | 98 | } |
97 | }, | 99 | }, |
@@ -107,33 +109,57 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
107 | handleExecuteFileOpen: { | 109 | handleExecuteFileOpen: { |
108 | value: function(event) { | 110 | value: function(event) { |
109 | var pickerSettings = event._event.settings || {}; | 111 | var pickerSettings = event._event.settings || {}; |
110 | pickerSettings.callback = this.openFileWithURI.bind(this); | 112 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
111 | pickerSettings.pickerMode = "read"; | 113 | pickerSettings.callback = this.openFileWithURI.bind(this); |
112 | pickerSettings.inFileMode = true; | 114 | pickerSettings.pickerMode = "read"; |
113 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | 115 | pickerSettings.inFileMode = true; |
116 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | ||
117 | } | ||
114 | } | 118 | } |
115 | }, | 119 | }, |
116 | 120 | ||
117 | handleExecuteNewFile: { | 121 | handleExecuteNewFile: { |
118 | value: function(event) { | 122 | value: function(event) { |
119 | var newFileSettings = event._event.settings || {}; | 123 | var newFileSettings = event._event.settings || {}; |
120 | newFileSettings.callback = this.createNewFile.bind(this); | 124 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
121 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | 125 | newFileSettings.callback = this.createNewFile.bind(this); |
126 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | ||
127 | } | ||
122 | } | 128 | } |
123 | }, | 129 | }, |
124 | |||
125 | |||
126 | //////////////////////////////////////////////////////////////////// | 130 | //////////////////////////////////////////////////////////////////// |
127 | //TODO: Check for appropiate structures | 131 | //TODO: Check for appropiate structures |
128 | handleExecuteSave: { | 132 | handleExecuteSave: { |
129 | value: function(event) { | 133 | value: function(event) { |
130 | if(!!this.activeDocument){ | 134 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
131 | //Text and HTML document classes should return the same save object for fileSave | 135 | //Text and HTML document classes should return the same save object for fileSave |
132 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | 136 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); |
137 | } | ||
133 | } | 138 | } |
139 | }, | ||
140 | //////////////////////////////////////////////////////////////////// | ||
141 | //TODO: Check for appropiate structures | ||
142 | handleExecuteSaveAll: { | ||
143 | value: function(event) { | ||
144 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | ||
145 | //Text and HTML document classes should return the same save object for fileSave | ||
146 | this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); | ||
147 | } | ||
134 | } | 148 | } |
135 | }, | 149 | }, |
136 | //////////////////////////////////////////////////////////////////// | 150 | //////////////////////////////////////////////////////////////////// |
151 | handleExecuteSaveAs: { | ||
152 | value: function(event) { | ||
153 | var saveAsSettings = event._event.settings || {}; | ||
154 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | ||
155 | saveAsSettings.fileName = this.activeDocument.name; | ||
156 | saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); | ||
157 | //add callback | ||
158 | this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); | ||
159 | } | ||
160 | } | ||
161 | }, | ||
162 | |||
137 | // | 163 | // |
138 | fileSaveResult: { | 164 | fileSaveResult: { |
139 | value: function (result) { | 165 | value: function (result) { |
@@ -169,6 +195,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
169 | value:function(doc){ | 195 | value:function(doc){ |
170 | var response = doc || null;//default just for testing | 196 | var response = doc || null;//default just for testing |
171 | if(!!response && response.success && (response.status!== 500) && !!response.uri){ | 197 | if(!!response && response.success && (response.status!== 500) && !!response.uri){ |
198 | |||
199 | this.isNewFilePath = true;//path identifier flag | ||
200 | this.creatingNewFile = true;//flag for timeline to identify new file flow | ||
201 | |||
172 | this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); | 202 | this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); |
173 | }else if(!!response && !response.success){ | 203 | }else if(!!response && !response.success){ |
174 | //Todo: restrict directory path to the sandbox, in the dialog itself | 204 | //Todo: restrict directory path to the sandbox, in the dialog itself |
@@ -196,6 +226,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
196 | value:function(response){ | 226 | value:function(response){ |
197 | //TODO: Add UI to handle error codes, shouldn't be alert windows | 227 | //TODO: Add UI to handle error codes, shouldn't be alert windows |
198 | if(!!response && (response.status === 204)) { | 228 | if(!!response && (response.status === 204)) { |
229 | |||
230 | if((typeof this.isNewFilePath === 'undefined') || (this.isNewFilePath !== true)){//not from new file flow | ||
231 | this.creatingNewFile = false; | ||
232 | } | ||
233 | this.isNewFilePath = false;//reset path identifier flag | ||
234 | |||
199 | //Sending full response object | 235 | //Sending full response object |
200 | this.openDocument(response); | 236 | this.openDocument(response); |
201 | } else if (!!response && (response.status === 404)){ | 237 | } else if (!!response && (response.status === 404)){ |
@@ -292,7 +328,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
292 | if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab | 328 | if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab |
293 | var nextDocumentIndex = -1 ; | 329 | var nextDocumentIndex = -1 ; |
294 | if((this._documents.length > 0) && (closeDocumentIndex === 0)){ | 330 | if((this._documents.length > 0) && (closeDocumentIndex === 0)){ |
295 | nextDocumentIndex = 1; | 331 | nextDocumentIndex = 0; |
296 | }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ | 332 | }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ |
297 | nextDocumentIndex = closeDocumentIndex - 1; | 333 | nextDocumentIndex = closeDocumentIndex - 1; |
298 | } | 334 | } |
@@ -306,6 +342,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
306 | 342 | ||
307 | this.application.ninja.stage.hideCanvas(true); | 343 | this.application.ninja.stage.hideCanvas(true); |
308 | } | 344 | } |
345 | |||
346 | NJevent("closeDocument", doc.uri); | ||
347 | |||
348 | doc=null; | ||
309 | } | 349 | } |
310 | }, | 350 | }, |
311 | 351 | ||
@@ -313,7 +353,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
313 | // Event Detail: Contains the current ActiveDocument | 353 | // Event Detail: Contains the current ActiveDocument |
314 | _onOpenDocument: { | 354 | _onOpenDocument: { |
315 | value: function(doc){ | 355 | value: function(doc){ |
316 | //var data = DocumentManager.activeDocument; | 356 | this.application.ninja.currentDocument = doc; |
317 | this._hideCurrentDocument(); | 357 | this._hideCurrentDocument(); |
318 | this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid); | 358 | this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid); |
319 | 359 | ||
@@ -397,7 +437,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
397 | value: function() { | 437 | value: function() { |
398 | if(this.activeDocument) { | 438 | if(this.activeDocument) { |
399 | if(this.activeDocument.currentView === "design"){ | 439 | if(this.activeDocument.currentView === "design"){ |
400 | this.application.ninja.stage.saveScroll(); | 440 | this.activeDocument.saveAppState(); |
401 | this.activeDocument.container.parentNode.style["display"] = "none"; | 441 | this.activeDocument.container.parentNode.style["display"] = "none"; |
402 | this.application.ninja.stage.hideCanvas(true); | 442 | this.application.ninja.stage.hideCanvas(true); |
403 | this.application.ninja.stage.stageView.hideRulers(); | 443 | this.application.ninja.stage.stageView.hideRulers(); |
@@ -414,7 +454,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
414 | this.activeDocument.container.style["display"] = "block"; | 454 | this.activeDocument.container.style["display"] = "block"; |
415 | if(this.activeDocument.currentView === "design"){ | 455 | if(this.activeDocument.currentView === "design"){ |
416 | this.activeDocument.container.parentNode.style["display"] = "block"; | 456 | this.activeDocument.container.parentNode.style["display"] = "block"; |
417 | this.application.ninja.stage.restoreScroll(); | 457 | this.activeDocument.restoreAppState(); |
418 | this.application.ninja.stage.hideCanvas(false); | 458 | this.application.ninja.stage.hideCanvas(false); |
419 | this.application.ninja.stage.stageView.showRulers(); | 459 | this.application.ninja.stage.stageView.showRulers(); |
420 | }else{ | 460 | }else{ |