aboutsummaryrefslogtreecommitdiff
path: root/js/io/system
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system')
-rw-r--r--js/io/system/ninjalibrary.js88
1 files changed, 75 insertions, 13 deletions
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
index e3d855f1..09cf7407 100644
--- a/js/io/system/ninjalibrary.js
+++ b/js/io/system/ninjalibrary.js
@@ -42,7 +42,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
42 // 42 //
43 this.chromeApi = chrome; 43 this.chromeApi = chrome;
44 // 44 //
45 var i, libs, xhr = new XMLHttpRequest(), tocopylibs = []; 45 var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = [];
46 //Getting known json list of libraries to copy to chrome 46 //Getting known json list of libraries to copy to chrome
47 xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); 47 xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false);
48 xhr.send(); 48 xhr.send();
@@ -52,9 +52,9 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
52 libs = JSON.parse(xhr.response); 52 libs = JSON.parse(xhr.response);
53 // 53 //
54 if (chromeLibs.length > 0) { 54 if (chromeLibs.length > 0) {
55 //Compare (always deleting for testing) 55 //TODO: Remove
56 for (i=0; chromeLibs[i]; i++) { 56 for (i=0; chromeLibs[i]; i++) {
57 this.chromeApi.directoryDelete(chromeLibs[i]); 57 this.chromeApi.directoryDelete(chromeLibs[i]);
58 } 58 }
59 } else { 59 } else {
60 //No library is present, must copy all 60 //No library is present, must copy all
@@ -84,12 +84,58 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
84 if (xhr.readyState === 4) { //TODO: add check for mime type 84 if (xhr.readyState === 4) { //TODO: add check for mime type
85 //Creating new file from loaded content 85 //Creating new file from loaded content
86 this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain'); 86 this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain');
87 //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain', function (v){console.log(v)});
88 } else { 87 } else {
89 //Error 88 //Error creating single file library
90 } 89 }
91 } else { 90 } else {
92 // 91 //Creating root folder
92 this.chromeApi.directoryNew('/'+tocopylibs[i].name);
93 //Getting file contents
94 xhr = new XMLHttpRequest();
95 xhr.open("GET", tocopylibs[i].path, false);
96 xhr.send();
97 //Checking for status
98 if (xhr.readyState === 4) {
99 //
100 libjson = JSON.parse(xhr.response);
101 //
102 for (l=0; libjson.directories[l]; l++) {
103 libjson.dirsToCreate = libjson.directories.length;
104 libjson.dirsCreated = 0;
105 libjson.filesToCreate = libjson.files.length;
106 libjson.filesCreated = 0;
107 libjson.api = this.chromeApi;
108 libjson.local = tocopylibs[i].name;
109 this.createDirectory(tocopylibs[i].name, libjson.directories[l], function (status) {
110 //Checking for success on directories created
111 if (status) {
112 this.dirsCreated++;
113 }
114 //All directories created
115 if (this.dirsCreated === this.dirsToCreate) {
116 var xhr, i;
117 for (i=0; this.files[i]; i++) {
118 xhr = new XMLHttpRequest();
119 xhr.open("GET", this.root+this.files[i], false);
120 xhr.send();
121 //Checking for status
122 if (xhr.readyState === 4) {
123 this.api.fileNew(this.local+'/'+this.files[i], xhr.response, 'text/plain', function (status) {
124 if (status) {
125 this.filesCreated++;
126 }
127 if (this.filesCreated === this.filesToCreate) {
128 //TODO: Add logic for task completed
129 }
130 }.bind(this));
131 }
132 }
133 }
134 }.bind(libjson));
135 }
136 } else {
137 //Error
138 }
93 } 139 }
94 } 140 }
95 } else { 141 } else {
@@ -99,18 +145,34 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
99 //Error 145 //Error
100 } 146 }
101 } 147 }
102 }/* 148 },
103,
104 //////////////////////////////////////////////////////////////////// 149 ////////////////////////////////////////////////////////////////////
105 // 150 //
106 createFolder: { 151 createDirectory: {
107 enumerable: true, 152 enumerable: true,
108 value: function(name) { 153 value: function(root, folder, callback) {
109 // 154 //
110 this.chromeApi.directoryNew(name); 155 if (folder.name) {
156 if (root) {
157 dir = root+'/'+folder.name;
158 } else {
159 dir = folder.name;
160 }
161 //
162 this.chromeApi.directoryNew(dir, function (status) {if (callback)callback(status)});
163 }
164 //
165 if (folder.children) {
166 for (var j in folder.children) {
167 if (root) {
168 this.createDirectory(root+'/'+folder.name, folder.children[j]);
169 } else {
170 this.createDirectory(folder.name, folder.children[j]);
171 }
172 }
173 }
111 } 174 }
112 } 175 }
113*/
114 //////////////////////////////////////////////////////////////////// 176 ////////////////////////////////////////////////////////////////////
115 //////////////////////////////////////////////////////////////////// 177 ////////////////////////////////////////////////////////////////////
116}); 178});