aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers')
-rwxr-xr-xjs/controllers/document-controller.js48
-rwxr-xr-xjs/controllers/selection-controller.js31
-rwxr-xr-xjs/controllers/styles-controller.js10
3 files changed, 76 insertions, 13 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 194496a6..de080167 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -61,7 +61,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
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 63
64 this.eventManager.addEventListener("recordStyleChanged", this, false); 64 this.eventManager.addEventListener("styleSheetDirty", this, false);
65 65
66 } 66 }
67 }, 67 },
@@ -157,7 +157,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
157 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 157 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
158 saveAsSettings.fileName = this.activeDocument.name; 158 saveAsSettings.fileName = this.activeDocument.name;
159 saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); 159 saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/"));
160 //add callback 160 saveAsSettings.callback = this.saveAsCallback.bind(this);
161 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); 161 this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings);
162 } 162 }
163 } 163 }
@@ -166,8 +166,12 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
166 // 166 //
167 fileSaveResult: { 167 fileSaveResult: {
168 value: function (result) { 168 value: function (result) {
169 if(result.status === 204){ 169 if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved
170 this.activeDocument.needsSave = false; 170 this.activeDocument.needsSave = false;
171 if(this.application.ninja.currentDocument !== null){
172 //clear Dirty StyleSheets for the saved document
173 this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument);
174 }
171 } 175 }
172 } 176 }
173 }, 177 },
@@ -249,6 +253,29 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
249 }, 253 },
250 //////////////////////////////////////////////////////////////////// 254 ////////////////////////////////////////////////////////////////////
251 // 255 //
256 saveAsCallback:{
257 value:function(saveAsDetails){
258 var fileUri = null, filename = saveAsDetails.filename, destination = saveAsDetails.destination;
259 //update document metadata
260 this.activeDocument.name = ""+filename;
261 //prepare new file uri
262 if(destination && (destination.charAt(destination.length -1) !== "/")){
263 destination = destination + "/";
264 }
265 fileUri = destination+filename;
266
267 this.activeDocument.uri = fileUri;
268 //save a new file
269 //use the ioMediator.fileSaveAll when implemented
270 this.activeDocument._userDocument.name=filename;
271 this.activeDocument._userDocument.root=destination;
272 this.activeDocument._userDocument.uri=fileUri;
273 this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this));
274 //
275 }
276 },
277
278 ////////////////////////////////////////////////////////////////////
252 openDocument: { 279 openDocument: {
253 value: function(doc) { 280 value: function(doc) {
254 281
@@ -336,14 +363,23 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
336 nextDocumentIndex = closeDocumentIndex - 1; 363 nextDocumentIndex = closeDocumentIndex - 1;
337 } 364 }
338 this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); 365 this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]);
366 doc.stopVideos();
339 this._removeDocumentView(doc.container); 367 this._removeDocumentView(doc.container);
340 }else if(this._documents.length === 0){ 368 }else if(this._documents.length === 0){
369 if(typeof this.activeDocument.pauseVideos !== "undefined"){
370 this.activeDocument.pauseVideos(true);
371 }
341 this.activeDocument = null; 372 this.activeDocument = null;
342 this._removeDocumentView(doc.container); 373 this._removeDocumentView(doc.container);
343 this.application.ninja.stage.stageView.hideRulers(); 374 this.application.ninja.stage.stageView.hideRulers();
344 document.getElementById("iframeContainer").style.display="block"; 375 document.getElementById("iframeContainer").style.display="block";
345 376
346 this.application.ninja.stage.hideCanvas(true); 377 this.application.ninja.stage.hideCanvas(true);
378 }else{//closing inactive document tab - just clear DOM
379 if(typeof doc.pauseVideos !== "undefined"){
380 doc.pauseVideos(true);
381 }
382 this._removeDocumentView(doc.container);
347 } 383 }
348 384
349 NJevent("closeDocument", doc.uri); 385 NJevent("closeDocument", doc.uri);
@@ -506,5 +542,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
506 value: function() { 542 value: function() {
507 return "userDocument_" + (this._iframeCounter++); 543 return "userDocument_" + (this._iframeCounter++);
508 } 544 }
545 },
546
547 handleStyleSheetDirty:{
548 value:function(){
549 this.activeDocument.needsSave = true;
509 } 550 }
551 }
510}); 552});
diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js
index 75968d4a..eff9c91a 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 }
@@ -89,17 +90,31 @@ 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} );
103
104 this._selectionContainer = this.application.ninja.currentSelectedContainer;
99 } 105 }
100 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); 106 }
107 },
101 108
102 this._selectionContainer = this.application.ninja.currentSelectedContainer; 109 handleCloseDocument:{
110 value: function() {
111 //clear selections if all documents are closed
112 if(this.application.ninja.documentController._documents.length === 0){
113 this._selectedItems.length =0;
114 this.application.ninja.selectedElements.length =0;
115 this._isDocument = true;
116 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} );
117 }
103 } 118 }
104 }, 119 },
105 120
diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js
index 662816f5..addfc24e 100755
--- a/js/controllers/styles-controller.js
+++ b/js/controllers/styles-controller.js
@@ -1236,11 +1236,17 @@ var stylesController = exports.StylesController = Montage.create(Component, {
1236 1236
1237 clearDirtyStyleSheets : { 1237 clearDirtyStyleSheets : {
1238 value: function(doc) { 1238 value: function(doc) {
1239 if(!doc) { 1239 this.dirtyStyleSheets.length = 0;
1240
1241 if(doc) {
1242 var stillDirty = this.dirtyStyleSheets.filter(function(sheet) {
1243 return sheet.document !== doc;
1244 });
1240 this.dirtyStyleSheets = null; 1245 this.dirtyStyleSheets = null;
1241 this.dirtyStyleSheets = []; 1246 this.dirtyStyleSheets = stillDirty;
1242 } 1247 }
1243 1248
1249
1244 } 1250 }
1245 }, 1251 },
1246 1252