diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/controllers/document-controller.js | 73 |
1 files changed, 25 insertions, 48 deletions
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, | |||
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 | redirectRequests: { | ||
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,6 +59,9 @@ 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: { |
@@ -151,7 +144,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
151 | // | 144 | // |
152 | saveExecuted: { | 145 | saveExecuted: { |
153 | value: function (value) { | 146 | value: function (value) { |
154 | //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) |
155 | } | 148 | } |
156 | }, | 149 | }, |
157 | //////////////////////////////////////////////////////////////////// | 150 | //////////////////////////////////////////////////////////////////// |
@@ -161,9 +154,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
161 | // | 154 | // |
162 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 155 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
163 | // | 156 | // |
164 | this.activeDocument.model.saveAll(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) | 157 | this.activeDocument.model.saveAll(); |
165 | } else { | 158 | } else { |
166 | //Error: | 159 | //TODO: Add error handling |
167 | } | 160 | } |
168 | } | 161 | } |
169 | }, | 162 | }, |
@@ -183,38 +176,22 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
183 | handleExecuteFileClose:{ | 176 | handleExecuteFileClose:{ |
184 | value: function(event) { | 177 | value: function(event) { |
185 | if (this.activeDocument) { | 178 | if (this.activeDocument) { |
186 | // this.activeDocument.closeDocument(); | ||
187 | this.closeFile(this.activeDocument); | 179 | this.closeFile(this.activeDocument); |
188 | } | 180 | } |
189 | } | 181 | } |
190 | }, | 182 | }, |
191 | //////////////////////////////////////////////////////////////////// | 183 | //////////////////////////////////////////////////////////////////// |
184 | //TODO: Is this used, should be cleaned up | ||
192 | handleExecuteFileCloseAll:{ | 185 | handleExecuteFileCloseAll:{ |
193 | value: function(event) { | 186 | value: function(event) { |
194 | var i=0; | 187 | var i=0;//TODO: who is using this?? |
195 | if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ | 188 | if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ |
196 | while(this._documents.length > 0){ | 189 | while(this._documents.length > 0){ |
197 | this.closeDocument(this._documents[this._documents.length -1].uuid); | 190 | this.closeDocument(this._documents[this._documents.length -1].uuid); |
198 | } | 191 | } |
199 | } | 192 | } |
200 | } | 193 | } |
201 | }, | 194 | }, |
202 | //////////////////////////////////////////////////////////////////// | ||
203 | // | ||
204 | fileSaveResult: { | ||
205 | value: function (result) { | ||
206 | if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved | ||
207 | this.activeDocument.model.needsSave = false; | ||
208 | if(this.application.ninja.currentDocument !== null){ | ||
209 | //clear Dirty StyleSheets for the saved document | ||
210 | this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument); | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | }, | ||
215 | |||
216 | |||
217 | |||
218 | //////////////////////////////////////////////////////////////////// | 195 | //////////////////////////////////////////////////////////////////// |
219 | // | 196 | // |
220 | createNewFile:{ | 197 | createNewFile:{ |