diff options
Diffstat (limited to 'js/controllers')
-rwxr-xr-x | js/controllers/document-controller.js | 391 | ||||
-rwxr-xr-x | js/controllers/elements/body-controller.js | 30 | ||||
-rwxr-xr-x | js/controllers/elements/component-controller.js | 4 | ||||
-rwxr-xr-x | js/controllers/elements/shapes-controller.js | 4 | ||||
-rwxr-xr-x | js/controllers/selection-controller.js | 29 | ||||
-rwxr-xr-x | js/controllers/styles-controller.js | 13 |
6 files changed, 243 insertions, 228 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index c6bf4c6b..cf46e73e 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -21,10 +21,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
21 | value: false | 21 | value: false |
22 | }, | 22 | }, |
23 | 23 | ||
24 | webTemplate: { | ||
25 | value: false | ||
26 | }, | ||
27 | |||
28 | _documents: { | 24 | _documents: { |
29 | value: [] | 25 | value: [] |
30 | }, | 26 | }, |
@@ -33,6 +29,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
33 | value: false | 29 | value: false |
34 | }, | 30 | }, |
35 | 31 | ||
32 | _hackInitialStyles: { | ||
33 | value: true | ||
34 | }, | ||
35 | |||
36 | _activeDocument: { value: null }, | 36 | _activeDocument: { value: null }, |
37 | _iframeCounter: { value: 1, enumerable: false }, | 37 | _iframeCounter: { value: 1, enumerable: false }, |
38 | _iframeHolder: { value: null, enumerable: false }, | 38 | _iframeHolder: { value: null, enumerable: false }, |
@@ -44,8 +44,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
44 | return this._activeDocument; | 44 | return this._activeDocument; |
45 | }, | 45 | }, |
46 | set: function(doc) { | 46 | set: function(doc) { |
47 | if(!!this._activeDocument){ this._activeDocument.isActive = false;} | 47 | // if(!!this._activeDocument){ this._activeDocument.isActive = false;} |
48 | |||
48 | this._activeDocument = doc; | 49 | this._activeDocument = doc; |
50 | |||
49 | if(!!this._activeDocument){ | 51 | if(!!this._activeDocument){ |
50 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); | 52 | if(this._documents.indexOf(doc) === -1) this._documents.push(doc); |
51 | this._activeDocument.isActive = true; | 53 | this._activeDocument.isActive = true; |
@@ -69,37 +71,25 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
69 | this.eventManager.addEventListener("executeFileCloseAll", this, false); | 71 | this.eventManager.addEventListener("executeFileCloseAll", this, false); |
70 | 72 | ||
71 | this.eventManager.addEventListener("styleSheetDirty", this, false); | 73 | this.eventManager.addEventListener("styleSheetDirty", this, false); |
72 | |||
73 | this.eventManager.addEventListener("addComponentFirstDraw", this, false); | ||
74 | |||
75 | // Temporary add listeners for the new stage templates | ||
76 | this.eventManager.addEventListener("executeWebpageOpen", this, false); | ||
77 | this.eventManager.addEventListener("executeNewWebpage", this, false); | ||
78 | } | 74 | } |
79 | }, | 75 | }, |
80 | 76 | ||
81 | handleAddComponentFirstDraw: { | ||
82 | value: function (e) { | ||
83 | //TODO: Add logic to reparse the document for dynamically added styles | ||
84 | //console.log(e); | ||
85 | } | ||
86 | }, | ||
87 | |||
88 | |||
89 | |||
90 | |||
91 | 77 | ||
92 | //////////////////////////////////////////////////////////////////// | 78 | //TODO: Ensure these APIs are not needed |
79 | //////////////////////////////////////////////////////////////////// | ||
93 | // | 80 | // |
94 | handleWebRequest: { | 81 | handleWebRequest: { |
95 | value: function (request) { | 82 | value: function (request) { |
96 | //TODO: Check if frameId is proper | 83 | //TODO: Check if frameId is proper |
97 | if (this._hackRootFlag && request.parentFrameId !== -1) { | 84 | if (this._hackRootFlag && request.parentFrameId !== -1) { |
98 | //TODO: Optimize creating string | 85 | //Checking for proper URL redirect (from different directories) |
99 | //console.log(request); | 86 | if (request.url.indexOf('js/document/templates/banner') !== -1) { |
100 | //console.log(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1], request.url); | 87 | 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]}; |
101 | //return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; | 88 | } else if (request.url.indexOf('js/document/templates/html') !== -1) { |
102 | 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/montage-html/'))[1]}; | 89 | 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]}; |
90 | } else { | ||
91 | //Error, not a valid folder | ||
92 | } | ||
103 | } | 93 | } |
104 | } | 94 | } |
105 | }, | 95 | }, |
@@ -140,47 +130,46 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
140 | } | 130 | } |
141 | }, | 131 | }, |
142 | 132 | ||
143 | handleExecuteWebpageOpen: { | ||
144 | value: function(event) { | ||
145 | this.webTemplate = true; | ||
146 | this.handleExecuteFileOpen(event); | ||
147 | } | ||
148 | }, | ||
149 | |||
150 | handleExecuteNewWebpage: { | ||
151 | value: function(event) { | ||
152 | this.webTemplate = true; | ||
153 | this.handleExecuteNewFile(event); | ||
154 | } | ||
155 | }, | ||
156 | |||
157 | handleExecuteNewFile: { | 133 | handleExecuteNewFile: { |
158 | value: function(event) { | 134 | value: function(event) { |
159 | var newFileSettings = event._event.settings || {}; | 135 | var newFileSettings = event._event.settings || {}; |
160 | if (this.application.ninja.coreIoApi.cloudAvailable()) { | 136 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
161 | newFileSettings.callback = this.createNewFile.bind(this); | 137 | newFileSettings.callback = this.createNewFile.bind(this); |
162 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | 138 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); |
163 | } | ||
164 | } | 139 | } |
140 | } | ||
165 | }, | 141 | }, |
166 | //////////////////////////////////////////////////////////////////// | 142 | //////////////////////////////////////////////////////////////////// |
167 | //TODO: Check for appropiate structures | 143 | // |
168 | handleExecuteSave: { | 144 | handleExecuteSave: { |
169 | value: function(event) { | 145 | value: function(event) { |
170 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 146 | // |
171 | //Text and HTML document classes should return the same save object for fileSave | 147 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
172 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | 148 | // |
173 | } | 149 | this.activeDocument.model.save(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) |
150 | } else { | ||
151 | //Error: | ||
152 | } | ||
174 | } | 153 | } |
175 | }, | 154 | }, |
155 | testCallback: { | ||
156 | value: function (value) { | ||
157 | console.log(value); | ||
158 | //TODO: Move this to the model.save() | ||
159 | this.activeDocument.model.needsSave = false; | ||
160 | } | ||
161 | }, | ||
176 | //////////////////////////////////////////////////////////////////// | 162 | //////////////////////////////////////////////////////////////////// |
177 | //TODO: Check for appropiate structures | 163 | //TODO: Check for appropiate structures |
178 | handleExecuteSaveAll: { | 164 | handleExecuteSaveAll: { |
179 | value: function(event) { | 165 | value: function(event) { |
180 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 166 | // |
181 | //Text and HTML document classes should return the same save object for fileSave | 167 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
182 | this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); | 168 | // |
183 | } | 169 | this.activeDocument.model.saveAll(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) |
170 | } else { | ||
171 | //Error: | ||
172 | } | ||
184 | } | 173 | } |
185 | }, | 174 | }, |
186 | //////////////////////////////////////////////////////////////////// | 175 | //////////////////////////////////////////////////////////////////// |
@@ -198,9 +187,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
198 | //////////////////////////////////////////////////////////////////// | 187 | //////////////////////////////////////////////////////////////////// |
199 | handleExecuteFileClose:{ | 188 | handleExecuteFileClose:{ |
200 | value: function(event) { | 189 | value: function(event) { |
201 | if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){ | 190 | if (this.activeDocument) { |
202 | this.closeDocument(this.activeDocument.uuid); | 191 | // this.activeDocument.closeDocument(); |
203 | } | 192 | this.closeFile(this.activeDocument); |
193 | } | ||
204 | } | 194 | } |
205 | }, | 195 | }, |
206 | //////////////////////////////////////////////////////////////////// | 196 | //////////////////////////////////////////////////////////////////// |
@@ -219,7 +209,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
219 | fileSaveResult: { | 209 | fileSaveResult: { |
220 | value: function (result) { | 210 | value: function (result) { |
221 | if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved | 211 | if((result.status === 204) || (result.status === 404)){//204=>existing file || 404=>new file... saved |
222 | this.activeDocument.needsSave = false; | 212 | this.activeDocument.model.needsSave = false; |
223 | if(this.application.ninja.currentDocument !== null){ | 213 | if(this.application.ninja.currentDocument !== null){ |
224 | //clear Dirty StyleSheets for the saved document | 214 | //clear Dirty StyleSheets for the saved document |
225 | this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument); | 215 | this.application.ninja.stylesController.clearDirtyStyleSheets(this.application.ninja.currentDocument); |
@@ -228,20 +218,20 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
228 | } | 218 | } |
229 | }, | 219 | }, |
230 | 220 | ||
221 | |||
222 | |||
223 | //////////////////////////////////////////////////////////////////// | ||
224 | // | ||
231 | createNewFile:{ | 225 | createNewFile:{ |
232 | value:function(newFileObj){ | 226 | value:function(newFileObj){ |
233 | // |