aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/document-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-xjs/controllers/document-controller.js97
1 files changed, 36 insertions, 61 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 3e15511d..2c34eedf 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -13,24 +13,14 @@ var Montage = require("montage/core/core").Montage,
13 TextDocument = require("js/document/document-text").TextDocument; 13 TextDocument = require("js/document/document-text").TextDocument;
14//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
15// 15//
16var DocumentController = exports.DocumentController = Montage.create(Component, { 16exports.DocumentController = Montage.create(Component, {
17 hasTemplate: { 17 //
18 value: false 18 hasTemplate: {value: false},
19 }, 19 _documents: {value: []},
20 20 //TODO: what is this?!?!
21 _documents: { 21 _hackInitialStyles: {value: true},
22 value: []
23 },
24
25 _hackRootFlag: {
26 value: false
27 },
28
29 _hackInitialStyles: {
30 value: true
31 },
32
33 _activeDocument: { value: null }, 22 _activeDocument: { value: null },
23 //TODO: Are any of these needed?
34 _iframeCounter: { value: 1, enumerable: false }, 24 _iframeCounter: { value: 1, enumerable: false },
35 _iframeHolder: { value: null, enumerable: false }, 25 _iframeHolder: { value: null, enumerable: false },
36 _textHolder: { value: null, enumerable: false }, 26 _textHolder: { value: null, enumerable: false },
@@ -41,7 +31,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
41 return this._activeDocument; 31 return this._activeDocument;
42 }, 32 },
43 set: function(doc) { 33 set: function(doc) {
44// if(!!this._activeDocument){ this._activeDocument.isActive = false;} 34 //if(!!this._activeDocument){ this._activeDocument.isActive = false;}
45 35
46 this._activeDocument = doc; 36 this._activeDocument = doc;
47 37
@@ -53,7 +43,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
53 }, 43 },
54 44
55 deserializedFromTemplate: { 45 deserializedFromTemplate: {
56 value: function() { 46 value: function() { //TODO: Add event naming consistency (save, fileOpen and newFile should be consistent, all file events should be executeFile[operation name])
57 this.eventManager.addEventListener("appLoaded", this, false); 47 this.eventManager.addEventListener("appLoaded", this, false);
58 this.eventManager.addEventListener("executeFileOpen", this, false); 48 this.eventManager.addEventListener("executeFileOpen", this, false);
59 this.eventManager.addEventListener("executeNewFile", this, false); 49 this.eventManager.addEventListener("executeNewFile", this, false);
@@ -69,17 +59,22 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
69 59
70 60
71 //TODO: Ensure these APIs are not needed 61 //TODO: Ensure these APIs are not needed
62 redirectRequests: {
63 value: false
64 },
72 //////////////////////////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////////////
73 // 66 //
74 handleWebRequest: { 67 handleWebRequest: {
75 value: function (request) { 68 value: function (request) {
76 //TODO: Check if frameId is proper 69 //TODO: Check if frameId is proper
77 if (this._hackRootFlag && request.parentFrameId !== -1) { 70 if (this.redirectRequests && request.parentFrameId !== -1) {
78 //Checking for proper URL redirect (from different directories) 71 //Checking for proper URL redirect (from different directories)
79 if (request.url.indexOf('js/document/templates/banner') !== -1) { 72 if (request.url.indexOf('js/document/templates/banner') !== -1) {
80 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]}; 73 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]};
81 } else if (request.url.indexOf('js/document/templates/html') !== -1) { 74 } else if (request.url.indexOf('js/document/templates/html') !== -1) {
82 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]}; 75 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]};
76 } else if (request.url.indexOf('js/document/templates/app') !== -1) {
77 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]};
83 } else { 78 } else {
84 //Error, not a valid folder 79 //Error, not a valid folder
85 } 80 }
@@ -103,7 +98,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
103 }, 98 },
104 //////////////////////////////////////////////////////////////////// 99 ////////////////////////////////////////////////////////////////////
105 100
106
107 101
108 102
109 103
@@ -150,7 +144,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
150 // 144 //
151 saveExecuted: { 145 saveExecuted: {
152 value: function (value) { 146 value: function (value) {
153 //File saved, any callbacks or events should go here 147 //File saved, any callbacks or events should go here (must be added in handleExecuteSave passed as callback)
154 } 148 }
155 }, 149 },
156 //////////////////////////////////////////////////////////////////// 150 ////////////////////////////////////////////////////////////////////
@@ -160,9 +154,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
160 // 154 //
161 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ 155 if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){
162 // 156 //
163 this.activeDocument.model.saveAll(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) 157 this.activeDocument.model.saveAll();
164 } else { 158 } else {
165 //Error: 159 //TODO: Add error handling
166 } 160 }
167 } 161 }
168 }, 162 },
@@ -182,38 +176,22 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
182 handleExecuteFileClose:{ 176 handleExecuteFileClose:{
183 value: function(event) { 177 value: function(event) {
184 if (this.activeDocument) { 178 if (this.activeDocument) {
185// this.activeDocument.closeDocument();
186 this.closeFile(this.activeDocument); 179 this.closeFile(this.activeDocument);
187 } 180 }
188 } 181 }
189 }, 182 },
190 //////////////////////////////////////////////////////////////////// 183 ////////////////////////////////////////////////////////////////////
184 //TODO: Is this used, should be cleaned up
191 handleExecuteFileCloseAll:{ 185 handleExecuteFileCloseAll:{
192 value: function(event) { 186 value: function(event) {
193 var i=0; 187 var i=0;//TODO: who is using this??
194 if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ 188 if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
195 while(this._documents.length > 0){ 189 while(this._documents.length > 0){
196 this.closeDocument(this._documents[this._documents.length -1].uuid); 190 this.closeDocument(this._documents[this._documents.length -1].uuid);
197 } 191 }
198 } 192 }
199 } 193 }
200 }, 194 },
201 ////////////////////////////////////////////////////////////////////
202 //
203 fileSaveResult: {
204 value: function (result) {
205 if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved
206 this.activeDocument.model.needsSave = false;
207 if(this.application.ninja.currentDocument !== null){
208 //clear Dirty StyleSheets for the saved document
209 this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument);
210 }
211 }
212 }
213 },
214
215
216
217 //////////////////////////////////////////////////////////////////// 195 ////////////////////////////////////////////////////////////////////
218 // 196 //
219 createNewFile:{ 197 createNewFile:{
@@ -329,7 +307,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
329 } 307 }
330 308
331 //Open in designer view 309 //Open in designer view
332 this._hackRootFlag = false; 310 this.redirectRequests = false;
333 Montage.create(HTMLDocument).init(file, this, this._onOpenDocument, 'design', template); 311 Montage.create(HTMLDocument).init(file, this, this._onOpenDocument, 'design', template);
334 break; 312 break;
335 default: 313 default:
@@ -399,10 +377,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
399 377
400 if(this._documents.length > 0) { 378 if(this._documents.length > 0) {
401 previousFocusedDocument = this._documents[this._documents.length - 1]; 379 previousFocusedDocument = this._documents[this._documents.length - 1];
402 this._activeDocument = previousFocusedDocument; 380 this.activeDocument = previousFocusedDocument;
403 this.switchDocuments(this.activeDocument, previousFocusedDocument, true); 381 this.switchDocuments(this.activeDocument, previousFocusedDocument, false);
404 } else { 382 } else {
405 this._activeDocument = null; 383 this.activeDocument = null;
406 this.application.ninja.stage.hideRulers(); 384 this.application.ninja.stage.hideRulers();
407 385
408 this.application.ninja.stage.hideCanvas(true); 386 this.application.ninja.stage.hideCanvas(true);
@@ -474,7 +452,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
474 this.activeDocument = doc; 452 this.activeDocument = doc;
475 453
476 // Initialize the documentRoot styles 454 // Initialize the documentRoot styles
477 this.initializeRootStyles(doc.documentRoot); 455 this.initializeRootStyles(doc.model.documentRoot);
478 // Flag to stop stylesheet dirty event 456 // Flag to stop stylesheet dirty event
479 this._hackInitialStyles = false; 457 this._hackInitialStyles = false;
480 458
@@ -524,13 +502,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
524 this.application.ninja.stage.restoreAllPanels(); 502 this.application.ninja.stage.restoreAllPanels();