diff options
Diffstat (limited to 'js/io/system')
-rw-r--r-- | js/io/system/chromeapi.js | 51 | ||||
-rwxr-xr-x | js/io/system/coreioapi.js | 34 | ||||
-rw-r--r-- | js/io/system/ninjalibrary.js | 93 | ||||
-rw-r--r-- | js/io/system/ninjalibrary.json | 2 |
4 files changed, 138 insertions, 42 deletions
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index fb141687..6df41fd3 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js | |||
@@ -9,6 +9,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
9 | NOTES: | 9 | NOTES: |
10 | The init function starts up the file system API, and a size must be | 10 | The init function starts up the file system API, and a size must be |
11 | set, no unlimited available as of now. | 11 | set, no unlimited available as of now. |
12 | |||
13 | Core API reference in NINJA: this.application.ninja.coreIoApi | ||
14 | |||
12 | //////////////////////////////////////////////////////////////////////// | 15 | //////////////////////////////////////////////////////////////////////// |
13 | ///////////////////////////////////////////////////////////////////// */ | 16 | ///////////////////////////////////////////////////////////////////// */ |
14 | // | 17 | // |
@@ -61,24 +64,51 @@ exports.ChromeApi = Montage.create(Object.prototype, { | |||
61 | }, | 64 | }, |
62 | //////////////////////////////////////////////////////////////////// | 65 | //////////////////////////////////////////////////////////////////// |
63 | // | 66 | // |
67 | fileNew: { | ||
68 | enumerable: true, | ||
69 | value: function(filePath, content, mime, callback) { | ||
70 | // | ||
71 | this.fileSystem.root.getFile(filePath, {create: true}, function(f) { | ||
72 | // | ||
73 | f.createWriter(function(writer) { | ||
74 | // | ||
75 | var b = new window.WebKitBlobBuilder; | ||
76 | b.append(content); | ||
77 | writer.write(b.getBlob(mime)); | ||
78 | // | ||
79 | if (callback) callback(true); | ||
80 | }, function (e) {if (callback) callback(false)}); | ||
81 | }, function (e) {if (callback) callback(false)}); | ||
82 | } | ||
83 | }, | ||
84 | //////////////////////////////////////////////////////////////////// | ||
85 | //Creating directory from path, callback optional | ||
64 | directoryNew: { | 86 | directoryNew: { |
65 | enumerable: true, | 87 | enumerable: true, |
66 | value: function() { | 88 | value: function(directoryPath, callback) { |
89 | //Checking for directory not to already exist | ||
90 | this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) { | ||
91 | if (callback) callback(false); | ||
92 | return; //Directory already exists | ||
93 | }); | ||
94 | //Creating new directory | ||
95 | this.fileSystem.root.getDirectory(directoryPath, {create: true}, function(dir) { | ||
96 | if (callback) callback(true); | ||
97 | }, function (e) {if (callback) callback(false)}); | ||
67 | } | 98 | } |
68 | }, | 99 | }, |
69 | |||
70 | //////////////////////////////////////////////////////////////////// | 100 | //////////////////////////////////////////////////////////////////// |
71 | // | 101 | // |
72 | directoryDelete: { | 102 | directoryDelete: { |
73 | enumerable: true, | 103 | enumerable: true, |
74 | value: function(directoryPath, callback) { | 104 | value: function(directoryPath, callback) { |
75 | // | 105 | // |
76 | this.fileSystem.getDirectory(directoryPath, {}, function(dirEntry) { | 106 | this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) { |
77 | // | 107 | // |
78 | dirEntry.removeRecursively(function() { | 108 | dir.removeRecursively(function() { |
79 | callback(true); | 109 | if (callback) callback(true); |
80 | }); | 110 | }); |
81 | }, function (e) {callback(false)}); | 111 | }, function (e) {if (callback) callback(false)}); |
82 | } | 112 | } |
83 | }, | 113 | }, |
84 | //////////////////////////////////////////////////////////////////// | 114 | //////////////////////////////////////////////////////////////////// |
@@ -125,9 +155,12 @@ exports.ChromeApi = Montage.create(Object.prototype, { | |||
125 | // | 155 | // |
126 | var lib = []; | 156 | var lib = []; |
127 | // | 157 | // |
128 | 158 | for(var i=0; contents[i]; i++) { | |
129 | 159 | // | |
130 | 160 | if (contents[i].isDirectory) { | |
161 | lib.push(contents[i].name); | ||
162 | } | ||
163 | } | ||
131 | //Dispatching action ready event | 164 | //Dispatching action ready event |
132 | var libraryEvent = document.createEvent("CustomEvent"); | 165 | var libraryEvent = document.createEvent("CustomEvent"); |
133 | libraryEvent.initEvent('library', true, true); | 166 | libraryEvent.initEvent('library', true, true); |
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index b821936f..9836f33f 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -17,6 +17,7 @@ var Montage = require("montage/core/core").Montage, | |||
17 | Popup = require("js/components/popup.reel").Popup, | 17 | Popup = require("js/components/popup.reel").Popup, |
18 | CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup, | 18 | CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup, |
19 | ChromeApi = require("js/io/system/chromeapi").ChromeApi; | 19 | ChromeApi = require("js/io/system/chromeapi").ChromeApi; |
20 | NinjaLibrary = require("js/io/system/ninjalibrary").NinjaLibrary; | ||
20 | //////////////////////////////////////////////////////////////////////// | 21 | //////////////////////////////////////////////////////////////////////// |
21 | //Exporting as Project I/O | 22 | //Exporting as Project I/O |
22 | exports.CoreIoApi = Montage.create(Component, { | 23 | exports.CoreIoApi = Montage.create(Component, { |
@@ -37,6 +38,8 @@ exports.CoreIoApi = Montage.create(Component, { | |||
37 | this.ioServiceDetected = false; | 38 | this.ioServiceDetected = false; |
38 | } | 39 | } |
39 | //////////////////////////////////////////////////////////// | 40 | //////////////////////////////////////////////////////////// |
41 | //Instance of ninja library | ||
42 | this.ninjaLibrary = NinjaLibrary; | ||
40 | //Getting reference of chrome file system API | 43 | //Getting reference of chrome file system API |
41 | this.chromeFileSystem = ChromeApi; | 44 | this.chromeFileSystem = ChromeApi; |
42 | //Sending size in MBs for file system storage | 45 | //Sending size in MBs for file system storage |
@@ -69,36 +72,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
69 | //Removing events | 72 | //Removing events |
70 | this.chromeFileSystem.removeEventListener('library', this, false); | 73 | this.chromeFileSystem.removeEventListener('library', this, false); |
71 | // | 74 | // |
72 | var xhr = new XMLHttpRequest(), libs, tocopylibs = []; | 75 | this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem); |
73 | //Getting known json list of libraries to copy to chrome | ||
74 | xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); | ||
75 | xhr.send(); | ||
76 | //Checkng for correct reponse | ||
77 | if (xhr.readyState === 4) { | ||
78 | //Parsing json libraries | ||
79 | libs = JSON.parse(xhr.response); | ||
80 | // | ||
81 | if (e._event.ninjaChromeLibrary.length > 0) { | ||
82 | //Compare | ||
83 | } else { | ||
84 | //No library is present, must copy all | ||
85 | for (var i in libs.libraries) { | ||
86 | if (libs.libraries[i].singular) { | ||
87 | tocopylibs.push({name: String(libs.libraries[i].name+libs.libraries[i].version).toLowerCase(), path: libs.libraries[i].path, singular: true}); | ||
88 | } else { | ||
89 | tocopylibs.push({name: String(libs.libraries[i].name+libs.libraries[i].version).toLowerCase(), path: libs.libraries[i].path, singular: false}); | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | // | ||
94 | if (tocopylibs.length > 0) { | ||
95 | //Copy libraries | ||
96 | } else { | ||
97 | //No libraries to copy | ||
98 | } | ||
99 | } else { | ||
100 | //Error | ||
101 | } | ||
102 | } | 76 | } |
103 | }, | 77 | }, |
104 | //////////////////////////////////////////////////////////////////// | 78 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 3f8585ed..e3d855f1 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js | |||
@@ -7,6 +7,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
7 | /* ///////////////////////////////////////////////////////////////////// | 7 | /* ///////////////////////////////////////////////////////////////////// |
8 | //////////////////////////////////////////////////////////////////////// | 8 | //////////////////////////////////////////////////////////////////////// |
9 | NOTES: | 9 | NOTES: |
10 | |||
11 | Core API reference in NINJA: this.application.ninja.coreIoApi | ||
12 | |||
10 | //////////////////////////////////////////////////////////////////////// | 13 | //////////////////////////////////////////////////////////////////////// |
11 | ///////////////////////////////////////////////////////////////////// */ | 14 | ///////////////////////////////////////////////////////////////////// */ |
12 | // | 15 | // |
@@ -16,12 +19,98 @@ var Montage = require("montage/core/core").Montage; | |||
16 | exports.NinjaLibrary = Montage.create(Object.prototype, { | 19 | exports.NinjaLibrary = Montage.create(Object.prototype, { |
17 | //////////////////////////////////////////////////////////////////// | 20 | //////////////////////////////////////////////////////////////////// |
18 | // | 21 | // |
19 | init: { | 22 | _chromeApi: { |
23 | enumerable: false, | ||
24 | value: null | ||
25 | }, | ||
26 | //////////////////////////////////////////////////////////////////// | ||
27 | // | ||
28 | chromeApi: { | ||
29 | enumerable: false, | ||
30 | get: function() { | ||
31 | return this._chromeApi; | ||
32 | }, | ||
33 | set: function(value) { | ||
34 | this._chromeApi = value; | ||
35 | } | ||
36 | }, | ||
37 | //////////////////////////////////////////////////////////////////// | ||
38 | // | ||
39 | synchronize: { | ||
40 | enumerable: true, | ||
41 | value: function(chromeLibs, chrome) { | ||
42 | // | ||
43 | this.chromeApi = chrome; | ||
44 | // | ||
45 | var i, libs, xhr = new XMLHttpRequest(), tocopylibs = []; | ||
46 | //Getting known json list of libraries to copy to chrome | ||
47 | xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); | ||
48 | xhr.send(); | ||
49 | //Checkng for correct reponse | ||
50 | if (xhr.readyState === 4) { | ||
51 | //Parsing json libraries | ||
52 | libs = JSON.parse(xhr.response); | ||
53 | // | ||
54 | if (chromeLibs.length > 0) { | ||
55 | //Compare (always deleting for testing) | ||
56 | for (i=0; chromeLibs[i]; i++) { | ||
57 | this.chromeApi.directoryDelete(chromeLibs[i]); | ||
58 | } | ||
59 | } else { | ||
60 | //No library is present, must copy all | ||
61 | for (var j in libs.libraries) { | ||
62 | //name: used to folder container contents | ||
63 | //path: url of descriptor json or single file to load (descriptor has list of files) | ||
64 | //singular: indicates the path is the file to be loaded into folder | ||
65 | if (libs.libraries[j].file) { | ||
66 | tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file}); | ||
67 | } else { | ||
68 |