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.js1131
1 files changed, 1131 insertions, 0 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js
new file mode 100755
index 00000000..005eabf2
--- /dev/null
+++ b/js/io/system/coreioapi.js
@@ -0,0 +1,1131 @@
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 //Getting reference of chrome file system API
44 this.chromeFileSystem = ChromeApi;
45 //Sending size in MBs for file system storage
46 var chromeFs = this.chromeFileSystem.init(20);
47 //Checking for availability of API
48 if (chromeFs) {
49 this.chromeFileSystem.addEventListener('ready', this, false);
50 } else {
51 //Error, Chrome File System API not detected
52 }
53 ////////////////////////////////////////////////////////////
54 }
55 },
56 ////////////////////////////////////////////////////////////////////
57 //
58 handleReady: {
59 enumerable: false,
60 value: function (e) {
61 //Removing events
62 this.chromeFileSystem.removeEventListener('ready', this, false);
63 //Listening for library to be copied event (builds list)
64 this.chromeFileSystem.addEventListener('library', this, false);
65 }
66 },
67 ////////////////////////////////////////////////////////////////////
68 //
69 handleLibrary: {
70 enumerable: false,
71 value: function (e) {
72 //Removing events
73 this.chromeFileSystem.removeEventListener('library', this, false);
74 //Listening for synced library event
75 this.ninjaLibrary.addEventListener('sync', this, false);
76 //Sending library to be synced to chrome
77 this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem);
78
79 }
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 },
92 ////////////////////////////////////////////////////////////////////
93 //
94 _chromeNinjaLibrary: {
95 enumerable: false,
96 value: null
97 },
98 ////////////////////////////////////////////////////////////////////
99 //
100 chromeNinjaLibrary: {
101 enumerable: false,
102 get: function() {
103 return this._chromeNinjaLibrary;
104 },
105 set: function(value) {
106 this._chromeNinjaLibrary = value;
107 }
108 },
109 ////////////////////////////////////////////////////////////////////
110 //
111 _chromeFileSystem: {
112 enumerable: false,
113 value: null
114 },
115 ////////////////////////////////////////////////////////////////////
116 //
117 chromeFileSystem: {
118 enumerable: false,
119 get: function() {
120 return this._chromeFileSystem;
121 },
122 set: function(value) {
123 this._chromeFileSystem = value;
124 }
125 },
126 ////////////////////////////////////////////////////////////////////
127 //
128 _ioServiceDetected: {
129 enumerable: false,
130 value: false
131 },
132 ////////////////////////////////////////////////////////////////////
133 //Checking for service availability on boot
134 ioServiceDetected: {
135 enumerable: false,
136 get: function() {
137 return this._ioServiceDetected;
138 },
139 set: function(value) {
140 this._ioServiceDetected = value;
141 }
142 },
143 ////////////////////////////////////////////////////////////////////
144 //Root API URL
145 _rootUrl: {
146 enumerable: false,
147 value: null
148 },
149 ////////////////////////////////////////////////////////////////////
150 //
151 rootUrl: {
152 enumerable: false,
153 get: function() {
154 return this._rootUrl;
155 },
156 set: function(value) {
157 this._rootUrl = window.localStorage["ioRootUrl"] = value;
158 }
159 },
160 ////////////////////////////////////////////////////////////////////
161 //API service URL
162 _apiServiceURL: {
163 enumerable: false,
164 value: '/cloudstatus'
165 },
166 ////////////////////////////////////////////////////////////////////
167 //
168 apiServiceURL: {
169 enumerable: false,
170 get: function() {
171 return String(this.rootUrl+this._apiServiceURL);
172 },
173 set: function(value) {
174 this._apiServiceURL = value;
175 }
176 },
177 ////////////////////////////////////////////////////////////////////
178 //File service API URL
179 _fileServiceURL: {
180 enumerable: false,
181 value: '/file'
182 },
183 ////////////////////////////////////////////////////////////////////
184 //
185 fileServiceURL: {
186 enumerable: false,
187 get: function() {
188 return String(this.rootUrl+this._fileServiceURL);
189 },
190 set: function(value) {
191 this._fileServiceURL = value;
192 }
193 },
194 ////////////////////////////////////////////////////////////////////
195 //Directory service API URL
196 _directoryServiceURL: {
197 enumerable: false,
198 value: '/directory'
199 },
200 ////////////////////////////////////////////////////////////////////
201 //
202 directoryServiceURL: {
203 enumerable: false,
204 get: function() {
205 return String(this.rootUrl+this._directoryServiceURL);
206 },
207 set: function(value) {
208 this._directoryServiceURL = value;
209 }
210 },
211 ////////////////////////////////////////////////////////////////////
212 // private helper to parse URIs and append them to the service URL
213 _prepareServiceURL: {
214 enumerable: false,
215 value: function(serviceURL, path) {
216 var urlOut = path.replace(/\\/g,"/");
217 urlOut = urlOut.replace(/:/g,"");
218 urlOut = encodeURI(urlOut);
219 //add leading / if not already there
220 if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){
221 urlOut = "/" + urlOut;
222 }
223 //remove extra / at the end
224 if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){
225 urlOut = urlOut.substring(0, (urlOut.length - 1));
226 }
227 //
228 return String(serviceURL+urlOut);
229 }
230 },
231 ////////////////////////////////////////////////////////////////////
232 //Method to check status of I/O API, will return false if not active
233 cloudAvailable: {
234 enumerable: false,
235 value: function () {
236 var cloud = this.getCloudStatus();
237 //
238 if (this.rootUrl && cloud.status === 200) {
239 //Active
240 this.cloudData.name = cloud.response['name'];
</