diff options
Diffstat (limited to 'js/io/system/coreioapi.js')
-rwxr-xr-x | js/io/system/coreioapi.js | 1143 |
1 files changed, 1143 insertions, 0 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js new file mode 100755 index 00000000..b821936f --- /dev/null +++ b/js/io/system/coreioapi.js | |||
@@ -0,0 +1,1143 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | /* ///////////////////////////////////////////////////////////////////// | ||
8 | //////////////////////////////////////////////////////////////////////// | ||
9 | NOTES: | ||
10 | |||
11 | Core API reference in NINJA: this.application.ninja.coreIoApi | ||
12 | |||
13 | //////////////////////////////////////////////////////////////////////// | ||
14 | ///////////////////////////////////////////////////////////////////// */ | ||
15 | var Montage = require("montage/core/core").Montage, | ||
16 | Component = require("montage/ui/component").Component, | ||
17 | Popup = require("js/components/popup.reel").Popup, | ||
18 | CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup, | ||
19 | ChromeApi = require("js/io/system/chromeapi").ChromeApi; | ||
20 | //////////////////////////////////////////////////////////////////////// | ||
21 | //Exporting as Project I/O | ||
22 | exports.CoreIoApi = Montage.create(Component, { | ||
23 | //////////////////////////////////////////////////////////////////// | ||
24 | // | ||
25 | deserializedFromTemplate: { | ||
26 | enumerable: false, | ||
27 | value: function () { | ||
28 | //////////////////////////////////////////////////////////// | ||
29 | //Checking for local storage of URL for IO | ||
30 | if (window.localStorage['ioRootUrl']) { | ||
31 | //Getting URL from local storage | ||
32 | this.rootUrl = window.localStorage['ioRootUrl']; | ||
33 | //Checks for IO API to be active | ||
34 | this.ioServiceDetected = this.cloudAvailable(); | ||
35 | } else { | ||
36 | //IO API to be inactive | ||
37 | this.ioServiceDetected = false; | ||
38 | } | ||
39 | //////////////////////////////////////////////////////////// | ||
40 | //Getting reference of chrome file system API | ||
41 | this.chromeFileSystem = ChromeApi; | ||
42 | //Sending size in MBs for file system storage | ||
43 | var chromeFs = this.chromeFileSystem.init(20); | ||
44 | //Checking for availability of API | ||
45 | if (chromeFs) { | ||
46 | this.chromeFileSystem.addEventListener('ready', this, false); | ||
47 | } else { | ||
48 | //Error, Chrome File System API not detected | ||
49 | } | ||
50 | //////////////////////////////////////////////////////////// | ||
51 | } | ||
52 | }, | ||
53 | //////////////////////////////////////////////////////////////////// | ||
54 | // | ||
55 | handleReady: { | ||
56 | enumerable: false, | ||
57 | value: function (e) { | ||
58 | // | ||
59 | this.chromeFileSystem.removeEventListener('ready', this, false); | ||
60 | // | ||
61 | this.chromeFileSystem.addEventListener('library', this, false); | ||
62 | } | ||
63 | }, | ||
64 | //////////////////////////////////////////////////////////////////// | ||
65 | // | ||
66 | handleLibrary: { | ||
67 | enumerable: false, | ||
68 | value: function (e) { | ||
69 | //Removing events | ||
70 | this.chromeFileSystem.removeEventListener('library', this, false); | ||
71 | // | ||
72 | var xhr = new XMLHttpRequest(), libs, tocopylibs = []; | ||
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 | } | ||
103 | }, | ||
104 | //////////////////////////////////////////////////////////////////// | ||
105 | // | ||
106 | _chromeNinjaLibrary: { | ||
107 | enumerable: false, | ||
108 | value: null | ||
109 | }, | ||
110 | //////////////////////////////////////////////////////////////////// | ||
111 | // | ||
112 | chromeNinjaLibrary: { | ||
113 | enumerable: false, | ||
114 | get: function() { | ||
115 | return this._chromeNinjaLibrary; | ||
116 | }, | ||
117 | set: function(value) { | ||
118 | this._chromeNinjaLibrary = value; | ||
119 | } | ||
120 | }, | ||
121 | //////////////////////////////////////////////////////////////////// | ||
122 | // | ||
123 | _chromeFileSystem: { | ||
124 | enumerable: false, | ||
125 | value: null | ||
126 | }, | ||
127 | //////////////////////////////////////////////////////////////////// | ||
128 | // | ||
129 | chromeFileSystem: { | ||
130 | enumerable: false, | ||
131 | get: function() { | ||
132 | return this._chromeFileSystem; | ||
133 | }, | ||
134 | set: function(value) { | ||
135 | this._chromeFileSystem = value; | ||
136 | } | ||
137 | }, | ||
138 | //////////////////////////////////////////////////////////////////// | ||
139 | // | ||
140 | _ioServiceDetected: { | ||
141 | enumerable: false, | ||
142 | value: false | ||
143 | }, | ||
144 | //////////////////////////////////////////////////////////////////// | ||
145 | //Checking for service availability on boot | ||
146 | ioServiceDetected: { | ||
147 | enumerable: false, | ||
148 | get: function() { | ||
149 | return this._ioServiceDetected; | ||
150 | }, | ||
151 | set: function(value) { | ||
152 | this._ioServiceDetected = value; | ||
153 | } | ||
154 | }, | ||
155 | //////////////////////////////////////////////////////////////////// | ||
156 | //Root API URL | ||
157 | _rootUrl: { | ||
158 | enumerable: false, | ||
159 | value: null | ||
160 | }, | ||
161 | //////////////////////////////////////////////////////////////////// | ||
162 | // | ||
163 | rootUrl: { | ||
164 | enumerable: false, | ||
165 | get: function() { | ||
166 | return this._rootUrl; | ||
167 | }, | ||
168 | set: function(value) { | ||
169 | this._rootUrl = window.localStorage["ioRootUrl"] = value; | ||
170 | } | ||
171 | }, | ||
172 | //////////////////////////////////////////////////////////////////// | ||
173 | //API service URL | ||
174 | _apiServiceURL: { | ||
175 | enumerable: false, | ||
176 | value: '/cloudstatus' | ||
177 | }, | ||
178 | //////////////////////////////////////////////////////////////////// | ||
179 | // | ||
180 | apiServiceURL: { | ||
181 | enumerable: false, | ||
182 | get: function() { | ||
183 | return String(this.rootUrl+this._apiServiceURL); | ||
184 | }, | ||
185 | set: function(value) { | ||
186 | this._apiServiceURL = value; | ||
187 | } | ||
188 | }, | ||
189 | //////////////////////////////////////////////////////////////////// | ||
190 | //File service API URL | ||
191 | _fileServiceURL: { | ||
192 | enumerable: false, | ||
193 | value: '/file' | ||
194 | }, | ||
195 | //////////////////////////////////////////////////////////////////// | ||
196 | // | ||
197 | fileServiceURL: { | ||
198 | enumerable: false, | ||
199 | get: function() { | ||
200 | return String(this.rootUrl+this._fileServiceURL); | ||
201 | }, | ||
202 | set: function(value) { | ||
203 | this._fileServiceURL = value; | ||
204 | } | ||
205 | }, | ||
206 | //////////////////////////////////////////////////////////////////// | ||
207 | //Directory service API URL | ||
208 | _directoryServiceURL: { | ||
209 | enumerable: false, | ||
210 | value: '/directory' | ||
211 | }, | ||
212 | //////////////////////////////////////////////////////////////////// | ||
213 | // | ||
214 | directoryServiceURL: { | ||
215 | enumerable: false, | ||
216 | get: function() { | ||
217 | return String(this.rootUrl+this._directoryServiceURL); | ||
218 | }, | ||
219 | set: function(value) { | ||
220 | this._directoryServiceURL = value; | ||
221 | } | ||
222 | }, | ||
223 | //////////////////////////////////////////////////////////////////// | ||
224 | // private helper to parse URIs and append them to the service URL | ||
225 | _prepareServiceURL: { | ||
226 | enumerable: false, | ||
227 | value: function(serviceURL, path) { | ||
228 | var urlOut = path.replace(/\\/g,"/"); | ||
229 | urlOut = urlOut.replace(/:/g,""); | ||
230 | urlOut = encodeURI(urlOut); | ||
231 | //add leading / if not already there | ||
232 | if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){ | ||
233 | urlOut = "/" + urlOut; | ||
234 | } | ||
235 | //remove extra / at the end | ||
236 | if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ | ||
237 | urlOut = urlOut.substring(0, (urlOut.length - 1)); | ||
238 | } | ||
239 | // | ||
240 | return String(serviceURL+urlOut); | ||