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.js1022
1 files changed, 1022 insertions, 0 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js
new file mode 100755
index 00000000..4407d59a
--- /dev/null
+++ b/js/io/system/coreioapi.js
@@ -0,0 +1,1022 @@
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///////////////////////////////////////////////////////////////////// */
12var Montage = require("montage/core/core").Montage,
13 Component = require("montage/ui/component").Component,
14 Popup = require("js/components/popup.reel").Popup,
15 CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup;
16////////////////////////////////////////////////////////////////////////
17//Exporting as Project I/O
18exports.CoreIoApi = Montage.create(Component, {
19 ////////////////////////////////////////////////////////////////////
20 //
21 deserializedFromTemplate: {
22 enumerable: false,
23 value: function () {
24 //Checking for local storage of URL for IO
25 if (window.localStorage['ioRootUrl']) {
26 //Getting URL from local storage
27 this.rootUrl = window.localStorage['ioRootUrl'];
28 //Checks for IO API to be active
29 this.ioServiceDetected = this.cloudAvailable();
30 //
31 console.log('Cloud Status: URL detected in localStorage as '+this.rootUrl);
32 } else {
33 //
34 this.ioServiceDetected = false;
35 console.log('Cloud Status: No URL detected in localStorage');
36 }
37 }
38 },
39 ////////////////////////////////////////////////////////////////////
40 //Method to check status of I/O API, will return false if not active
41 cloudAvailable: {
42 enumerable: false,
43 value: function () {
44 //
45 if (this.rootUrl && this.getCloudStatus().status === 200) {
46 //Active
47 return true;
48 } else {
49 //Inactive
50 if (!this._cloudDialogOpen || this.application.ninja) {
51 this.showCloudDialog();
52 }
53 return false;
54 }
55 }
56 },
57 ////////////////////////////////////////////////////////////////////
58 //
59 _cloudDialogOpen: {
60 enumerable: false,
61 value: false
62 },
63 ////////////////////////////////////////////////////////////////////
64 //
65 _cloudDialogComponents: {
66 enumerable: false,
67 value: {blackout: null, popup: null, dialog: null}
68 },
69 ////////////////////////////////////////////////////////////////////
70 //
71 showCloudDialog: {
72 enumerable: false,
73 value: function () {
74 //
75 this._cloudDialogComponents.blackout = document.createElement('div');
76 this._cloudDialogComponents.blackout.style.width = '100%';
77 this._cloudDialogComponents.blackout.style.height = '100%';
78 this._cloudDialogComponents.blackout.style.background = 'rgba(0, 0, 0, .6)';
79 this.application.ninja.popupManager.addPopup(this._cloudDialogComponents.blackout);
80 //
81 ////////////////////////////////////////////////////
82 //Creating popup from m-js component
83 var popup = document.createElement('div');
84 //
85 this._cloudDialogComponents.dialog = CloudPopup.create();
86 //
87 document.body.appendChild(popup);
88 //
89 this._cloudDialogComponents.dialog.element = popup;
90 this._cloudDialogComponents.dialog.needsDraw = true;
91 this._cloudDialogComponents.dialog.element.style.opacity = 0;
92 //
93 this._cloudDialogComponents.dialog.addEventListener('firstDraw', this, false);
94 }
95 },
96
97 handleFirstDraw: {
98 value: function (e) {
99 if (e._target._element.className === 'cloud_popup') {
100 this._cloudDialogComponents.dialog.removeEventListener('firstDraw', this, false);
101 //
102 this._cloudDialogComponents.popup = this.application.ninja.popupManager.createPopup(this._cloudDialogComponents.dialog.element, {x: '200px', y: '200px'});
103 this._cloudDialogComponents.popup.addEventListener('firstDraw', this, false);
104 } else {
105 //
106 this._cloudDialogComponents.dialog.element.style.opacity = 1;
107 this._cloudDialogComponents.popup.element.style.opacity = 1;
108 }
109 }
110 },
111
112
113 ////////////////////////////////////////////////////////////////////
114 //
115 hideCloudDialog: {
116 enumerable: false,
117 value: function () {
118 }
119 },
120 ////////////////////////////////////////////////////////////////////
121 //
122 _ioServiceDetected: {
123 enumerable: false,
124 value: false
125 },
126 ////////////////////////////////////////////////////////////////////
127 //Checking for service availability on boot
128 ioServiceDetected: {
129 enumerable: false,
130 get: function() {
131 return this._ioServiceDetected;
132 },
133 set: function(value) {
134 this._ioServiceDetected = value;
135 }
136 },
137 ////////////////////////////////////////////////////////////////////
138 //Root API URL
139 _rootUrl: {
140 enumerable: false,
141 value: null
142 },
143 ////////////////////////////////////////////////////////////////////
144 //
145 rootUrl: {
146 enumerable: false,
147 get: function() {
148 return this._rootUrl;
149 },
150 set: function(value) {
151 this._rootUrl = window.localStorage["ioRootUrl"] = value;
152 }
153 },
154 ////////////////////////////////////////////////////////////////////
155 //API service URL
156 _apiServiceURL: {
157 enumerable: false,
158 value: '/cloudstatus'
159 },
160 ////////////////////////////////////////////////////////////////////
161 //
162 apiServiceURL: {
163 enumerable: false,
164 get: function() {
165 return String(this.rootUrl+this._apiServiceURL);
166 },
167 set: function(value) {
168 this._apiServiceURL = value;
169 }
170 },
171 ////////////////////////////////////////////////////////////////////
172 //File service API URL
173 _fileServiceURL: {
174 enumerable: false,
175 value: '/file'
176 },
177 ////////////////////////////////////////////////////////////////////
178 //
179 fileServiceURL: {
180 enumerable: false,
181 get: function() {
182 return String(this.rootUrl+this._fileServiceURL);
183 },
184 set: function(value) {
185 this._fileServiceURL = value;
186 }
187 },
188 ////////////////////////////////////////////////////////////////////
189 //Directory service API URL
190 _directoryServiceURL: {
191 enumerable: false,
192 value: '/directory'
193 },
194 ////////////////////////////////////////////////////////////////////
195 //
196 directoryServiceURL: {
197 enumerable: false,
198 get: function() {
199 return String(this.rootUrl+this._directoryServiceURL);
200 },
201 set: function(value) {
202 this._directoryServiceURL = value;
203 }
204 },
205 ////////////////////////////////////////////////////////////////////
206 // private helper to parse URIs and append them to the service URL
207 _prepareServiceURL: {
208 enumerable: false,
209 value: function(serviceURL, path) {
210 var urlOut = path.replace(/\\/g,"/");
211 urlOut = urlOut.replace(/:/g,"");
212 urlOut = encodeURI(urlOut);
213 //add leading / if not already there
214 if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){
215 urlOut = "/" + urlOut;
216 }
217 //remove extra / at the end
218 if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){
219 urlOut = urlOut.substring(0, (urlOut.length - 1));
220 }
221
222 return serviceURL + urlOut;
223 }
224 },
225 ////////////////////////////////////////////////////////////////////
226 // Checks for the existence of a file
227 // Parameters:
228 // the file parameter must contain the following properties
229 // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html"
230 //
231 // Return values:
232 // returns an object with two properties
233 // success: boolean indicating if the call succeeded or failed
234 // status: int indicating the request HTTP status code
235 // 204 - the file exists
236 // 404 - the file does not exist
237 // 500 - unknown server error occurred
238 fileExists: {