From 919a0d0ed35c24b1047281723ddde2ac98fc9a3e Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 15 May 2012 22:36:44 -0700 Subject: document close handler. initial working draft Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 66 ++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'js/controllers/document-controller.js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 48ceb21b..51791a11 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -33,6 +33,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: false }, + _hackInitialStyles: { + value: true + }, + _activeDocument: { value: null }, _iframeCounter: { value: 1, enumerable: false }, _iframeHolder: { value: null, enumerable: false }, @@ -44,8 +48,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, return this._activeDocument; }, set: function(doc) { - if(!!this._activeDocument){ this._activeDocument.isActive = false;} +// if(!!this._activeDocument){ this._activeDocument.isActive = false;} + this._activeDocument = doc; + if(!!this._activeDocument){ if(this._documents.indexOf(doc) === -1) this._documents.push(doc); this._activeDocument.isActive = true; @@ -213,13 +219,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileClose:{ value: function(event) { if (this.activeDocument) { - this.activeDocument.closeDocument(); +// this.activeDocument.closeDocument(); + this.closeFile(this.activeDocument); } - /* -if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ - this.closeDocument(this.activeDocument.uuid); - } -*/ } }, //////////////////////////////////////////////////////////////////// @@ -448,7 +450,32 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ */ } - }, + }, + + closeFile: { + value: function(document) { + document.closeDocument(this, this.onCloseFile); + } + }, + + onCloseFile: { + value: function(doc) { + + this._documents.splice(this._documents.indexOf(doc), 1); + + this.activeDocument = null; + + this.application.ninja.stage.stageView.hideRulers(); + +// document.getElementById("iframeContainer").style.display="block"; + + this.application.ninja.stage.hideCanvas(true); + + + NJevent("closeDocument", doc.model.file.uri); + //TODO: Delete object here + } + }, closeDocument: { value: function(id) { @@ -468,15 +495,7 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();} this._removeDocumentView(doc.container); }else if(this._documents.length === 0){ - if(typeof this.activeDocument.pauseAndStopVideos !== "undefined"){ - this.activeDocument.pauseAndStopVideos(); - } - this.activeDocument = null; - this._removeDocumentView(doc.container); - this.application.ninja.stage.stageView.hideRulers(); - document.getElementById("iframeContainer").style.display="block"; - - this.application.ninja.stage.hideCanvas(true); + // See above }else{//closing inactive document tab - just clear DOM if(typeof doc.pauseAndStopVideos !== "undefined"){ doc.pauseAndStopVideos(); @@ -515,6 +534,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ this.application.ninja.stage.stageView.showCodeViewBar(false); this.application.ninja.stage.stageView.restoreAllPanels(); + + // Flag to stop stylesheet dirty event + this._hackInitialStyles = false; } }, @@ -552,12 +574,6 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ /** * VIEW Related Methods */ - // PUBLIC - ShowActiveDocument: { - value: function() { - this.activeDocument.iframe.style.opacity = 1.0; - } - }, // PRIVATE _findDocumentByUUID: { @@ -656,7 +672,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ handleStyleSheetDirty:{ value:function(){ -// this.activeDocument.model.needsSave = true; + if(!this._hackInitialStyles) { + this.activeDocument.model.needsSave = true; + } } }, -- cgit v1.2.3 From 0eaa0be8e030a6bac5ab70af3c1044682d973366 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 15 May 2012 23:33:44 -0700 Subject: fixed some binding warnings Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/controllers/document-controller.js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 51791a11..fba9fad5 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -463,7 +463,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this._documents.splice(this._documents.indexOf(doc), 1); - this.activeDocument = null; + this._activeDocument = null; this.application.ninja.stage.stageView.hideRulers(); -- cgit v1.2.3 From 99f16ae08fbb0a6dfe6008c9833f2253b18c19e5 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 16 May 2012 14:13:28 -0700 Subject: removing first draw on the component event Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'js/controllers/document-controller.js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index fba9fad5..1e894f02 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -76,24 +76,13 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("styleSheetDirty", this, false); - this.eventManager.addEventListener("addComponentFirstDraw", this, false); - // Temporary add listeners for the new stage templates this.eventManager.addEventListener("executeWebpageOpen", this, false); this.eventManager.addEventListener("executeNewWebpage", this, false); } }, - handleAddComponentFirstDraw: { - value: function (e) { - //TODO: Add logic to reparse the document for dynamically added styles - //console.log(e); - } - }, - - - - + //TODO: Ensure these APIs are not needed //////////////////////////////////////////////////////////////////// // -- cgit v1.2.3 From b1e5ef1949eeddc39a1e9570a65612879cbdadef Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 16 May 2012 20:49:40 -0700 Subject: clearing the needs save flag on save. Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/controllers/document-controller.js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 1e894f02..ecb988ff 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -177,6 +177,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, testCallback: { value: function (value) { console.log(value); + //TODO: Move this to the model.save() + this.activeDocument.model.needsSave = false; } }, //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From c26de5fa7b909a53b103b72027b5cbe7c3e1c49f Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 16 May 2012 22:48:39 -0700 Subject: code cleanup and refactoring of the document controller and stage view Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 194 ++++++++++------------------------ 1 file changed, 56 insertions(+), 138 deletions(-) (limited to 'js/controllers/document-controller.js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index ecb988ff..1796f9b5 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -21,10 +21,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: false }, - webTemplate: { - value: false - }, - _documents: { value: [] }, @@ -75,10 +71,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("executeFileCloseAll", this, false); this.eventManager.addEventListener("styleSheetDirty", this, false); - - // Temporary add listeners for the new stage templates - this.eventManager.addEventListener("executeWebpageOpen", this, false); - this.eventManager.addEventListener("executeNewWebpage", this, false); } }, @@ -138,20 +130,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - handleExecuteWebpageOpen: { - value: function(event) { - this.webTemplate = true; - this.handleExecuteFileOpen(event); - } - }, - - handleExecuteNewWebpage: { - value: function(event) { - this.webTemplate = true; - this.handleExecuteNewFile(event); - } - }, - handleExecuteNewFile: { value: function(event) { var newFileSettings = event._event.settings || {}; @@ -304,12 +282,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.isNewFilePath = false;//reset path identifier flag //Sending full response object - // TODO: Unify those 2 methods. Using if/else for the new template - if(this.webTemplate) { - this.openWebDocument(response); - } else { - this.openDocument(response); - } + this.openDocument(response); + } else if (!!response && (response.status === 404)){ alert("Unable to open file.\n [Error: File does not exist]"); } else if (!!response && (response.status === 500)){ @@ -345,30 +319,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, }, //////////////////////////////////////////////////////////////////// - openDocument: { - value: function(doc) { - - // - this.documentHackReference = doc; - // - switch (doc.extension) { - case 'html': - //Open in designer view - Montage.create(HTMLDocument).initialize(doc, Uuid.generate(), this._createIframeElement(), this._onOpenDocument.bind(this)); - break; - default: - //Open in code view - var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea; - textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid); - code.initialize(doc, docuuid, textArea, textArea.parentNode); - //code.init(doc.name, doc.uri, doc.extension, null, docuuid); - code.textArea.value = doc.content; - this.application.ninja.stage.stageView.createTextView(code); - break; - } - } - }, - openWebDocument: { + openDocument: { value: function(doc) { var template, dimensions; if (doc.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { @@ -484,14 +435,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } this.application.ninja.stage.stageView.switchDocument(this._documents[nextDocumentIndex]); if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();} - this._removeDocumentView(doc.container); + doc.container.parentNode.removeChild(doc.container); }else if(this._documents.length === 0){ // See above }else{//closing inactive document tab - just clear DOM if(typeof doc.pauseAndStopVideos !== "undefined"){ doc.pauseAndStopVideos(); } - this._removeDocumentView(doc.container); + doc.container.parentNode.removeChild(doc.container); } NJevent("closeDocument", doc.uri); @@ -500,41 +451,65 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - // Document has been loaded into the Iframe. Dispatch the event. - // Event Detail: Contains the current ActiveDocument + // Open document callback _onOpenDocument: { value: function(doc){ - this.application.ninja.currentDocument = doc; - this._hideCurrentDocument(); - this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid); - this.application.ninja.stage.hideCanvas(false); + if(this.activeDocument) { + // There is a document currently opened - this.activeDocument = doc; +// this.application.ninja.stage.stageView.showCodeViewBar(false); +// this.application.ninja.stage.stageView.restoreAllPanels(); - if(!this.webTemplate) { - this._showCurrentDocument(); + // + /* + if(this.activeDocument.currentView === "design"){ + this.activeDocument.saveAppState(); + this.activeDocument.container.parentNode.style["display"] = "none"; + this.application.ninja.stage.hideCanvas(true); + this.application.ninja.stage.stageView.hideRulers(); + } + + this.activeDocument.container.style["display"] = "none"; + */ + // hide current document } else { - this.application.ninja.stage.stageView.showRulers(); - } + // There is no document opened - this.webTemplate = false; + // Set the active document + this.activeDocument = doc; - this._initializeBodyStyles(); - NJevent("onOpenDocument", doc); + // Show the canvas + this.application.ninja.stage.hideCanvas(false); + + // Show the rulers + // TODO: Move this indo design view + this.application.ninja.stage.stageView.showRulers(); - this.application.ninja.stage.stageView.showCodeViewBar(false); - this.application.ninja.stage.stageView.restoreAllPanels(); + // Initialize the documentRoot styles + this.initializeRootStyles(doc.documentRoot); + // Flag to stop stylesheet dirty event + this._hackInitialStyles = false; - // Flag to stop stylesheet dirty event - this._hackInitialStyles = false; + NJevent("onOpenDocument", doc); + } } }, _onOpenTextDocument: { value: function(doc) { - this._hideCurrentDocument(); + if(this.activeDocument) { + if(this.activeDocument.currentView === "design"){ + this.activeDocument.saveAppState(); + this.activeDocument.container.parentNode.style["display"] = "none"; + this.application.ninja.stage.hideCanvas(true); + this.application.ninja.stage.stageView.hideRulers(); + } + + this.activeDocument.container.style["display"] = "none"; + } + this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe this.activeDocument = doc; @@ -589,21 +564,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - _hideCurrentDocument: { - value: function() { - if(this.activeDocument) { - if(this.activeDocument.currentView === "design"){ - this.activeDocument.saveAppState(); - this.activeDocument.container.parentNode.style["display"] = "none"; - this.application.ninja.stage.hideCanvas(true); - this.application.ninja.stage.stageView.hideRulers(); - } - - this.activeDocument.container.style["display"] = "none"; - } - } - }, - _showCurrentDocument: { value: function() { if(this.activeDocument) { @@ -611,8 +571,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(this.activeDocument.currentView === "design"){ this.activeDocument.container.parentNode.style["display"] = "block"; this.activeDocument.restoreAppState(); - this.application.ninja.stage.hideCanvas(false); - this.application.ninja.stage.stageView.showRulers(); }else{ //hide the iframe when switching to code view document.getElementById("iframeContainer").style.display = "none"; @@ -621,46 +579,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - _removeDocumentView: { - value: function(node) { - node.parentNode.removeChild(node); - } - }, - - reloadDocumentContent: { - value: function() { - this.activeDocument._window.location.reload(); - } - }, - - /** - * Creates a new iFrame element using a new unique ID for it. Returns the iframe ID. - */ - _createIframeElement: { - value: function() { - var e = document.createElement("iframe"); - e.id = this._createIframeID(); - e.style.border = "none"; - e.style.opacity = 0; - e.height = 1000; - e.width = 2000; - e.src = ""; - - if(!this._iframeHolder) this._iframeHolder = document.getElementById("iframeContainer"); - - this._iframeHolder.appendChild(e); - - return e; - } - }, - - - _createIframeID: { - value: function() { - return "userDocument_" + (this._iframeCounter++); - } - }, - handleStyleSheetDirty:{ value:function(){ if(!this._hackInitialStyles) { @@ -669,27 +587,27 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - _initializeBodyStyles: { - value: function() { + // TODO: Move this into the design views + initializeRootStyles: { + value: function(documentRoot) { var sc = this.application.ninja.stylesController, - docRoot = this.application.ninja.currentDocument.documentRoot, styles = {}, needsRule = false, rule; - if(sc.getElementStyle(docRoot, "width", false, false) == null) { + if(sc.getElementStyle(documentRoot, "width", false, false) == null) { styles['width'] = '100%'; needsRule = true; } - if(sc.getElementStyle(docRoot, "height", false, false) == null) { + if(sc.getElementStyle(documentRoot, "height", false, false) == null) { styles['height'] = '100%'; needsRule = true; } - if(sc.getElementStyle(docRoot, "-webkit-transform", false, false) == null) { + if(sc.getElementStyle(documentRoot, "-webkit-transform", false, false) == null) { styles['-webkit-transform'] = 'perspective(1400) matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)'; needsRule = true; } - if(sc.getElementStyle(docRoot, "-webkit-transform-style", false, false) == null) { + if(sc.getElementStyle(documentRoot, "-webkit-transform-style", false, false) == null) { styles['-webkit-transform-style'] = 'preserve-3d'; needsRule = true; } @@ -697,7 +615,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(needsRule) { rule = sc.addRule('.ninja-body{}'); sc.setStyles(rule, styles); - sc.addClass(docRoot, "ninja-body"); + sc.addClass(documentRoot, "ninja-body"); } } } -- cgit v1.2.3 From 402a369c7bf164c3c6686be3a33f5e36f25e4130 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 16 May 2012 23:19:32 -0700 Subject: document controller and stage view code cleanup Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'js/controllers/document-controller.js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 1796f9b5..cf46e73e 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -458,8 +458,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(this.activeDocument) { // There is a document currently opened -// this.application.ninja.stage.stageView.showCodeViewBar(false); -// this.application.ninja.stage.stageView.restoreAllPanels(); + + + //this.application.ninja.stage.stageView.showCodeViewBar(false); + //this.application.ninja.stage.stageView.restoreAllPanels(); // /* @@ -472,6 +474,18 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.activeDocument.container.style["display"] = "none"; */ + + /* + this.activeDocument.container.style["display"] = "block"; + if(this.activeDocument.currentView === "design"){ + this.activeDocument.container.parentNode.style["display"] = "block"; + this.activeDocument.restoreAppState(); + }else{ + //hide the iframe when switching to code view + document.getElementById("iframeContainer").style.display = "none"; + } + + */ // hide current document } else { // There is no document opened @@ -564,21 +578,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } }, - _showCurrentDocument: { - value: function() { - if(this.activeDocument) { - this.activeDocument.container.style["display"] = "block"; - if(this.activeDocument.currentView === "design"){ - this.activeDocument.container.parentNode.style["display"] = "block"; - this.activeDocument.restoreAppState(); - }else{ - //hide the iframe when switching to code view - document.getElementById("iframeContainer").style.display = "none"; - } - } - } - }, - handleStyleSheetDirty:{ value:function(){ if(!this._hackInitialStyles) { -- cgit v1.2.3