aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/coreioapi.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system/coreioapi.js')
-rwxr-xr-xjs/io/system/coreioapi.js1103
1 files changed, 1103 insertions, 0 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js
new file mode 100755
index 00000000..2051da43
--- /dev/null
+++ b/js/io/system/coreioapi.js
@@ -0,0 +1,1103 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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////////////////////////////////////////////////////////////////////////
9NOTES:
10
11 Core API reference in NINJA: this.application.ninja.coreIoApi
12
13////////////////////////////////////////////////////////////////////////
14///////////////////////////////////////////////////////////////////// */
15var 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 NinjaLibrary = require("js/io/system/ninjalibrary").NinjaLibrary;
21////////////////////////////////////////////////////////////////////////
22//Exporting as Project I/O
23exports.CoreIoApi = Montage.create(Component, {
24 ////////////////////////////////////////////////////////////////////
25 //
26 deserializedFromTemplate: {
27 enumerable: false,
28 value: function () {
29 ////////////////////////////////////////////////////////////
30 //Checking for local storage of URL for IO
31 if (window.localStorage['ioRootUrl']) {
32 //Getting URL from local storage
33 this.rootUrl = window.localStorage['ioRootUrl'];
34 //Checks for IO API to be active
35 this.ioServiceDetected = this.cloudAvailable();
36 } else {
37 //IO API to be inactive
38 this.ioServiceDetected = false;
39 }
40 ////////////////////////////////////////////////////////////
41 //Instance of ninja library
42 this.ninjaLibrary = NinjaLibrary;
43 this.ninjaLibrary.coreApi = this;
44 //Getting reference of chrome file system API
45 this.chromeFileSystem = ChromeApi;
46 //Sending size in MBs for file system storage
47 var chromeFs = this.chromeFileSystem.init(20);
48 //Checking for availability of API
49 if (chromeFs) {
50 this.chromeFileSystem.addEventListener('ready', this, false);
51 } else {
52 //Error, Chrome File System API not detected
53 }
54 ////////////////////////////////////////////////////////////
55 }
56 },
57 ////////////////////////////////////////////////////////////////////
58 //
59 handleReady: {
60 enumerable: false,
61 value: function (e) {
62 //Removing events
63 this.chromeFileSystem.removeEventListener('ready', this, false);
64 //Listening for library to be copied event (builds list)
65 this.chromeFileSystem.addEventListener('library', this, false);
66 //TODO: Add sync loading screen logic (Add screen here)
67 }
68 },
69 ////////////////////////////////////////////////////////////////////
70 //
71 handleLibrary: {
72 enumerable: false,
73 value: function (e) {
74 //Removing events
75 this.chromeFileSystem.removeEventListener('library', this, false);
76 //Listening for synced library event
77 this.ninjaLibrary.addEventListener('sync', this, false);
78 //Sending library to be synced to chrome
79 this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem);
80
81 }
82 },
83 ////////////////////////////////////////////////////////////////////
84 //
85 handleSync: {
86 enumerable: false,
87 value: function (e) {
88 console.log('Ninja Local Library: Ready');
89 //Removing events
90 this.ninjaLibrary.removeEventListener('sync', this, false);
91 //TODO: Add sync loading screen logic (Remove screen here)
92 }
93 },
94 ////////////////////////////////////////////////////////////////////
95 //
96 _chromeNinjaLibrary: {
97 enumerable: false,
98 value: null
99 },
100 ////////////////////////////////////////////////////////////////////
101 //
102 chromeNinjaLibrary: {
103 enumerable: false,
104 get: function() {
105 return this._chromeNinjaLibrary;
106 },
107 set: function(value) {
108 this._chromeNinjaLibrary = value;
109 }
110 },
111 ////////////////////////////////////////////////////////////////////
112 //
113 _chromeFileSystem: {
114 enumerable: false,
115 value: null
116 },
117 ////////////////////////////////////////////////////////////////////
118 //
119 chromeFileSystem: {
120 enumerable: false,
121 get: function() {
122 return this._chromeFileSystem;
123 },
124 set: function(value) {
125 this._chromeFileSystem = value;
126 }
127 },
128 ////////////////////////////////////////////////////////////////////
129 //
130 _ioServiceDetected: {
131 enumerable: false,
132 value: false
133 },
134 ////////////////////////////////////////////////////////////////////
135 //Checking for service availability on boot
136 ioServiceDetected: {
137 enumerable: false,
138 get: function() {
139 return this._ioServiceDetected;
140 },
141 set: function(value) {
142 this._ioServiceDetected = value;
143 }
144 },
145 ////////////////////////////////////////////////////////////////////
146 //Root API URL
147 _rootUrl: {
148 enumerable: false,
149 value: null
150 },
151 ////////////////////////////////////////////////////////////////////
152 //
153 rootUrl: {
154 enumerable: false,
155 get: function() {
156 return this._rootUrl;
157 },
158 set: function(value) {
159 this._rootUrl = window.localStorage["ioRootUrl"] = value;
160 }
161 },
162 ////////////////////////////////////////////////////////////////////
163 //API service URL
164 _apiServiceURL: {
165 enumerable: false,
166 value: '/cloudstatus'
167 },
168 ////////////////////////////////////////////////////////////////////
169 //
170 apiServiceURL: {
171 enumerable: false,
172 get: function() {
173 return String(this.rootUrl+this._apiServiceURL);
174 },
175 set: function(value) {
176 this._apiServiceURL = value;
177 }
178 },
179 ////////////////////////////////////////////////////////////////////
180 //File service API URL
181 _fileServiceURL: {
182 enumerable: false,
183 value: '/file'
184 },
185 ////////////////////////////////////////////////////////////////////
186 //
187 fileServiceURL: {
188 enumerable: false,
189 get: function() {
190 return String(this.rootUrl+this._fileServiceURL);
191 },
192 set: function(value) {
193 this._fileServiceURL = value;
194 }
195 },
196 ////////////////////////////////////////////////////////////////////
197 //Directory service API URL
198 _directoryServiceURL: {
199 enumerable: false,
200 value: '/directory'
201 },
202 ////////////////////////////////////////////////////////////////////
203 //
204 directoryServiceURL: {
205 enumerable: false,
206 get: function() {
207 return String(this.rootUrl+this._directoryServiceURL);
208 },
209 set: function(value) {
210 this._directoryServiceURL = value;
211 }
212 },
213 ////////////////////////////////////////////////////////////////////
214 // private helper to parse URIs and append them to the service URL
215 _prepareServiceURL: {
216 enumerable: false,
217 value: function(serviceURL, path) {
218 var urlOut = path.replace(/\\/g,"/");
219 urlOut = urlOut.replace(/:/g,"");
220 urlOut = encodeURI(urlOut);
221 //add leading / if not already there
222 if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){
223 urlOut = "/" + urlOut;
224 }
225 //remove extra / at the end
226 if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){
227 urlOut = urlOut.substring(0, (urlOut.length - 1));
228 }
229 //
230 return String(serviceURL+urlOut);
231 }
232 },
233 ////////////////////////////////////////////////////////////////////
234 //Method to check status of I/O API, will return false if not active
235 cloudAvailable: {
236 enumerable: false,
237 value: function () {
238 var cloud = this.getCloudStatus();
239 //
240 if (this.rootUrl && cloud.status === 200) {
241 //Active