diff options
Diffstat (limited to 'js/io/system/coreioapi.js')
-rwxr-xr-x | js/io/system/coreioapi.js | 1137 |
1 files changed, 1137 insertions, 0 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js new file mode 100755 index 00000000..0e721500 --- /dev/null +++ b/js/io/system/coreioapi.js | |||
@@ -0,0 +1,1137 @@ | |||
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 | NinjaLibrary = require("js/io/system/ninjalibrary").NinjaLibrary; | ||
21 | //////////////////////////////////////////////////////////////////////// | ||
22 | //Exporting as Project I/O | ||
23 | exports.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 | console.log('Ninja Local Library: Ready'); | ||
87 | //Removing events | ||
88 | this.ninjaLibrary.removeEventListener('sync', this, false); | ||
89 | this.ninjaLibrary.coreApi = this; | ||
90 | //TODO: Add sync loading screen logic | ||
91 | |||
92 | //TODO: Remove test | ||
93 | //this.ninjaLibrary.copyLibToCloud('Users/kgq387/Desktop/Ninja Cloud/Disk', 'montage0.6.0'); | ||
94 | //this.ninjaLibrary.deleteLibraries(); | ||
95 | } | ||
96 | }, | ||
97 | //////////////////////////////////////////////////////////////////// | ||
98 | // | ||
99 | _chromeNinjaLibrary: { | ||
100 | enumerable: false, | ||
101 | value: null | ||
102 | }, | ||
103 | //////////////////////////////////////////////////////////////////// | ||
104 | // | ||
105 | chromeNinjaLibrary: { | ||
106 | enumerable: false, | ||
107 | get: function() { | ||
108 | return this._chromeNinjaLibrary; | ||
109 | }, | ||
110 | set: function(value) { | ||
111 | this._chromeNinjaLibrary = value; | ||
112 | } | ||
113 | }, | ||
114 | //////////////////////////////////////////////////////////////////// | ||
115 | // | ||
116 | _chromeFileSystem: { | ||
117 | enumerable: false, | ||
118 | value: null | ||
119 | }, | ||
120 | //////////////////////////////////////////////////////////////////// | ||
121 | // | ||
122 | chromeFileSystem: { | ||
123 | enumerable: false, | ||
124 | get: function() { | ||
125 | return this._chromeFileSystem; | ||
126 | }, | ||
127 | set: function(value) { | ||
128 | this._chromeFileSystem = value; | ||
129 | } | ||
130 | }, | ||
131 | //////////////////////////////////////////////////////////////////// | ||
132 | // | ||
133 | _ioServiceDetected: { | ||
134 | enumerable: false, | ||
135 | value: false | ||
136 | }, | ||
137 | //////////////////////////////////////////////////////////////////// | ||
138 | //Checking for service availability on boot | ||
139 | ioServiceDetected: { | ||
140 | enumerable: false, | ||
141 | get: function() { | ||
142 | return this._ioServiceDetected; | ||
143 | }, | ||
144 | set: function(value) { | ||
145 | this._ioServiceDetected = value; | ||
146 | } | ||
147 | }, | ||
148 | //////////////////////////////////////////////////////////////////// | ||
149 | //Root API URL | ||
150 | _rootUrl: { | ||
151 | enumerable: false, | ||
152 | value: null | ||
153 | }, | ||
154 | //////////////////////////////////////////////////////////////////// | ||
155 | // | ||
156 | rootUrl: { | ||
157 | enumerable: false, | ||
158 | get: function() { | ||
159 | return this._rootUrl; | ||
160 | }, | ||
161 | set: function(value) { | ||
162 | this._rootUrl = window.localStorage["ioRootUrl"] = value; | ||
163 | } | ||
164 | }, | ||
165 | //////////////////////////////////////////////////////////////////// | ||
166 | //API service URL | ||
167 | _apiServiceURL: { | ||
168 | enumerable: false, | ||
169 | value: '/cloudstatus' | ||
170 | }, | ||
171 | //////////////////////////////////////////////////////////////////// | ||
172 | // | ||
173 | apiServiceURL: { | ||
174 | enumerable: false, | ||
175 | get: function() { | ||
176 | return String(this.rootUrl+this._apiServiceURL); | ||
177 | }, | ||
178 | set: function(value) { | ||
179 | this._apiServiceURL = value; | ||
180 | } | ||
181 | }, | ||
182 | //////////////////////////////////////////////////////////////////// | ||
183 | //File service API URL | ||
184 | _fileServiceURL: { | ||
185 | enumerable: false, | ||
186 | value: '/file' | ||
187 | }, | ||
188 | //////////////////////////////////////////////////////////////////// | ||
189 | // | ||
190 | fileServiceURL: { | ||
191 | enumerable: false, | ||
192 | get: function() { | ||
193 | return String(this.rootUrl+this._fileServiceURL); | ||
194 | }, | ||
195 | set: function(value) { | ||
196 | this._fileServiceURL = value; | ||
197 | } | ||
198 | }, | ||
199 | //////////////////////////////////////////////////////////////////// | ||
200 | //Directory service API URL | ||
201 | _directoryServiceURL: { | ||
202 | enumerable: false, | ||
203 | value: '/directory' | ||
204 | }, | ||
205 | //////////////////////////////////////////////////////////////////// | ||
206 | // | ||
207 | directoryServiceURL: { | ||
208 | enumerable: false, | ||
209 | get: function() { | ||
210 | return String(this.rootUrl+this._directoryServiceURL); | ||
211 | }, | ||
212 | set: function(value) { | ||
213 | this._directoryServiceURL = value; | ||
214 | } | ||
215 | }, | ||
216 | //////////////////////////////////////////////////////////////////// | ||
217 | // private helper to parse URIs and append them to the service URL | ||
218 | _prepareServiceURL: { | ||
219 | enumerable: false, | ||
220 | value: function(serviceURL, path) { | ||
221 | var urlOut = path.replace(/\\/g,"/"); | ||
222 | urlOut = urlOut.replace(/:/g,""); | ||
223 | urlOut = encodeURI(urlOut); | ||
224 | //add leading / if not already there | ||
225 | if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){ | ||
226 | urlOut = "/" + urlOut; | ||
227 | } | ||
228 | //remove extra / at the end | ||
229 | if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ | ||
230 | urlOut = urlOut.substring(0, (urlOut.length - 1)); | ||
231 | } | ||
232 | // | ||
233 | return String(serviceURL+urlOut); | ||
234 | } | ||
235 | }, | ||
236 | //////////////////////////////////////////////////////////////////// | ||
237 | //Method to check status of I/O API, will return false if not active | ||
238 | cloudAvailable: { | ||
239 | enumerable: false, | ||
240 | value: function () { | ||