From 75fe4f36a6768d688792bc1925cfa4bfa508ac3e Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 22 May 2012 18:02:01 -0700 Subject: Adding redirect from app folder in templates This doesn't resolve the issue of XHR requests made in Montage. --- js/controllers/document-controller.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index d99fadbb..2eba556e 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -80,6 +80,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, 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/banner/'))[1]}; } else if (request.url.indexOf('js/document/templates/html') !== -1) { 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/html/'))[1]}; + } else if (request.url.indexOf('js/document/templates/app') !== -1) { + 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/app/'))[1]}; } else { //Error, not a valid folder } @@ -103,7 +105,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, }, //////////////////////////////////////////////////////////////////// - -- cgit v1.2.3 From d5b36812ba84e49aa8b597eea9f75bf36ddcb571 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 23 May 2012 15:24:25 -0700 Subject: fixing the styles manager to open code view files and closing the last document. Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 15 ++++++--------- js/controllers/styles-controller.js | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 3e15511d..aa037bd4 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -399,10 +399,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(this._documents.length > 0) { previousFocusedDocument = this._documents[this._documents.length - 1]; - this._activeDocument = previousFocusedDocument; - this.switchDocuments(this.activeDocument, previousFocusedDocument, true); + this.activeDocument = previousFocusedDocument; + this.switchDocuments(this.activeDocument, previousFocusedDocument, false); } else { - this._activeDocument = null; + this.activeDocument = null; this.application.ninja.stage.hideRulers(); this.application.ninja.stage.hideCanvas(true); @@ -524,13 +524,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.application.ninja.stage.restoreAllPanels(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.showRulers(); - } else if(currentDocument.currentView === "design" && newDocument.currentView === "code") { - this.application.ninja.stage.showCodeViewBar(true); - this.application.ninja.stage.collapseAllPanels(); - this.application.ninja.stage.hideCanvas(true); - this.application.ninja.stage.hideRulers(); } - }else if(!currentDocument && newDocument.currentView === "code"){ + } + + if(newDocument.currentView === "code") { this.application.ninja.stage.showCodeViewBar(true); this.application.ninja.stage.collapseAllPanels(); this.application.ninja.stage.hideCanvas(true); diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index dcbe0eaf..8ceb9774 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -81,7 +81,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { set : function(document) { ///// If the document is null set default stylesheets to null - if(!document) { + if(!document || document.currentView === "code") { this._activeDocument = null; this._stageStylesheet = null; this.defaultStylesheet = null; -- cgit v1.2.3 From 5914c5b2209c4b8daac4249bb76cda5c9314c4e6 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 24 May 2012 00:07:23 -0700 Subject: Cleaning up referencing to 'documentRoot' and '_document' Moved to reference new model in DOM architecture rework. This should not affect anything, just moving the references, and also the setting to the render methods in the design view. --- js/controllers/document-controller.js | 2 +- js/controllers/selection-controller.js | 6 +++--- js/controllers/styles-controller.js | 36 +++++++++++++++++----------------- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 4edcff48..f84e4da5 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -475,7 +475,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.activeDocument = doc; // Initialize the documentRoot styles - this.initializeRootStyles(doc.documentRoot); + this.initializeRootStyles(doc.model.documentRoot); // Flag to stop stylesheet dirty event this._hackInitialStyles = false; diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index 1092615a..7bef0db8 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -114,7 +114,7 @@ exports.SelectionController = Montage.create(Component, { value: function(event) { var selected = [], childNodes = [], self = this; - childNodes = this.application.ninja.currentDocument.documentRoot.childNodes; + childNodes = this.application.ninja.currentDocument.model.documentRoot.childNodes; childNodes = Array.prototype.slice.call(childNodes, 0); childNodes.forEach(function(item) { if(self.isNodeTraversable(item)) { @@ -256,10 +256,10 @@ exports.SelectionController = Montage.create(Component, { for(var i=0, uuid; this.application.ninja.selectedElements[i];i++) { // Check for multiple selection and excluding inner elements - if(item.parentNode && item.parentNode !== this.application.ninja.currentDocument.documentRoot) { + if(item.parentNode && item.parentNode !== this.application.ninja.currentDocument.model.documentRoot) { var outerElement = item.parentNode; - while(outerElement.parentNode && outerElement.parentNode !== this.application.ninja.currentDocument.documentRoot) { + while(outerElement.parentNode && outerElement.parentNode !== this.application.ninja.currentDocument.model.documentRoot) { outerElement = outerElement.parentNode; } diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index dcbe0eaf..04e87ba7 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -99,7 +99,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { // Setter will handle null case this.defaultStylesheet = this.getSheetFromElement(this.CONST.DEFAULT_SHEET_ID); - this.userStyleSheets = nj.toArray(document._document.styleSheets).filter(function(sheet) { + this.userStyleSheets = nj.toArray(document.model.views.design.document.styleSheets).filter(function(sheet) { return sheet !== this._stageStylesheet; }, this); @@ -132,7 +132,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { else if(this._activeDocument.model && this._activeDocument.model.views && this._activeDocument.model.views.design){ ///// Use the last stylesheet in the document as the default - var sheets = this._activeDocument._document.styleSheets, + var sheets = this._activeDocument.model.views.design.document.styleSheets, lastIndex = sheets.length-1; ///// If the only sheet is the stage stylesheet, this will be true @@ -887,7 +887,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { getAnimationRuleWithName : { value: function(name, document) { - var doc = document || this._activeDocument._document, + var doc = document || this._activeDocument.model.views.design.document, animRules = this.getDocumentAnimationRules(doc), rule, i; @@ -909,7 +909,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { getDocumentAnimationRules : { value: function(document) { - var sheets = (document) ? document.styleSheets : this._activeDocument._document.styleSheets, + var sheets = (document) ? document.styleSheets : this._activeDocument.model.views.design.document.styleSheets, rules = []; nj.toArray(sheets).forEach(function(sheet) { @@ -1272,7 +1272,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { createStylesheet : { value: function(id, document) { - var doc = document || this._activeDocument._document, + var doc = document || this._activeDocument.model.views.design.document, sheetElement, sheet; sheetElement = nj.make('style', { @@ -1329,7 +1329,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { getSheetFromElement : { value : function(element, context) { - var doc = context || this._activeDocument._document, + var doc = context || this._activeDocument.model.views.design.document, el = (typeof element === 'string') ? nj.$(element, doc) : element; if(el && el.sheet) { @@ -1572,7 +1572,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { getStyleTest : function() { var properties = ['background-position', 'width', 'height']; - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); properties.forEach(function(prop) { console.log('Getting value for "' + prop + '": ' + stylesController.getElementStyle(el, prop, true)); @@ -1591,7 +1591,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { }); }, getMatchingRulesTest : function() { - var el = stylesController.activeDocument._document.getElementById('Div_1'), + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'), mRules; this.addRulesTest(); @@ -1606,7 +1606,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// apply a new style using setElementStyle, and print out the new ///// value. - var el = stylesController.activeDocument._document.getElementById('Div_1'), + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'), bg; console.log('----- Set Element Style Test -----'); @@ -1631,14 +1631,14 @@ var stylesController = exports.StylesController = Montage.create(Component, { var rules = ['#UserContent div { background-color: blue }']; rules.forEach(function(rule) { stylesController.addRule(rule); }); - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); stylesController.setElementStyle(el, 'color', 'red'); ///// the #Div_1 rule created by tag tool should have the color style }, setElementStyle3Test : function() { ///// First, draw a div onto the stage - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); //// now add a multi-target rule overriding the bg color var rules = [ @@ -1655,14 +1655,14 @@ var stylesController = exports.StylesController = Montage.create(Component, { }, setGroupStyleTest : function() { ///// draw 2 divs on stage - var el1 = stylesController.activeDocument._document.getElementById('Div_1'); - var el2 = stylesController.activeDocument._document.getElementById('Div_2'); + var el1 = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); + var el2 = stylesController.activeDocument.model.views.design.document.getElementById('Div_2'); var dominantRule = stylesController.getDominantRuleForGroup([el1, el2], 'color'); }, setElementStylesTest : function() { ///// draw a div on stage - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); mRules = stylesController.getMatchingRules(el, true); mRules.forEach(function(rule) { @@ -1681,7 +1681,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { console.log('----- Create Override Rule Test -----'); - var el = stylesController.activeDocument._document.getElementById('Div_1'), + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'), rule = stylesController.addRule('#UserContent div { background-color: blue }'), override; @@ -1693,7 +1693,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { }, deleteRulesTest : function() { // drag one div on stage - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); this.addRulesTest(); mRules = stylesController.getMatchingRules(el, true); @@ -1705,8 +1705,8 @@ var stylesController = exports.StylesController = Montage.create(Component, { matchesElementsExclusivelyTest : function() { /// drag two divs on stage var rule = stylesController.addRule('#Div_1, #Div_3 { color:black; }'); - var el1 = stylesController.activeDocument._document.getElementById('Div_1'); - var el2 = stylesController.activeDocument._document.getElementById('Div_2'); + var el1 = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); + var el2 = stylesController.activeDocument.model.views.design.document.getElementById('Div_2'); console.log('Does rule match elements exclusively? ' + stylesController.matchesElementsExclusively(rule, [el1, el2])); } -- cgit v1.2.3 From 36c7e9a31e5197fee6824ffe746d715b24bcadcb Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 24 May 2012 00:25:14 -0700 Subject: Renaming variable as it will now be used This is no longer a temp fix, it might be a permanent boolean to open/close web-request API gates. --- js/controllers/document-controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index f84e4da5..c61441b7 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -22,7 +22,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: [] }, - _hackRootFlag: { + redirectRequests: { value: false }, @@ -74,7 +74,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleWebRequest: { value: function (request) { //TODO: Check if frameId is proper - if (this._hackRootFlag && request.parentFrameId !== -1) { + if (this.redirectRequests && request.parentFrameId !== -1) { //Checking for proper URL redirect (from different directories) if (request.url.indexOf('js/document/templates/banner') !== -1) { 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/banner/'))[1]}; @@ -330,7 +330,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } //Open in designer view - this._hackRootFlag = false; + this.redirectRequests = false; Montage.create(HTMLDocument).init(file, this, this._onOpenDocument, 'design', template); break; default: -- cgit v1.2.3 From d57cd68741f340a45be780675ed79b5caf2094e9 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 24 May 2012 00:43:51 -0700 Subject: Some clean up, adding comments This obviously needs much work and reworking... --- js/controllers/document-controller.js | 73 ++++++++++++----------------------- 1 file changed, 25 insertions(+), 48 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index c61441b7..eecf9146 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -13,24 +13,14 @@ var Montage = require("montage/core/core").Montage, TextDocument = require("js/document/document-text").TextDocument; //////////////////////////////////////////////////////////////////////// // -var DocumentController = exports.DocumentController = Montage.create(Component, { - hasTemplate: { - value: false - }, - - _documents: { - value: [] - }, - - redirectRequests: { - value: false - }, - - _hackInitialStyles: { - value: true - }, - +exports.DocumentController = Montage.create(Component, { + // + hasTemplate: {value: false}, + _documents: {value: []}, + //TODO: what is this?!?! + _hackInitialStyles: {value: true}, _activeDocument: { value: null }, + //TODO: Are any of these needed? _iframeCounter: { value: 1, enumerable: false }, _iframeHolder: { value: null, enumerable: false }, _textHolder: { value: null, enumerable: false }, @@ -41,7 +31,7 @@ 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; @@ -53,7 +43,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, }, deserializedFromTemplate: { - value: function() { + value: function() { //TODO: Add event naming consistency (save, fileOpen and newFile should be consistent, all file events should be executeFile[operation name]) this.eventManager.addEventListener("appLoaded", this, false); this.eventManager.addEventListener("executeFileOpen", this, false); this.eventManager.addEventListener("executeNewFile", this, false); @@ -69,6 +59,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, //TODO: Ensure these APIs are not needed + redirectRequests: { + value: false + }, //////////////////////////////////////////////////////////////////// // handleWebRequest: { @@ -151,7 +144,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // saveExecuted: { value: function (value) { - //File saved, any callbacks or events should go here + //File saved, any callbacks or events should go here (must be added in handleExecuteSave passed as callback) } }, //////////////////////////////////////////////////////////////////// @@ -161,9 +154,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, // if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ // - this.activeDocument.model.saveAll(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) + this.activeDocument.model.saveAll(); } else { - //Error: + //TODO: Add error handling } } }, @@ -183,38 +176,22 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileClose:{ value: function(event) { if (this.activeDocument) { -// this.activeDocument.closeDocument(); this.closeFile(this.activeDocument); } } }, //////////////////////////////////////////////////////////////////// + //TODO: Is this used, should be cleaned up handleExecuteFileCloseAll:{ - value: function(event) { - var i=0; - if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ - while(this._documents.length > 0){ - this.closeDocument(this._documents[this._documents.length -1].uuid); - } - } - } - }, - //////////////////////////////////////////////////////////////////// - // - fileSaveResult: { - value: function (result) { - if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved - this.activeDocument.model.needsSave = false; - if(this.application.ninja.currentDocument !== null){ - //clear Dirty StyleSheets for the saved document - this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument); - } - } - } - }, - - - + value: function(event) { + var i=0;//TODO: who is using this?? + if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ + while(this._documents.length > 0){ + this.closeDocument(this._documents[this._documents.length -1].uuid); + } + } + } + }, //////////////////////////////////////////////////////////////////// // createNewFile:{ -- cgit v1.2.3 From 209ec9524a987a8f8bc20c57e2a76ac55be15fd9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 24 May 2012 11:11:47 -0700 Subject: Fixed selection bug when switching/opening documents. Also, use saved scroll values when switching between documents. Signed-off-by: Nivesh Rajbhandari --- js/controllers/selection-controller.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index 1092615a..214b9032 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -67,10 +67,9 @@ exports.SelectionController = Montage.create(Component, { this._isDocument = true; if(currentSelectionArray) { - if(currentSelectionArray.length >= 1) { + this.application.ninja.selectedElements = currentSelectionArray; + if(currentSelectionArray.length) { this._isDocument = false; - - this.application.ninja.selectedElements = currentSelectionArray; NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); } } -- cgit v1.2.3