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