diff options
Diffstat (limited to 'js/controllers')
-rwxr-xr-x | js/controllers/document-controller.js | 68 | ||||
-rwxr-xr-x | js/controllers/selection-controller.js | 21 | ||||
-rwxr-xr-x | js/controllers/styles-controller.js | 10 | ||||
-rwxr-xr-x | js/controllers/undo-controller.js | 17 |
4 files changed, 96 insertions, 20 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 64ff2c7e..87e93465 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -60,8 +60,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
60 | this.eventManager.addEventListener("executeSave", this, false); | 60 | this.eventManager.addEventListener("executeSave", this, false); |
61 | this.eventManager.addEventListener("executeSaveAs", this, false); | 61 | this.eventManager.addEventListener("executeSaveAs", this, false); |
62 | this.eventManager.addEventListener("executeSaveAll", this, false); | 62 | this.eventManager.addEventListener("executeSaveAll", this, false); |
63 | this.eventManager.addEventListener("executeFileClose", this, false); | ||
63 | 64 | ||
64 | this.eventManager.addEventListener("recordStyleChanged", this, false); | 65 | this.eventManager.addEventListener("styleSheetDirty", this, false); |
65 | 66 | ||
66 | } | 67 | } |
67 | }, | 68 | }, |
@@ -76,11 +77,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
76 | // | 77 | // |
77 | handleWebRequest: { | 78 | handleWebRequest: { |
78 | value: function (request) { | 79 | value: function (request) { |
79 | if (this._hackRootFlag && request.url.indexOf('js/document/templates/montage-html') !== -1) { | 80 | //TODO: Check if frameId is proper |
81 | if (this._hackRootFlag && request.parentFrameId !== -1) { | ||
80 | //TODO: Optimize creating string | 82 | //TODO: Optimize creating string |
81 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; | 83 | //console.log(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1], request.url); |
82 | } | 84 | //return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; |
85 | return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/montage-html/'))[1]}; | ||
83 | } | 86 | } |
87 | } | ||
84 | }, | 88 | }, |
85 | //////////////////////////////////////////////////////////////////// | 89 | //////////////////////////////////////////////////////////////////// |
86 | // | 90 | // |
@@ -154,17 +158,29 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
154 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 158 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
155 | saveAsSettings.fileName = this.activeDocument.name; | 159 | saveAsSettings.fileName = this.activeDocument.name; |
156 | saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); | 160 | saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); |
157 | //add callback | 161 | saveAsSettings.callback = this.saveAsCallback.bind(this); |
158 | this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); | 162 | this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); |
159 | } | 163 | } |
160 | } | 164 | } |
161 | }, | 165 | }, |
162 | 166 | //////////////////////////////////////////////////////////////////// | |
167 | handleExecuteFileClose:{ | ||
168 | value: function(event) { | ||
169 | if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ | ||
170 | this.closeDocument(this.activeDocument.uuid); | ||
171 | } | ||
172 | } | ||
173 | }, | ||
174 | //////////////////////////////////////////////////////////////////// | ||
163 | // | 175 | // |
164 | fileSaveResult: { | 176 | fileSaveResult: { |
165 | value: function (result) { | 177 | value: function (result) { |
166 | if(result.status === 204){ | 178 | if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved |
167 | this.activeDocument.needsSave = false; | 179 | this.activeDocument.needsSave = false; |
180 | if(this.application.ninja.currentDocument !== null){ | ||
181 | //clear Dirty StyleSheets for the saved document | ||
182 | this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument); | ||
183 | } | ||
168 | } | 184 | } |
169 | } | 185 | } |
170 | }, | 186 | }, |
@@ -246,6 +262,29 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
246 | }, | 262 | }, |
247 | //////////////////////////////////////////////////////////////////// | 263 | //////////////////////////////////////////////////////////////////// |
248 | // | 264 | // |
265 | saveAsCallback:{ | ||
266 | value:function(saveAsDetails){ | ||
267 | var fileUri = null, filename = saveAsDetails.filename, destination = saveAsDetails.destination; | ||
268 | //update document metadata | ||
269 | this.activeDocument.name = ""+filename; | ||
270 | //prepare new file uri | ||
271 | if(destination && (destination.charAt(destination.length -1) !== "/")){ | ||
272 | destination = destination + "/"; | ||
273 | } | ||
274 | fileUri = destination+filename; | ||
275 | |||
276 | this.activeDocument.uri = fileUri; | ||
277 | //save a new file | ||
278 | //use the ioMediator.fileSaveAll when implemented | ||
279 | this.activeDocument._userDocument.name=filename; | ||
280 | this.activeDocument._userDocument.root=destination; | ||
281 | this.activeDocument._userDocument.uri=fileUri; | ||
282 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | ||
283 | // | ||
284 | } | ||
285 | }, | ||
286 | |||
287 | //////////////////////////////////////////////////////////////////// | ||
249 | openDocument: { | 288 | openDocument: { |
250 | value: function(doc) { | 289 | value: function(doc) { |
251 | 290 | ||
@@ -333,14 +372,23 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
333 | nextDocumentIndex = closeDocumentIndex - 1; | 372 | nextDocumentIndex = closeDocumentIndex - 1; |
334 | } | 373 | } |
335 | this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); | 374 | this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); |
375 | if(typeof this.activeDocument.stopVideos !== "undefined"){doc.stopVideos();} | ||
336 | this._removeDocumentView(doc.container); | 376 | this._removeDocumentView(doc.container); |
337 | }else if(this._documents.length === 0){ | 377 | }else if(this._documents.length === 0){ |
378 | if(typeof this.activeDocument.pauseAndStopVideos !== "undefined"){ | ||
379 | this.activeDocument.pauseAndStopVideos(); | ||
380 | } | ||
338 | this.activeDocument = null; | 381 | this.activeDocument = null; |
339 | this._removeDocumentView(doc.container); | 382 | this._removeDocumentView(doc.container); |
340 | this.application.ninja.stage.stageView.hideRulers(); | 383 | this.application.ninja.stage.stageView.hideRulers(); |
341 | document.getElementById("iframeContainer").style.display="block"; | 384 | document.getElementById("iframeContainer").style.display="block"; |
342 | 385 | ||
343 | this.application.ninja.stage.hideCanvas(true); | 386 | this.application.ninja.stage.hideCanvas(true); |
387 | }else{//closing inactive document tab - just clear DOM | ||
388 | if(typeof doc.pauseAndStopVideos !== "undefined"){ | ||
389 | doc.pauseAndStopVideos(); | ||
390 | } | ||
391 | this._removeDocumentView(doc.container); | ||
344 | } | 392 | } |
345 | 393 | ||
346 | NJevent("closeDocument", doc.uri); | 394 | NJevent("closeDocument", doc.uri); |
@@ -503,5 +551,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
503 | value: function() { | 551 | value: function() { |
504 | return "userDocument_" + (this._iframeCounter++); | 552 | return "userDocument_" + (this._iframeCounter++); |
505 | } | 553 | } |
554 | }, | ||
555 | |||
556 | handleStyleSheetDirty:{ | ||
557 | value:function(){ | ||
558 | this.activeDocument.needsSave = true; | ||
506 | } | 559 | } |
560 | } | ||
507 | }); | 561 | }); |
diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index c4623d3f..c713b6e5 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js | |||
@@ -48,6 +48,7 @@ exports.SelectionController = Montage.create(Component, { | |||
48 | this.eventManager.addEventListener("selectAll", this, false); | 48 | this.eventManager.addEventListener("selectAll", this, false); |
49 | this.eventManager.addEventListener("deleteSelection", this, false); | 49 | this.eventManager.addEventListener("deleteSelection", this, false); |
50 | this.eventManager.addEventListener("switchDocument", this, false); | 50 | this.eventManager.addEventListener("switchDocument", this, false); |
51 | this.eventManager.addEventListener("closeDocument", this, false); | ||
51 | // defaultEventManager.addEventListener( "undo", this, false); | 52 | // defaultEventManager.addEventListener( "undo", this, false); |
52 | // defaultEventManager.addEventListener( "redo", this, false); | 53 | // defaultEventManager.addEventListener( "redo", this, false); |
53 | } | 54 | } |
@@ -76,7 +77,7 @@ exports.SelectionController = Montage.create(Component, { | |||
76 | 77 | ||
77 | 78 | ||
78 | this.application.ninja.selectedElements = currentSelectionArray; | 79 | this.application.ninja.selectedElements = currentSelectionArray; |
79 | NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); | 80 | NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); |
80 | 81 | ||
81 | 82 | ||
82 | 83 | ||
@@ -89,15 +90,17 @@ exports.SelectionController = Montage.create(Component, { | |||
89 | } | 90 | } |
90 | }, | 91 | }, |
91 | 92 | ||
92 | handleSwitchDocument: { | 93 | handleSwitchDocument: { |
93 | value: function() { | 94 | value: function() { |
94 | this._selectedItems = this.application.ninja.selectedElements.slice(0); | 95 | if(this.application.ninja.documentController.activeDocument.currentView === "design"){ |
95 | if(this._selectedItems.length === 0 ){ | 96 | this._selectedItems = this.application.ninja.selectedElements.slice(0); |
96 | this._isDocument = true; | 97 | if(this._selectedItems.length === 0 ){ |
97 | }else{ | 98 | this._isDocument = true; |
98 | this._isDocument = false; | 99 | }else{ |
100 | this._isDocument = false; | ||
101 | } | ||
102 | NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); | ||
99 | } | 103 | } |
100 | NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); | ||
101 | } | 104 | } |
102 | }, | 105 | }, |
103 | 106 | ||
@@ -137,7 +140,7 @@ exports.SelectionController = Montage.create(Component, { | |||
137 | value: function(event) { | 140 | value: function(event) { |
138 | this.application.ninja.selectedElements = []; | 141 | this.application.ninja.selectedElements = []; |
139 | this._isDocument = true; | 142 | this._isDocument = true; |
140 | NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); | 143 | NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); |
141 | } | 144 | } |
142 |