aboutsummaryrefslogtreecommitdiff
path: root/js/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers')
-rwxr-xr-xjs/controllers/document-controller.js225
1 files changed, 72 insertions, 153 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 1e894f02..cf46e73e 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -21,10 +21,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
21 value: false 21 value: false
22 }, 22 },
23 23
24 webTemplate: {
25 value: false
26 },
27
28 _documents: { 24 _documents: {
29 value: [] 25 value: []
30 }, 26 },
@@ -75,10 +71,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
75 this.eventManager.addEventListener("executeFileCloseAll", this, false); 71 this.eventManager.addEventListener("executeFileCloseAll", this, false);
76 72
77 this.eventManager.addEventListener("styleSheetDirty", this, false); 73 this.eventManager.addEventListener("styleSheetDirty", this, false);
78
79 // Temporary add listeners for the new stage templates
80 this.eventManager.addEventListener("executeWebpageOpen", this, false);
81 this.eventManager.addEventListener("executeNewWebpage", this, false);
82 } 74 }
83 }, 75 },
84 76
@@ -138,20 +130,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
138 } 130 }
139 }, 131 },
140 132
141 handleExecuteWebpageOpen: {
142 value: function(event) {
143 this.webTemplate = true;
144 this.handleExecuteFileOpen(event);
145 }
146 },
147
148 handleExecuteNewWebpage: {
149 value: function(event) {
150 this.webTemplate = true;
151 this.handleExecuteNewFile(event);
152 }
153 },
154
155 handleExecuteNewFile: { 133 handleExecuteNewFile: {
156 value: function(event) { 134 value: function(event) {
157 var newFileSettings = event._event.settings || {}; 135 var newFileSettings = event._event.settings || {};
@@ -177,6 +155,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
177 testCallback: { 155 testCallback: {
178 value: function (value) { 156 value: function (value) {
179 console.log(value); 157 console.log(value);
158 //TODO: Move this to the model.save()
159 this.activeDocument.model.needsSave = false;
180 } 160 }
181 }, 161 },
182 //////////////////////////////////////////////////////////////////// 162 ////////////////////////////////////////////////////////////////////
@@ -302,12 +282,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
302 this.isNewFilePath = false;//reset path identifier flag 282 this.isNewFilePath = false;//reset path identifier flag
303 283
304 //Sending full response object 284 //Sending full response object
305 // TODO: Unify those 2 methods. Using if/else for the new template 285 this.openDocument(response);
306 if(this.webTemplate) { 286
307 this.openWebDocument(response);
308 } else {
309 this.openDocument(response);
310 }
311 } else if (!!response && (response.status === 404)){ 287 } else if (!!response && (response.status === 404)){
312 alert("Unable to open file.\n [Error: File does not exist]"); 288 alert("Unable to open file.\n [Error: File does not exist]");
313 } else if (!!response && (response.status === 500)){ 289 } else if (!!response && (response.status === 500)){
@@ -343,30 +319,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
343 }, 319 },
344 320
345 //////////////////////////////////////////////////////////////////// 321 ////////////////////////////////////////////////////////////////////
346 openDocument: { 322 openDocument: {
347 value: function(doc) {
348
349 //
350 this.documentHackReference = doc;
351 //
352 switch (doc.extension) {
353 case 'html':
354 //Open in designer view
355 Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument.bind(this));
356 break;
357 default:
358 //Open in code view
359 var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea;
360 textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid);
361 code.initialize(doc, docuuid, textArea, textArea.parentNode);
362 //code.init(doc.name, doc.uri, doc.extension, null, docuuid);
363 code.textArea.value = doc.content;
364 this.application.ninja.stage.stageView.createTextView(code);
365 break;
366 }
367 }
368 },
369 openWebDocument: {
370 value: function(doc) { 323 value: function(doc) {
371 var template, dimensions; 324 var template, dimensions;
372 if (doc.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { 325 if (doc.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) {
@@ -482,14 +435,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
482 } 435 }
483 this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); 436 this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]);
484 if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();} 437 if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();}
485 this._removeDocumentView(doc.container); 438 doc.container.parentNode.removeChild(doc.container);
486 }else if(this._documents.length === 0){ 439 }else if(this._documents.length === 0){
487 // See above 440 // See above
488 }else{//closing inactive document tab - just clear DOM 441 }else{//closing inactive document tab - just clear DOM
489 if(typeof doc.pauseAndStopVideos !== "undefined"){ 442 if(typeof doc.pauseAndStopVideos !== "undefined"){
490 doc.pauseAndStopVideos(); 443 doc.pauseAndStopVideos();
491 } 444 }
492 this._removeDocumentView(doc.container); 445 doc.container.parentNode.removeChild(doc.container);
493 } 446 }
494 447
495 NJevent("closeDocument", doc.uri); 448 NJevent("closeDocument", doc.uri);
@@ -498,41 +451,79 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
498 } 451 }
499 }, 452 },
500 453
501 // Document has been loaded into the Iframe. Dispatch the event. 454 // Open document callback
502 // Event Detail: Contains the current ActiveDocument
503 _onOpenDocument: { 455 _onOpenDocument: {
504 value: function(doc){ 456 value: function(doc){
505 this.application.ninja.currentDocument = doc;
506 this._hideCurrentDocument();
507 this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid);
508 457
509 this.application.ninja.stage.hideCanvas(false); 458 if(this.activeDocument) {
459 // There is a document currently opened
510 460
511 this.activeDocument = doc;
512 461
513 if(!this.webTemplate) { 462
514 this._showCurrentDocument(); 463 //this.application.ninja.stage.stageView.showCodeViewBar(false);
464 //this.application.ninja.stage.stageView.restoreAllPanels();
465
466 //
467 /*
468 if(this.activeDocument.currentView === "design"){
469 this.activeDocument.saveAppState();
470 this.activeDocument.container.parentNode.style["display"] = "none";
471 this.application.ninja.stage.hideCanvas(true);
472 this.application.ninja.stage.stageView.hideRulers();
473 }
474
475 this.activeDocument.container.style["display"] = "none";
476 */
477
478 /*
479 this.activeDocument.container.style["display"] = "block";
480 if(this.activeDocument.currentView === "design"){
481 this.activeDocument.container.parentNode.style["display"] = "block";
482 this.activeDocument.restoreAppState();
483 }else{
484 //hide the iframe when switching to code view
485 document.getElementById("iframeContainer").style.display = "none";
486 }
487
488 */
489 // hide current document
515 } else { 490 } else {
516 this.application.ninja.stage.stageView.showRulers(); 491 // There is no document opened
517 } 492
493 // Set the active document
494 this.activeDocument = doc;
518 495
519 this.webTemplate = false; 496 // Show the canvas
497 this.application.ninja.stage.hideCanvas(false);
520 498
521 this._initializeBodyStyles(); 499 // Show the rulers
522 NJevent("onOpenDocument", doc); 500 // TODO: Move this indo design view
501 this.application.ninja.stage.stageView.showRulers();
523 502
524 this.application.ninja.stage.stageView.showCodeViewBar(false); 503 // Initialize the documentRoot styles
525 this.application.ninja.stage.stageView.restoreAllPanels(); 504 this.initializeRootStyles(doc.documentRoot);
505 // Flag to stop stylesheet dirty event
506 this._hackInitialStyles = false;
526 507
527 // Flag to stop stylesheet dirty event 508 NJevent("onOpenDocument", doc);
528 this._hackInitialStyles = false; 509 }
529 } 510 }
530 }, 511 },
531 512
532 513
533 _onOpenTextDocument: {