aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/coreioapi.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-15 17:04:39 -0800
committerValerio Virgillito2012-02-15 17:04:39 -0800
commitfe71cb9aa1700199c0089166ad54fc56eb760644 (patch)
treeb0c7c24b1f45a079e1c09312ca716e3d35aecad4 /js/io/system/coreioapi.js
parent747616980cad14f0b65fbcc7f497ed9680a39d29 (diff)
parentd366c0bd1af6471511217ed574083e15059519b5 (diff)
downloadninja-fe71cb9aa1700199c0089166ad54fc56eb760644.tar.gz
Merge branch 'refs/heads/master' into components
Diffstat (limited to 'js/io/system/coreioapi.js')
-rwxr-xr-xjs/io/system/coreioapi.js1146
1 files changed, 1146 insertions, 0 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js
new file mode 100755
index 00000000..ea9627cc
--- /dev/null
+++ b/js/io/system/coreioapi.js
@@ -0,0 +1,1146 @@
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 /*
96window.hack = function (name, type) {
97 this.application.ninja.ioMediator.fileNew('Users/kgq387/Desktop/Ninja Cloud/Disk/'+name+'.'+type, '/js/io/templates/files/'+type+'.txt', function (status) {console.log(status)});
98 }.bind(this);
99*/
100 window.hack = function (path) {
101 //
102 this.application.ninja.ioMediator.fileOpen('Users/kgq387/Desktop/Ninja Cloud/Disk/'+path, function (result) {console.log(result)});
103 }.bind(this);
104 }
105 },
106 ////////////////////////////////////////////////////////////////////
107 //
108 _chromeNinjaLibrary: {
109 enumerable: false,
110 value: null
111 },
112 ////////////////////////////////////////////////////////////////////
113 //
114 chromeNinjaLibrary: {
115 enumerable: false,
116 get: function() {
117 return this._chromeNinjaLibrary;
118 },
119 set: function(value) {
120 this._chromeNinjaLibrary = value;
121 }
122 },
123 ////////////////////////////////////////////////////////////////////
124 //
125 _chromeFileSystem: {
126 enumerable: false,
127 value: null
128 },
129 ////////////////////////////////////////////////////////////////////
130 //
131 chromeFileSystem: {
132 enumerable: false,
133 get: function() {
134 return this._chromeFileSystem;
135 },
136 set: function(value) {
137 this._chromeFileSystem = value;
138 }
139 },
140 ////////////////////////////////////////////////////////////////////
141 //
142 _ioServiceDetected: {
143 enumerable: false,
144 value: false
145 },
146 ////////////////////////////////////////////////////////////////////
147 //Checking for service availability on boot
148 ioServiceDetected: {
149 enumerable: false,
150 get: function() {
151 return this._ioServiceDetected;
152 },
153 set: function(value) {
154 this._ioServiceDetected = value;
155 }
156 },
157 ////////////////////////////////////////////////////////////////////
158 //Root API URL
159 _rootUrl: {
160 enumerable: false,
161 value: null
162 },
163 ////////////////////////////////////////////////////////////////////
164 //
165 rootUrl: {
166 enumerable: false,
167 get: function() {
168 return this._rootUrl;
169 },
170 set: function(value) {
171 this._rootUrl = window.localStorage["ioRootUrl"] = value;
172 }
173 },
174 ////////////////////////////////////////////////////////////////////
175 //API service URL
176 _apiServiceURL: {
177 enumerable: false,
178 value: '/cloudstatus'
179 },
180 ////////////////////////////////////////////////////////////////////
181 //
182 apiServiceURL: {
183 enumerable: false,
184 get: function() {
185 return String(this.rootUrl+this._apiServiceURL);
186 },
187 set: function(value) {
188 this._apiServiceURL = value;
189 }
190 },
191 ////////////////////////////////////////////////////////////////////
192 //File service API URL
193 _fileServiceURL: {
194 enumerable: false,
195 value: '/file'
196 },
197 ////////////////////////////////////////////////////////////////////
198 //
199 fileServiceURL: {
200 enumerable: false,
201 get: function() {
202 return String(this.rootUrl+this._fileServiceURL);
203 },
204 set: function(value) {
205 this._fileServiceURL = value;
206 }
207 },
208 ////////////////////////////////////////////////////////////////////
209 //Directory service API URL
210 _directoryServiceURL: {
211 enumerable: false,
212 value: '/directory'
213 },
214 ////////////////////////////////////////////////////////////////////
215 //
216 directoryServiceURL: {
217 enumerable: false,
218 get: function() {
219 return String(this.rootUrl+this._directoryServiceURL);
220 },
221 set: function(value) {
222 this._directoryServiceURL = value;
223 }
224 },
225 ////////////////////////////////////////////////////////////////////
226 // private helper to parse URIs and append them to the service URL
227 _prepareServiceURL: {
228 enumerable: false,
229 value: function(serviceURL, path) {
230 var urlOut = path.replace(/\\/g,"/");
231 urlOut = urlOut.replace(/:/g,"");
232 urlOut = encodeURI(urlOut);
233 //add leading / if not already there