diff options
author | Jose Antonio Marquez | 2012-06-07 11:24:29 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-06-07 11:24:29 -0700 |
commit | 0efbbf8287517b755be1774f6aa49947bed50a0d (patch) | |
tree | 48bd340949ac558bb552b47092447d3a7b977b52 /js | |
parent | 47e0e1f047e83b71c3f86812a45d33904201cc7a (diff) | |
download | ninja-0efbbf8287517b755be1774f6aa49947bed50a0d.tar.gz |
Adding unique ID to canvas data folders
Also set up for tracking ID created, will be adding support for parsing files without saving later, but flag is now present.
Diffstat (limited to 'js')
-rwxr-xr-x | js/document/mediators/template.js | 49 | ||||
-rwxr-xr-x | js/document/models/base.js | 33 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 10 |
3 files changed, 66 insertions, 26 deletions
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index 068a1f48..c9d46f79 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js | |||
@@ -8,7 +8,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
8 | // | 8 | // |
9 | var Montage = require("montage/core/core").Montage, | 9 | var Montage = require("montage/core/core").Montage, |
10 | Component = require("montage/ui/component").Component, | 10 | Component = require("montage/ui/component").Component, |
11 | TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator; | 11 | TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator, |
12 | ClassUuid = require("js/components/core/class-uuid").ClassUuid; | ||
12 | //////////////////////////////////////////////////////////////////////// | 13 | //////////////////////////////////////////////////////////////////////// |
13 | // | 14 | // |
14 | exports.TemplateDocumentMediator = Montage.create(Component, { | 15 | exports.TemplateDocumentMediator = Montage.create(Component, { |
@@ -93,7 +94,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
93 | //////////////////////////////////////////////////////////////////// | 94 | //////////////////////////////////////////////////////////////////// |
94 | //TODO: Expand to allow more templates, clean up variables | 95 | //TODO: Expand to allow more templates, clean up variables |
95 | parseNinjaTemplateToHtml: { | 96 | parseNinjaTemplateToHtml: { |
96 | value: function (template, ninjaWrapper, libCopyCallback) { | 97 | value: function (saveExternalData, template, ninjaWrapper, libCopyCallback) { |
97 | //TODO: Improve reference for rootUrl | 98 | //TODO: Improve reference for rootUrl |
98 | var regexRootUrl, | 99 | var regexRootUrl, |
99 | rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), | 100 | rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), |
@@ -328,7 +329,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
328 | 329 | ||
329 | 330 | ||
330 | 331 | ||
331 | //TODO: Make proper webGL/Canvas method | 332 | |
332 | 333 | ||
333 | // | 334 | // |
334 | var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], | 335 | var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], |
@@ -357,19 +358,33 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
357 | } | 358 | } |
358 | } | 359 | } |
359 | } | 360 | } |
361 | |||
362 | |||
363 | |||
364 | |||
365 | //TODO: Make proper webGL/Canvas method | ||
366 | |||
367 | |||
360 | //Checking for webGL elements in document | 368 | //Checking for webGL elements in document |
361 | if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix | 369 | if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix |
362 | var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1, fileOrgDataSrc; | 370 | var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1, fileOrgDataSrc; |
363 | // | 371 | // |
364 | if (cvsDataDir && !matchingtags.length && !webgllibtag) { | 372 | if (cvsDataDir && !matchingtags.length && !webgllibtag) { |
365 | fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]; | 373 | |
374 | if (template.libs.canvasId) { | ||
375 | libsobserver.canvasId = template.libs.canvasId; | ||
376 | } else { | ||
377 | libsobserver.canvasId = ClassUuid.generate(); | ||
378 | } | ||
379 | |||
380 | //Creating data directory, will include materials at a later time | ||
381 | fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]+'_'+libsobserver.canvasId; | ||
382 | |||
366 | if (!this._getUserDirectory(fileCvsDir)) { | 383 | if (!this._getUserDirectory(fileCvsDir)) { |
367 | fileCvsDirAppend = fileCvsDir+cvsDirCounter; | 384 | //TODO: create proper logic not to overwrite files |
368 | while (!this._getUserDirectory(fileCvsDirAppend)) { | 385 | console.log('error'); |
369 | fileCvsDirAppend = fileCvsDir+(cvsDirCounter++); | ||
370 | } | ||
371 | } | 386 | } |
372 | //TODO: Allow user overwrite | 387 | |
373 | fileCvsDir += '/'; | 388 | fileCvsDir += '/'; |
374 | } else if (webgllibtag && webgllibtag.getAttribute && webgllibtag.getAttribute('data-ninja-canvas-json') !== null) { | 389 | } else if (webgllibtag && webgllibtag.getAttribute && webgllibtag.getAttribute('data-ninja-canvas-json') !== null) { |
375 | fileOrgDataSrc = template.file.root+webgllibtag.getAttribute('data-ninja-canvas-json'); | 390 | fileOrgDataSrc = template.file.root+webgllibtag.getAttribute('data-ninja-canvas-json'); |
@@ -437,17 +452,9 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
437 | //Looping through data to create escaped array | 452 | //Looping through data to create escaped array |
438 | for (var j = 0; template.webgl[j]; j++) { | 453 | for (var j = 0; template.webgl[j]; j++) { |
439 | if (j === 0) { | 454 | if (j === 0) { |
440 | //if (fileCvsDir) { | 455 | json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; |
441 | // json += '\n\t\t\t"' + template.webgl[j] + '"'; | ||
442 | //} else { | ||
443 | json += '\n\t\t\t"' + escape(template.webgl[j]) + '"'; | ||
444 | //} | ||
445 | } else { | 456 | } else { |
446 | //if (fileCvsDir) { | 457 | json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; |
447 | // json += ',\n\t\t\t"' + template.webgl[j] + '"'; | ||
448 | //} else { | ||
449 | json += ',\n\t\t\t"' + escape(template.webgl[j]) + '"'; | ||
450 | //} | ||
451 | } | 458 | } |
452 | } | 459 | } |
453 | //Closing array (make-shift JSON string to validate data in <script> tag) | 460 | //Closing array (make-shift JSON string to validate data in <script> tag) |
@@ -590,9 +597,9 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
590 | } | 597 | } |
591 | // | 598 | // |
592 | if (libsobserver.montage || libsobserver.canvas) { | 599 | if (libsobserver.montage || libsobserver.canvas) { |
593 | return {content: this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')), libs: true}; | 600 | return {content: this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')), libs: true, montageId: libsobserver.montageId, canvasId: libsobserver.canvasId}; |
594 | } else { | 601 | } else { |
595 | return {content: this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')), libs: false}; | 602 | return {content: this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')), libs: false, montageId: libsobserver.montageId, canvasId: libsobserver.canvasId}; |
596 | } | 603 | } |
597 | } | 604 | } |
598 | }, | 605 | }, |
diff --git a/js/document/models/base.js b/js/document/models/base.js index a3644815..c69c54a9 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js | |||
@@ -92,6 +92,11 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
92 | }, | 92 | }, |
93 | //////////////////////////////////////////////////////////////////// | 93 | //////////////////////////////////////////////////////////////////// |
94 | // | 94 | // |
95 | libs: { | ||
96 | value: {montage: false, canvas: false, montageId: null, canvasId: null} | ||
97 | }, | ||
98 | //////////////////////////////////////////////////////////////////// | ||
99 | // | ||
95 | switchViewTo: { | 100 | switchViewTo: { |
96 | value: function (view) { | 101 | value: function (view) { |
97 | // | 102 | // |
@@ -167,8 +172,9 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
167 | // | 172 | // |
168 | if (this.currentView === this.views.design) { | 173 | if (this.currentView === this.views.design) { |
169 | // | 174 | // |
170 | this.application.ninja.ioMediator.fileSave({ | 175 | var save = this.application.ninja.ioMediator.fileSave({ |
171 | mode: 'html', | 176 | mode: 'html', |
177 | libs: this.libs, | ||
172 | file: this.file, | 178 | file: this.file, |
173 | webgl: this.webGlHelper.glData, | 179 | webgl: this.webGlHelper.glData, |
174 | styles: this.getStyleSheets(), | 180 | styles: this.getStyleSheets(), |
@@ -178,6 +184,17 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
178 | body: this.views.design.iframe.contentWindow.document.body, | 184 | body: this.views.design.iframe.contentWindow.document.body, |
179 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator | 185 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator |
180 | }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); | 186 | }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); |
187 | //TODO: Improve detection during save routine | ||
188 | if (save) { | ||
189 | if (save.montageId) { | ||
190 | this.libs.montageId = save.montageId; | ||
191 | this.libs.montage = true; | ||
192 | } | ||
193 | if (save.canvasId) { | ||
194 | this.libs.canvasId = save.canvasId; | ||
195 | this.libs.canvas = true; | ||
196 | } | ||
197 | } | ||
181 | } else { | 198 | } else { |
182 | //TODO: Add logic to save code view data | 199 | //TODO: Add logic to save code view data |
183 | } | 200 | } |
@@ -196,8 +213,9 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
196 | // | 213 | // |
197 | if (this.currentView === this.views.design) { | 214 | if (this.currentView === this.views.design) { |
198 | // | 215 | // |
199 | this.application.ninja.ioMediator.fileSave({ | 216 | var save = this.application.ninja.ioMediator.fileSave({ |
200 | mode: 'html', | 217 | mode: 'html', |
218 | libs: this.libs, | ||
201 | file: this.file, | 219 | file: this.file, |
202 | webgl: this.webGlHelper.glData, | 220 | webgl: this.webGlHelper.glData, |
203 | css: this.getStyleSheets(), | 221 | css: this.getStyleSheets(), |
@@ -207,6 +225,17 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
207 | body: this.views.design.iframe.contentWindow.document.body, | 225 | body: this.views.design.iframe.contentWindow.document.body, |
208 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator | 226 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator |
209 | }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); | 227 | }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); |
228 | //TODO: Improve detection during save routine | ||
229 | if (save) { | ||
230 | if (save.montageId) { | ||
231 | this.libs.montageId = save.montageId; | ||
232 | this.libs.montage = true; | ||
233 | } | ||
234 | if (save.canvasId) { | ||
235 | this.libs.canvasId = save.canvasId; | ||
236 | this.libs.canvas = true; | ||
237 | } | ||
238 | } | ||
210 | } else { | 239 | } else { |
211 | //TODO: Add logic to save code view data | 240 | //TODO: Add logic to save code view data |
212 | } | 241 | } |
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index c9e10896..c487fef5 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -162,9 +162,9 @@ exports.IoMediator = Montage.create(Component, { | |||
162 | case 'html': | 162 | case 'html': |
163 | //Getting content from function to properly handle saving assets (as in external if flagged) | 163 | //Getting content from function to properly handle saving assets (as in external if flagged) |
164 | if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) { | 164 | if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) { |