aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-06-04 11:58:53 -0700
committerJose Antonio Marquez2012-06-04 11:58:53 -0700
commit3f9cbffd7986cc5f42720ba38ca82c6424ba8916 (patch)
tree43e4bad7f1daf19b63ae227e82d7e8df376fc2dd /js
parentb6c6c194d4768cf03adee55e8ebe53428cbea2a1 (diff)
downloadninja-3f9cbffd7986cc5f42720ba38ca82c6424ba8916.tar.gz
Adding lib copy blocking to preview
This fixes an issue with launching preview before libraries were copied, hence, first time run would fail. Need to add a feedback screen for this process.
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/mediators/template.js50
-rwxr-xr-xjs/document/models/base.js10
-rw-r--r--js/mediators/io-mediator.js41
3 files changed, 73 insertions, 28 deletions
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js
index 1aac7e15..17fa553c 100755
--- a/js/document/mediators/template.js
+++ b/js/document/mediators/template.js
@@ -93,7 +93,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
93 //////////////////////////////////////////////////////////////////// 93 ////////////////////////////////////////////////////////////////////
94 //TODO: Expand to allow more templates, clean up variables 94 //TODO: Expand to allow more templates, clean up variables
95 parseNinjaTemplateToHtml: { 95 parseNinjaTemplateToHtml: {
96 value: function (template, ninjaWrapper) { 96 value: function (template, ninjaWrapper, libCopyCallback) {
97 //TODO: Improve reference for rootUrl 97 //TODO: Improve reference for rootUrl
98 var regexRootUrl, 98 var regexRootUrl,
99 rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), 99 rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])),
@@ -332,7 +332,9 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
332 332
333 // 333 //
334 var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], 334 var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [],
335 scripts = template.file.content.document.getElementsByTagName('script'); 335 scripts = template.file.content.document.getElementsByTagName('script'),
336 libsobserver = {montage: false, canvas: false, montageCopied: null, canvasCopied: null, callback: libCopyCallback, dispatched: false};
337
336 // 338 //
337 for (var i in scripts) { 339 for (var i in scripts) {
338 if (scripts[i].getAttribute) { 340 if (scripts[i].getAttribute) {
@@ -376,7 +378,8 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
376 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { 378 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
377 rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); 379 rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
378 rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; 380 rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
379 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, rdgeDirName, function(result) {console.log(result)}); 381 libsobserver.canvas = true;
382 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, rdgeDirName, function(result) {libsobserver.canvasCopied = result; this.libCopied(libsobserver);}.bind(this));
380 } else { 383 } else {
381 //TODO: Error handle no available library to copy 384 //TODO: Error handle no available library to copy
382 } 385 }
@@ -502,7 +505,8 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
502 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { 505 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
503 mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); 506 mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
504 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; 507 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
505 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName, function(result) {console.log(result)}); 508 libsobserver.montage = true;
509 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName, function(result) {libsobserver.montageCopied = result; this.libCopied(libsobserver);}.bind(this));
506 510
507 511
508 512
@@ -590,6 +594,44 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
590 }, 594 },
591 //////////////////////////////////////////////////////////////////// 595 ////////////////////////////////////////////////////////////////////
592 // 596 //
597 libCopied: {
598 value: function (observer) {
599 if (observer.montage && observer.canvas) {
600 //
601 if (observer.montageCopied && observer.canvasCopied) {
602 if (observer.callback && !observer.dispatched) observer.callback(true);
603 observer.dispatched = true;
604 } else if (observer.montageCopied === false || observer.canvasCopied === false) {
605 if (observer.callback && !observer.dispatched) observer.callback(false);
606 observer.dispatched = true;
607 }
608 } else if (observer.montage) {
609 //
610 if (observer.montageCopied) {
611 if (observer.callback && !observer.dispatched) observer.callback(true);
612 observer.dispatched = true;
613 } else {
614 if (observer.callback && !observer.dispatched) observer.callback(false);
615 observer.dispatched = true;
616 }
617 } else if (observer.canvas && observer.canvasCopied) {
618 //
619 if (observer.canvasCopied) {
620 if (observer.callback && !observer.dispatched) observer.callback(true);
621 observer.dispatched = true;
622 } else {
623 if (observer.callback && !observer.dispatched) observer.callback(false);
624 observer.dispatched = true;
625 }
626 } else {
627 //Error
628 if (observer.callback && !observer.dispatched) observer.callback(false);
629 observer.dispatched = true;
630 }
631 }
632 },
633 ////////////////////////////////////////////////////////////////////
634 //
593 getUrlfromNinjaUrl: { 635 getUrlfromNinjaUrl: {
594 enumerable: false, 636 enumerable: false,
595 value: function (url, fileRootUrl, fileUrl) { 637 value: function (url, fileRootUrl, fileUrl) {
diff --git a/js/document/models/base.js b/js/document/models/base.js
index 76a5e62b..27f7d43f 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -103,7 +103,7 @@ exports.BaseDocumentModel = Montage.create(Component, {
103 //Generating URL for document 103 //Generating URL for document
104 var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; 104 var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1];
105 //TODO: Add logic to prompt user to save (all) before preview 105 //TODO: Add logic to prompt user to save (all) before preview
106 this.saveAll(function (result) { 106 this.saveAll(null,function (result) {
107 //Currently only supporting current browser (Chrome, obviously) 107 //Currently only supporting current browser (Chrome, obviously)
108 switch (this.browser) { 108 switch (this.browser) {
109 case 'chrome': 109 case 'chrome':
@@ -145,7 +145,7 @@ exports.BaseDocumentModel = Montage.create(Component, {
145 //////////////////////////////////////////////////////////////////// 145 ////////////////////////////////////////////////////////////////////
146 // 146 //
147 save: { 147 save: {
148 value: function (callback) { 148 value: function (callback, libCopyCallback) {
149 // 149 //
150 if (this.needsSave) { 150 if (this.needsSave) {
151 //Save 151 //Save
@@ -165,7 +165,7 @@ exports.BaseDocumentModel = Montage.create(Component, {
165 head: this.views.design.iframe.contentWindow.document.head, 165 head: this.views.design.iframe.contentWindow.document.head,
166 body: this.views.design.iframe.contentWindow.document.body, 166 body: this.views.design.iframe.contentWindow.document.body,
167 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator 167 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator
168 }, this.handleSaved.bind({callback: callback, model: this})); 168 }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback);
169 } else { 169 } else {
170 //TODO: Add logic to save code view data 170 //TODO: Add logic to save code view data
171 } 171 }
@@ -174,7 +174,7 @@ exports.BaseDocumentModel = Montage.create(Component, {
174 //////////////////////////////////////////////////////////////////// 174 ////////////////////////////////////////////////////////////////////
175 // 175 //
176 saveAll: { 176 saveAll: {
177 value: function (callback) { 177 value: function (callback, libCopyCallback) {
178 // 178 //
179 if (this.needsSave) { 179 if (this.needsSave) {
180 //Save 180 //Save
@@ -194,7 +194,7 @@ exports.BaseDocumentModel = Montage.create(Component, {
194 head: this.views.design.iframe.contentWindow.document.head, 194 head: this.views.design.iframe.contentWindow.document.head,
195 body: this.views.design.iframe.contentWindow.document.body, 195 body: this.views.design.iframe.contentWindow.document.body,
196 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator 196 mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator
197 }, this.handleSaved.bind({callback: callback, model: this})); 197 }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback);
198 } else { 198 } else {
199 //TODO: Add logic to save code view data 199 //TODO: Add logic to save code view data
200 } 200 }
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 4535cad6..c5ec951e 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -43,6 +43,24 @@ exports.IoMediator = Montage.create(Component, {
43 }, 43 },
44 //////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////
45 // 45 //
46 parseToTemplate: {
47 value: function(content, template) {
48 //
49 if (template.name.toLowerCase() === 'banner' || template.name.toLowerCase() === 'animation') {
50 //Getting dimensions of banner
51 var dimensions = template.id.split('x');
52 dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'};
53 //
54 content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id);
55 content = content.replace(/ninja-banner {}/gi, "ninja-banner {overflow: visible; width: "+dimensions.width+"; height: "+dimensions.height+"}");
56 content = content.replace(/ninja-content-wrapper {}/gi, "ninja-content-wrapper {overflow: hidden; width: "+dimensions.width+"; height: "+dimensions.height+"}");
57 }
58 //
59 return content;
60 }
61 },
62 ////////////////////////////////////////////////////////////////////
63 //
46 fileNew: { 64 fileNew: {
47 value: function (file, url, callback, template) { 65 value: function (file, url, callback, template) {
48 //Loading template from template URL 66 //Loading template from template URL
@@ -51,7 +69,7 @@ exports.IoMediator = Montage.create(Component, {
51 xhr.send(); 69 xhr.send();
52 if (xhr.readyState === 4) { 70 if (xhr.readyState === 4) {
53 //Making call to create file, checking for return code 71 //Making call to create file, checking for return code
54 switch (this.fio.newFile({ uri: file, contents: parseTemplate(xhr.response, template) })) { 72 switch (this.fio.newFile({ uri: file, contents: this.parseToTemplate(xhr.response, template) })) {
55 case 201: 73 case 201:
56 result = { status: 201, success: true, uri: file }; 74 result = { status: 201, success: true, uri: file };
57 break; 75 break;
@@ -65,21 +83,6 @@ exports.IoMediator = Montage.create(Component, {
65 result = { status: 500, success: false, uri: file }; 83 result = { status: 500, success: false, uri: file };
66 break; 84 break;
67 } 85 }
68 //TODO: Improve template data injection
69 function parseTemplate (content, template) {
70 //
71 if (template.name.toLowerCase() === 'banner' || template.name.toLowerCase() === 'animation') {
72 //Getting dimensions of banner
73