diff options
Diffstat (limited to 'js/document/mediators')
-rwxr-xr-x | js/document/mediators/template.js | 49 |
1 files changed, 28 insertions, 21 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 | }, |