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