aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/mediators/template.js7
-rw-r--r--js/io/system/ninjalibrary.js42
2 files changed, 32 insertions, 17 deletions
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js
index aa23c00f..1aac7e15 100755
--- a/js/document/mediators/template.js
+++ b/js/document/mediators/template.js
@@ -331,7 +331,8 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
331 //TODO: Make proper webGL/Canvas method 331 //TODO: Make proper webGL/Canvas method
332 332
333 // 333 //
334 var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag; 334 var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [],
335 scripts = template.file.content.document.getElementsByTagName('script');
335 // 336 //
336 for (var i in scripts) { 337 for (var i in scripts) {
337 if (scripts[i].getAttribute) { 338 if (scripts[i].getAttribute) {
@@ -375,7 +376,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
375 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { 376 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
376 rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); 377 rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
377 rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; 378 rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
378 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, rdgeDirName); 379 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, rdgeDirName, function(result) {console.log(result)});
379 } else { 380 } else {
380 //TODO: Error handle no available library to copy 381 //TODO: Error handle no available library to copy
381 } 382 }
@@ -501,7 +502,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
501 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { 502 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
502 mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); 503 mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
503 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; 504 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
504 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName); 505 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName, function(result) {console.log(result)});
505 506
506 507
507 508
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
index 12af5988..0470a166 100644
--- a/js/io/system/ninjalibrary.js
+++ b/js/io/system/ninjalibrary.js
@@ -57,35 +57,38 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
57 // 57 //
58 copyLibToCloud: { 58 copyLibToCloud: {
59 value: function (path, libName, callback) { 59 value: function (path, libName, callback) {
60 var libCheck = this.coreApi.directoryExists({uri: path+libName});
60 //Checking for library to exists 61 //Checking for library to exists
61 if(this.coreApi.directoryExists({uri: path+libName}).status === 404) { 62 if(libCheck.status === 404) {
62 //Getting contents to begin copying 63 //Getting contents to begin copying
63 this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { 64 this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) {
64 for (var i in contents) { 65 for (var i in contents) {
65 if (libName === contents[i].name) { 66 if (libName === contents[i].name) {
66 //Getting contents of library to be copied 67 //Getting contents of library to be copied
67 this.chromeApi.directoryContents(contents[i], function (lib) { 68 this.chromeApi.directoryContents(contents[i], function (lib) {
68 //Copying to cloud, adding blocking if no callback specified 69 //Copying to cloud
69 if (!callback) { 70 if (callback) {
70 //TODO: Add blocking logic here 71 this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0, callback: callback.bind(this)});
71 this.copyDirectoryToCloud(path, contents[i], path); 72 } else {
72 } else { 73 this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0});
73 this.copyDirectoryToCloud(path, contents[i], path, callback); 74 }
74 }
75 }.bind(this)); 75 }.bind(this));
76 break; 76 break;
77 } 77 }
78 } 78 }
79 }.bind(this)); 79 }.bind(this));
80 } else if (libCheck.status === 204){
81 //Already present, so sending success
82 if (callback) callback(true);
80 } else { 83 } else {
81 //TODO: Add error handling 84 if (callback) callback(false);
82 } 85 }
83 } 86 }
84 }, 87 },
85 //////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////
86 // 89 //
87 copyDirectoryToCloud: { 90 copyDirectoryToCloud: {
88 value: function(root, folder, fileRoot, callback) { 91 value: function(root, folder, fileRoot, tracking) {
89 //Setting up directory name 92 //Setting up directory name
90 if (folder.name) { 93 if (folder.name) {
91 var dir; 94 var dir;
@@ -109,19 +112,30 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
109 //Checking for file or directory 112 //Checking for file or directory
110 if (contents[i].isDirectory) { 113 if (contents[i].isDirectory) {
111 //Recursive call if directory 114 //Recursive call if directory
112 this.copyDirectoryToCloud(dir, contents[i], fileRoot); 115 this.copyDirectoryToCloud(dir, contents[i], fileRoot, tracking);
113 } else if (contents[i].isFile){ 116 } else if (contents[i].isFile){
117 //
118 tracking.total++;
114 //Copying file 119 //Copying file
115 this.chromeApi.fileContent(contents[i].fullPath, function (result) { 120 this.chromeApi.fileContent(contents[i].fullPath, function (result) {
116 //Using binary when copying files to allow images and such to work 121 //Using binary when copying files to allow images and such to work
117 this.coreApi.createFile({uri: (fileRoot+result.file.fullPath).replace(/\/\//gi, '/'), contents: result.content}); 122 var file = this.coreApi.createFile({uri: (fileRoot+result.file.fullPath).replace(/\/\//gi, '/'), contents: result.content});
123 //Checking for file copy success
124 if (file.status === 201) {
125 tracking.copied++;
126 } else {
127 //Error
128 tracking.callback(false);
129 }
130 //Checking for all files to be copied to make callback
131 if (tracking.copied === tracking.total && tracking.callback) {
132 tracking.callback(true);
133 }
118 }.bind(this)); 134 }.bind(this));
119 } 135 }
120 } 136 }
121 }.bind(this)); 137 }.bind(this));
122 } 138 }
123 //TODO Add logic for proper callback status(es)
124 if (callback) callback(true);
125 } 139 }
126 }, 140 },
127 //////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////