aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/io/system/coreioapi.js20
-rw-r--r--js/io/system/ninjalibrary.js69
2 files changed, 78 insertions, 11 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js
index 9836f33f..005eabf2 100755
--- a/js/io/system/coreioapi.js
+++ b/js/io/system/coreioapi.js
@@ -58,9 +58,9 @@ exports.CoreIoApi = Montage.create(Component, {
58 handleReady: { 58 handleReady: {
59 enumerable: false, 59 enumerable: false,
60 value: function (e) { 60 value: function (e) {
61 // 61 //Removing events
62 this.chromeFileSystem.removeEventListener('ready', this, false); 62 this.chromeFileSystem.removeEventListener('ready', this, false);
63 // 63 //Listening for library to be copied event (builds list)
64 this.chromeFileSystem.addEventListener('library', this, false); 64 this.chromeFileSystem.addEventListener('library', this, false);
65 } 65 }
66 }, 66 },
@@ -71,10 +71,24 @@ exports.CoreIoApi = Montage.create(Component, {
71 value: function (e) { 71 value: function (e) {
72 //Removing events 72 //Removing events
73 this.chromeFileSystem.removeEventListener('library', this, false); 73 this.chromeFileSystem.removeEventListener('library', this, false);
74 // 74 //Listening for synced library event
75 this.ninjaLibrary.addEventListener('sync', this, false);
76 //Sending library to be synced to chrome
75 this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem); 77 this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem);
78
76 } 79 }
77 }, 80 },
81 ////////////////////////////////////////////////////////////////////
82 //
83 handleSync: {
84 enumerable: false,
85 value: function (e) {
86 //Removing events
87 console.log('Ninja Local Library: Ready');
88 this.ninjaLibrary.removeEventListener('sync', this, false);
89 //TODO: Add sync loading screen logic
90 }
91 },
78 //////////////////////////////////////////////////////////////////// 92 ////////////////////////////////////////////////////////////////////
79 // 93 //
80 _chromeNinjaLibrary: { 94 _chromeNinjaLibrary: {
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
index 658ce589..fa2e7d1f 100644
--- a/js/io/system/ninjalibrary.js
+++ b/js/io/system/ninjalibrary.js
@@ -34,6 +34,18 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
34 this._chromeApi = value; 34 this._chromeApi = value;
35 } 35 }
36 }, 36 },
37 ////////////////////////////////////////////////////////////////////
38 //
39 _libsToSync: {
40 enumerable: false,
41 value: 0
42 },
43 ////////////////////////////////////////////////////////////////////
44 //
45 _syncedLibs: {
46 enumerable: false,
47 value: 0
48 },
37 //////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////
38 // 50 //
39 synchronize: { 51 synchronize: {
@@ -42,7 +54,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
42 // 54 //
43 this.chromeApi = chrome; 55 this.chromeApi = chrome;
44 // 56 //
45 var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; 57 var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = [], copied;
46 //Getting known json list of libraries to copy to chrome 58 //Getting known json list of libraries to copy to chrome
47 xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); 59 xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false);
48 xhr.send(); 60 xhr.send();
@@ -52,10 +64,27 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
52 libs = JSON.parse(xhr.response); 64 libs = JSON.parse(xhr.response);
53 // 65 //
54 if (chromeLibs.length > 0) { 66 if (chromeLibs.length > 0) {
55 //TODO: Remove 67 //
56 for (i=0; chromeLibs[i]; i++) { 68 for (i=0; chromeLibs[i]; i++) {
57 this.chromeApi.directoryDelete(chromeLibs[i]); 69 copied = false;
70 for (var j in libs.libraries) {
71 if (String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase() === chromeLibs[i]) {
72 copied = true;
73 }
74 }
75 //
76 if (!copied) {
77 if (libs.libraries[j].file) {
78 tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file});
79 } else {
80 tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path});
81 }
82 } else {
83 //TODO: Remove, currently manually removing copied libraries
84 this.chromeApi.directoryDelete(chromeLibs[i]);
85 }
58 } 86 }
87
59 } else { 88 } else {
60 //No library is present, must copy all 89 //No library is present, must copy all
61 for (var j in libs.libraries) { 90 for (var j in libs.libraries) {
@@ -70,6 +99,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
70 } 99 }
71 } 100 }
72 // 101 //
102 this._libsToSync = tocopylibs.length;
103 //
73 if (tocopylibs.length > 0) { 104 if (tocopylibs.length > 0) {
74 for (i=0; tocopylibs[i]; i++) { 105 for (i=0; tocopylibs[i]; i++) {
75 //Checking for library to be single file 106 //Checking for library to be single file
@@ -83,7 +114,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
83 //Checking for status 114 //Checking for status
84 if (xhr.readyState === 4) { //TODO: add check for mime type 115 if (xhr.readyState === 4) { //TODO: add check for mime type
85 //Creating new file from loaded content 116 //Creating new file from loaded content
86 this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response); 117 this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this));
87 } else { 118 } else {
88 //Error creating single file library 119 //Error creating single file library
89 } 120 }
@@ -104,8 +135,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
104 libjson.dirsCreated = 0; 135 libjson.dirsCreated = 0;
105 libjson.filesToCreate = libjson.files.length; 136 libjson.filesToCreate = libjson.files.length;
106 libjson.filesCreated = 0; 137 libjson.filesCreated = 0;
107 libjson.api = this.chromeApi;
108 libjson.local = tocopylibs[i].name; 138 libjson.local = tocopylibs[i].name;
139 libjson.main = this;
109 this.createDirectory(tocopylibs[i].name, libjson.directories[l], function (status) { 140 this.createDirectory(tocopylibs[i].name, libjson.directories[l], function (status) {
110 //Checking for success on directories created 141 //Checking for success on directories created
111 if (status) { 142 if (status) {
@@ -120,12 +151,12 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
120 xhr.send(); 151 xhr.send();
121 //Checking for status 152 //Checking for status
122 if (xhr.readyState === 4) { 153 if (xhr.readyState === 4) {
123 this.api.fileNew(this.local+'/'+this.files[i], xhr.response, function (status) { 154 this.main.chromeApi.fileNew(this.local+'/'+this.files[i], xhr.response, function (status) {
124 if (status) { 155 if (status) {
125 this.filesCreated++; 156 this.filesCreated++;
126 } 157 }
127 if (this.filesCreated === this.filesToCreate) { 158 if (this.filesCreated === this.filesToCreate) {
128 //TODO: Add logic for task completed 159 this.main.libraryCopied();
129 } 160 }
130 }.bind(this)); 161 }.bind(this));
131 } 162 }
@@ -139,7 +170,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
139 } 170 }
140 } 171 }
141 } else { 172 } else {
142 //No libraries to copy 173 //Dispatching ready event since nothing to copy
174 this._dispatchEvent();
143 } 175 }
144 } else { 176 } else {
145 //Error 177 //Error
@@ -172,6 +204,27 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
172 } 204 }
173 } 205 }
174 } 206 }
207 },
208 ////////////////////////////////////////////////////////////////////
209 //
210 libraryCopied: {
211 enumerable: true,
212 value: function() {
213 this._syncedLibs++;
214 if (this._syncedLibs === this._libsToSync) {
215 this._dispatchEvent();
216 }
217 }
218 },
219 ////////////////////////////////////////////////////////////////////
220 //
221 _dispatchEvent: {
222 enumerable: true,
223 value: function () {
224 var syncEvent = document.createEvent("CustomEvent");
225 syncEvent.initEvent('sync', true, true);
226 this.dispatchEvent(syncEvent);
227 }
175 } 228 }
176 //////////////////////////////////////////////////////////////////// 229 ////////////////////////////////////////////////////////////////////
177 //////////////////////////////////////////////////////////////////// 230 ////////////////////////////////////////////////////////////////////