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