aboutsummaryrefslogtreecommitdiff
path: root/js/document/models/base.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/models/base.js')
-rwxr-xr-xjs/document/models/base.js78
1 files changed, 54 insertions, 24 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js
index 0957145a..5fa06259 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -65,14 +65,11 @@ exports.BaseDocumentModel = Montage.create(Component, {
65 _selection: { 65 _selection: {
66 value: [] 66 value: []
67 }, 67 },
68 68 ////////////////////////////////////////////////////////////////////
69 //
69 selection: { 70 selection: {
70 get: function() { 71 get: function() {return this._selection;},
71 return this._selection; 72 set: function(value) {this._selection = value;}
72 },
73 set: function(value) {
74 this._selection = value;
75 }
76 }, 73 },
77 //////////////////////////////////////////////////////////////////// 74 ////////////////////////////////////////////////////////////////////
78 // 75 //
@@ -91,6 +88,11 @@ exports.BaseDocumentModel = Montage.create(Component, {
91 }, 88 },
92 //////////////////////////////////////////////////////////////////// 89 ////////////////////////////////////////////////////////////////////
93 // 90 //
91 libs: {
92 value: null
93 },
94 ////////////////////////////////////////////////////////////////////
95 //
94 switchViewTo: { 96 switchViewTo: {
95 value: function (view) { 97 value: function (view) {
96 // 98 //
@@ -134,20 +136,22 @@ exports.BaseDocumentModel = Montage.create(Component, {
134 } 136 }
135 }, 137 },
136 //////////////////////////////////////////////////////////////////// 138 ////////////////////////////////////////////////////////////////////
137 // 139 //Gets all stylesheets in document
138 getStyleSheets: { 140 getStyleSheets: {
139 value: function () { 141 value: function () {
140 // 142 //Array to store styles (style and link tags)
141 var styles = []; 143 var styles = [];
142 // 144 //Looping through document sytles
143 for (var k in this.views.design.iframe.contentWindow.document.styleSheets) { 145 for (var k in this.views.design.iframe.contentWindow.document.styleSheets) {
146 //Check for styles to has proper propeties
144 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) { 147 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) {
148 //Check for ninja-template styles, if so, exclude
145 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) { 149 if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) {
146 styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]); 150 styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]);
147 } 151 }
148 } 152 }
149 } 153 }
150 // 154 //Returning filtered results
151 return styles; 155 return styles;
152 } 156 }
153 }, 157 },
@@ -155,7 +159,7 @@ exports.BaseDocumentModel = Montage.create(Component, {
155 // 159 //
156 save: { 160 save: {
157 value: function (callback, libCopyCallback) { 161 value: function (callback, libCopyCallback) {
158 // 162 //TODO: Implement on demand logic
159 if (this.needsSave) { 163 if (this.needsSave) {
160 //Save 164 //Save
161 } else { 165 } else {
@@ -164,8 +168,9 @@ exports.BaseDocumentModel = Montage.create(Component, {
164 // 168 //
165 if (this.currentView === this.views.design) { 169 if (this.currentView === this.views.design) {
166 // 170 //
167 this.application.ninja.ioMediator.fileSave({ 171 var save = this.application.ninja.ioMediator.fileSave({
168 mode: 'html', 172 mode: 'html',
173 libs: this.libs,
169 file: this.file, 174 file: this.file,
170 webgl: this.webGlHelper.glData, 175 webgl: this.webGlHelper.glData,
171 styles: this.getStyleSheets(), 176 styles: this.getStyleSheets(),
@@ -175,6 +180,17 @@ exports.BaseDocumentModel = Montage.create(Component, {
175 body: this.views.design.iframe.contentWindow.document.body, 180 body: this.views.design.iframe.contentWindow.document.body,
176 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator 181 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator
177 }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); 182 }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback);
183 //TODO: Improve detection during save routine
184 if (save) {
185 if (save.montageId) {
186 this.libs.montageId = save.montageId;
187 this.libs.montage = true;
188 }
189 if (save.canvasId) {
190 this.libs.canvasId = save.canvasId;
191 this.libs.canvas = true;
192 }
193 }
178 } else { 194 } else {
179 //TODO: Add logic to save code view data 195 //TODO: Add logic to save code view data
180 } 196 }
@@ -184,7 +200,7 @@ exports.BaseDocumentModel = Montage.create(Component, {
184 // 200 //
185 saveAll: { 201 saveAll: {
186 value: function (callback, libCopyCallback) { 202 value: function (callback, libCopyCallback) {
187 // 203 //TODO: Implement on demand logic
188 if (this.needsSave) { 204 if (this.needsSave) {
189 //Save 205 //Save
190 } else { 206 } else {
@@ -193,8 +209,9 @@ exports.BaseDocumentModel = Montage.create(Component, {
193 // 209 //
194 if (this.currentView === this.views.design) { 210 if (this.currentView === this.views.design) {
195 // 211 //
196 this.application.ninja.ioMediator.fileSave({ 212 var save = this.application.ninja.ioMediator.fileSave({
197 mode: 'html', 213 mode: 'html',
214 libs: this.libs,
198 file: this.file, 215 file: this.file,
199 webgl: this.webGlHelper.glData, 216 webgl: this.webGlHelper.glData,
200 css: this.getStyleSheets(), 217 css: this.getStyleSheets(),
@@ -204,6 +221,17 @@ exports.BaseDocumentModel = Montage.create(Component, {
204 body: this.views.design.iframe.contentWindow.document.body, 221 body: this.views.design.iframe.contentWindow.document.body,
205 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator 222 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator
206 }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); 223 }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback);
224 //TODO: Improve detection during save routine
225 if (save) {
226 if (save.montageId) {
227 this.libs.montageId = save.montageId;
228 this.libs.montage = true;
229 }
230 if (save.canvasId) {
231 this.libs.canvasId = save.canvasId;
232 this.libs.canvas = true;
233 }
234 }
207 } else { 235 } else {
208 //TODO: Add logic to save code view data 236 //TODO: Add logic to save code view data
209 } 237 }
@@ -214,47 +242,49 @@ exports.BaseDocumentModel = Montage.create(Component, {
214 // 242 //
215 saveAs: { 243 saveAs: {
216 value: function (callback) { 244 value: function (callback) {
217 // 245 //TODO: Implement on demand logic
218 if (this.needsSave) { 246 if (this.needsSave) {
219 //Save current file on memory 247 //Save current file on memory
220 } else { 248 } else {
221 //Copy file from disk 249 //Copy file from disk
222 } 250 }
251 //TODO: Add functionality
223 } 252 }
224 }, 253 },
225 //////////////////////////////////////////////////////////////////// 254 ////////////////////////////////////////////////////////////////////
226 // 255 //
227 handleSaved: { 256 handleSaved: {
228 value: function (result) { 257 value: function (result) {
229 // 258 //Checking for success code in save
230 if (result.status === 204) { 259 if (result.status === 204) {
260 //Clearing flag with successful save
231 this.model.needsSave = false; 261 this.model.needsSave = false;
232 } 262 }
233 // 263 //Making callback call if specifed with results of operation
234 if (this.callback) this.callback(result); 264 if (this.callback) this.callback(result);
235 } 265 }
236 }, 266 },
237 //////////////////////////////////////////////////////////////////// 267 ////////////////////////////////////////////////////////////////////
238 // 268 //TODO: Implement better logic to include different views on single document
239 close: { 269 close: {
240 value: function (view, callback) { 270 value: function (view, callback) {
241 //Outcome of close (pending on save logic) 271 //Outcome of close (pending on save logic)
242 var success; 272 var success;
243 // 273 //
244 if (this.needsSave) { 274 if (this.needsSave) {
245 //Prompt user to save of lose data 275 //TODO: Prompt user to save or lose data
246 } else { 276 } else {
247 //Close file 277 //Close file
248 success = true; 278 success = true;
249 } 279 }
250 // 280 //Checking for view mode to close
251 if (this.views.design && (!view || view === 'design')) { 281 if (this.views.design && (!view || view === 'design')) {
252 // 282 //TODO: Create a destroy method, this is messy
283 this.views.design.pauseAndStopVideos();
253 this.parentContainer.removeChild(this.views.design.iframe); 284 this.parentContainer.removeChild(this.views.design.iframe);
254 this.views.design.pauseAndStopVideos();
255 this.views.design = null; 285 this.views.design = null;
256 } 286 }
257 // 287 //Returning result of operation<