diff options
Diffstat (limited to 'js/controllers')
-rwxr-xr-x | js/controllers/document-controller.js | 110 | ||||
-rwxr-xr-x | js/controllers/selection-controller.js | 11 | ||||
-rwxr-xr-x | js/controllers/styles-controller.js | 38 |
3 files changed, 72 insertions, 87 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 7758f346..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 | // |
16 | var DocumentController = exports.DocumentController = Montage.create(Component, { | 16 | exports.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: |
@@ -393,14 +371,20 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
393 | 371 | ||
394 | onCloseFile: { | 372 | onCloseFile: { |
395 | value: function(doc) { | 373 | value: function(doc) { |
374 | var previousFocusedDocument; | ||
396 | 375 | ||
397 | this._documents.splice(this._documents.indexOf(doc), 1); | 376 | this._documents.splice(this._documents.indexOf(doc), 1); |
398 | |||
399 | this._activeDocument = null; | ||
400 | 377 | ||
401 | this.application.ninja.stage.hideRulers(); | 378 | if(this._documents.length > 0) { |
379 | previousFocusedDocument = this._documents[this._documents.length - 1]; | ||
380 | this.activeDocument = previousFocusedDocument; | ||
381 | this.switchDocuments(this.activeDocument, previousFocusedDocument, false); | ||
382 | } else { | ||
383 | this.activeDocument = null; | ||
384 | this.application.ninja.stage.hideRulers(); | ||
402 | 385 | ||
403 | this.application.ninja.stage.hideCanvas(true); | 386 | this.application.ninja.stage.hideCanvas(true); |
387 | } | ||
404 | 388 | ||
405 | //TODO: Use references for those instead of calling getElementById |