diff options
Diffstat (limited to 'js/io/system/coreioapi.js')
-rwxr-xr-x | js/io/system/coreioapi.js | 1118 |
1 files changed, 1118 insertions, 0 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js new file mode 100755 index 00000000..3be6011d --- /dev/null +++ b/js/io/system/coreioapi.js | |||
@@ -0,0 +1,1118 @@ | |||
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 | // | ||
70 | this.chromeFileSystem.removeEventListener('library', this, false); | ||
71 | // | ||
72 | if (e._event.ninjaChromeLibrary.length < 1) { | ||
73 | console.log('no libraries'); | ||
74 | } else { | ||
75 | console.log('found libraries'); | ||
76 | } | ||
77 | } | ||
78 | }, | ||
79 | //////////////////////////////////////////////////////////////////// | ||
80 | // | ||
81 | _chromeNinjaLibrary: { | ||
82 | enumerable: false, | ||
83 | value: null | ||
84 | }, | ||
85 | //////////////////////////////////////////////////////////////////// | ||
86 | // | ||
87 | chromeNinjaLibrary: { | ||
88 | enumerable: false, | ||
89 | get: function() { | ||
90 | return this._chromeNinjaLibrary; | ||
91 | }, | ||
92 | set: function(value) { | ||
93 | this._chromeNinjaLibrary = value; | ||
94 | } | ||
95 | }, | ||
96 | //////////////////////////////////////////////////////////////////// | ||
97 | // | ||
98 | _chromeFileSystem: { | ||
99 | enumerable: false, | ||
100 | value: null | ||
101 | }, | ||
102 | //////////////////////////////////////////////////////////////////// | ||
103 | // | ||
104 | chromeFileSystem: { | ||
105 | enumerable: false, | ||
106 | get: function() { | ||
107 | return this._chromeFileSystem; | ||
108 | }, | ||
109 | set: function(value) { | ||
110 | this._chromeFileSystem = value; | ||
111 | } | ||
112 | }, | ||
113 | //////////////////////////////////////////////////////////////////// | ||
114 | // | ||
115 | _ioServiceDetected: { | ||
116 | enumerable: false, | ||
117 | value: false | ||
118 | }, | ||
119 | //////////////////////////////////////////////////////////////////// | ||
120 | //Checking for service availability on boot | ||
121 | ioServiceDetected: { | ||
122 | enumerable: false, | ||
123 | get: function() { | ||
124 | return this._ioServiceDetected; | ||
125 | }, | ||
126 | set: function(value) { | ||
127 | this._ioServiceDetected = value; | ||
128 | } | ||
129 | }, | ||
130 | //////////////////////////////////////////////////////////////////// | ||
131 | //Root API URL | ||
132 | _rootUrl: { | ||
133 | enumerable: false, | ||
134 | value: null | ||
135 | }, | ||
136 | //////////////////////////////////////////////////////////////////// | ||
137 | // | ||
138 | rootUrl: { | ||
139 | enumerable: false, | ||
140 | get: function() { | ||
141 | return this._rootUrl; | ||
142 | }, | ||
143 | set: function(value) { | ||
144 | this._rootUrl = window.localStorage["ioRootUrl"] = value; | ||
145 | } | ||
146 | }, | ||
147 | //////////////////////////////////////////////////////////////////// | ||
148 | //API service URL | ||
149 | _apiServiceURL: { | ||
150 | enumerable: false, | ||
151 | value: '/cloudstatus' | ||
152 | }, | ||
153 | //////////////////////////////////////////////////////////////////// | ||
154 | // | ||
155 | apiServiceURL: { | ||
156 | enumerable: false, | ||
157 | get: function() { | ||
158 | return String(this.rootUrl+this._apiServiceURL); | ||
159 | }, | ||
160 | set: function(value) { | ||
161 | this._apiServiceURL = value; | ||
162 | } | ||
163 | }, | ||
164 | //////////////////////////////////////////////////////////////////// | ||
165 | //File service API URL | ||
166 | _fileServiceURL: { | ||
167 | enumerable: false, | ||
168 | value: '/file' | ||
169 | }, | ||
170 | //////////////////////////////////////////////////////////////////// | ||
171 | // | ||
172 | fileServiceURL: { | ||
173 | enumerable: false, | ||
174 | get: function() { | ||
175 | return String(this.rootUrl+this._fileServiceURL); | ||
176 | }, | ||
177 | set: function(value) { | ||
178 | this._fileServiceURL = value; | ||
179 | } | ||
180 | }, | ||
181 | //////////////////////////////////////////////////////////////////// | ||
182 | //Directory service API URL | ||
183 | _directoryServiceURL: { | ||
184 | enumerable: false, | ||
185 | value: '/directory' | ||
186 | }, | ||
187 | //////////////////////////////////////////////////////////////////// | ||
188 | // | ||
189 | directoryServiceURL: { | ||
190 | enumerable: false, | ||
191 | get: function() { | ||
192 | return String(this.rootUrl+this._directoryServiceURL); | ||
193 | }, | ||
194 | set: function(value) { | ||
195 | this._directoryServiceURL = value; | ||
196 | } | ||
197 | }, | ||
198 | //////////////////////////////////////////////////////////////////// | ||
199 | // private helper to parse URIs and append them to the service URL | ||
200 | _prepareServiceURL: { | ||
201 | enumerable: false, | ||
202 | value: function(serviceURL, path) { | ||
203 | var urlOut = path.replace(/\\/g,"/"); | ||
204 | urlOut = urlOut.replace(/:/g,""); | ||
205 | urlOut = encodeURI(urlOut); | ||
206 | //add leading / if not already there | ||
207 | if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){ | ||
208 | urlOut = "/" + urlOut; | ||
209 | } | ||
210 | //remove extra / at the end | ||
211 | if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ | ||
212 | urlOut = urlOut.substring(0, (urlOut.length - 1)); | ||
213 | } | ||
214 | // | ||
215 | return String(serviceURL+urlOut); | ||
216 | } | ||
217 | }, | ||
218 | //////////////////////////////////////////////////////////////////// | ||
219 | //Method to check status of I/O API, will return false if not active | ||
220 | cloudAvailable: { | ||
221 | enumerable: false, | ||
222 | value: function () { | ||
223 | var cloud = this.getCloudStatus(); | ||
224 | // | ||
225 | if (this.rootUrl && cloud.status === 200) { | ||
226 | //Active | ||
227 | this.cloudData.name = cloud.response['name']; | ||
228 | this.cloudData.root = cloud.response['server-root']; | ||
229 | return true; | ||
230 | } else { | ||
231 | //Inactive | ||
232 | if (!this._cloudDialogOpen && this.application.ninja) { | ||
233 | this.showCloudDialog(); | ||
234 | } | ||
235 | return false; | ||
236 | } | ||
237 | } | ||
238 | }, | ||
239 | //////////////////////////////////////////////////////////////////// | ||
240 | // | ||
241 | _cloud |