diff options
Diffstat (limited to 'js/io/system/coreioapi.js')
-rwxr-xr-x | js/io/system/coreioapi.js | 1027 |
1 files changed, 1027 insertions, 0 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js new file mode 100755 index 00000000..6b803f22 --- /dev/null +++ b/js/io/system/coreioapi.js | |||
@@ -0,0 +1,1027 @@ | |||
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 | ///////////////////////////////////////////////////////////////////// */ | ||
12 | var 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 | ||
18 | exports.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._cloudDialogOpen = true; | ||
76 | // | ||
77 | this._cloudDialogComponents.blackout = document.createElement('div'); | ||
78 | this._cloudDialogComponents.blackout.style.width = '100%'; | ||
79 | this._cloudDialogComponents.blackout.style.height = '100%'; | ||
80 | this._cloudDialogComponents.blackout.style.background = '-webkit-radial-gradient(center, ellipse cover, rgba(0,0,0,.65) 0%, rgba(0,0,0,0.8) 80%)'; | ||
81 | this.application.ninja.popupManager.addPopup(this._cloudDialogComponents.blackout); | ||
82 | // | ||
83 | //////////////////////////////////////////////////// | ||
84 | //Creating popup from m-js component | ||
85 | var popup = document.createElement('div'); | ||
86 | // | ||
87 | this._cloudDialogComponents.dialog = CloudPopup.create(); | ||
88 | // | ||
89 | document.body.appendChild(popup); | ||
90 | // | ||
91 | this._cloudDialogComponents.dialog.element = popup; | ||
92 | this._cloudDialogComponents.dialog.needsDraw = true; | ||
93 | this._cloudDialogComponents.dialog.element.style.opacity = 0; | ||
94 | // | ||
95 | this._cloudDialogComponents.dialog.addEventListener('firstDraw', this, false); | ||
96 | } | ||
97 | }, | ||
98 | //////////////////////////////////////////////////////////////////// | ||
99 | // | ||
100 | handleFirstDraw: { | ||
101 | value: function (e) { | ||
102 | if (e._target._element.className === 'cloud_popup') { | ||
103 | this._cloudDialogComponents.dialog.removeEventListener('firstDraw', this, false); | ||
104 | // | ||
105 | this._cloudDialogComponents.popup = this.application.ninja.popupManager.createPopup(this._cloudDialogComponents.dialog.element, {x: '50%', y: '50%'}); | ||
106 | this._cloudDialogComponents.popup.addEventListener('firstDraw', this, false); | ||
107 | } else { | ||
108 | // | ||
109 | this._cloudDialogComponents.dialog.element.style.opacity = 1; | ||
110 | this._cloudDialogComponents.popup.element.style.opacity = 1; | ||
111 | this._cloudDialogComponents.popup.element.style.margin = '-100px 0px 0px -190px'; | ||
112 | } | ||
113 | } | ||
114 | }, | ||
115 | //////////////////////////////////////////////////////////////////// | ||
116 | // | ||
117 | hideCloudDialog: { | ||
118 | enumerable: false, | ||
119 | value: function () { | ||
120 | // | ||
121 | this.application.ninja.popupManager.removePopup(this._cloudDialogComponents.blackout); | ||
122 | this.application.ninja.popupManager.removePopup(this._cloudDialogComponents.popup.element); | ||
123 | } | ||
124 | }, | ||
125 | //////////////////////////////////////////////////////////////////// | ||
126 | // | ||
127 | _ioServiceDetected: { | ||
128 | enumerable: false, | ||
129 | value: false | ||
130 | }, | ||
131 | //////////////////////////////////////////////////////////////////// | ||
132 | //Checking for service availability on boot | ||
133 | ioServiceDetected: { | ||
134 | enumerable: false, | ||
135 | get: function() { | ||
136 | return this._ioServiceDetected; | ||
137 | }, | ||
138 | set: function(value) { | ||
139 | this._ioServiceDetected = value; | ||
140 | } | ||
141 | }, | ||
142 | //////////////////////////////////////////////////////////////////// | ||
143 | //Root API URL | ||
144 | _rootUrl: { | ||
145 | enumerable: false, | ||
146 | value: null | ||
147 | }, | ||
148 | //////////////////////////////////////////////////////////////////// | ||
149 | // | ||
150 | rootUrl: { | ||
151 | enumerable: false, | ||
152 | get: function() { | ||
153 | return this._rootUrl; | ||
154 | }, | ||
155 | set: function(value) { | ||
156 | this._rootUrl = window.localStorage["ioRootUrl"] = value; | ||
157 | } | ||
158 | }, | ||
159 | //////////////////////////////////////////////////////////////////// | ||
160 | //API service URL | ||
161 | _apiServiceURL: { | ||
162 | enumerable: false, | ||
163 | value: '/cloudstatus' | ||
164 | }, | ||
165 | //////////////////////////////////////////////////////////////////// | ||
166 | // | ||
167 | apiServiceURL: { | ||
168 | enumerable: false, | ||
169 | get: function() { | ||
170 | return String(this.rootUrl+this._apiServiceURL); | ||
171 | }, | ||
172 | set: function(value) { | ||
173 | this._apiServiceURL = value; | ||
174 | } | ||
175 | }, | ||
176 | //////////////////////////////////////////////////////////////////// | ||
177 | //File service API URL | ||
178 | _fileServiceURL: { | ||
179 | enumerable: false, | ||
180 | value: '/file' | ||
181 | }, | ||
182 | //////////////////////////////////////////////////////////////////// | ||
183 | // | ||
184 | fileServiceURL: { | ||
185 | enumerable: false, | ||
186 | get: function() { | ||
187 | return String(this.rootUrl+this._fileServiceURL); | ||
188 | }, | ||
189 | set: function(value) { | ||
190 | this._fileServiceURL = value; | ||
191 | } | ||
192 | }, | ||
193 | //////////////////////////////////////////////////////////////////// | ||
194 | //Directory service API URL | ||
195 | _directoryServiceURL: { | ||
196 | enumerable: false, | ||
197 | value: '/directory' | ||
198 | }, | ||
199 | //////////////////////////////////////////////////////////////////// | ||
200 | // | ||
201 | directoryServiceURL: { | ||
202 | enumerable: false, | ||
203 | get: function() { | ||
204 | return String(this.rootUrl+this._directoryServiceURL); | ||
205 | }, | ||
206 | set: function(value) { | ||
207 | this._directoryServiceURL = value; | ||
208 | } | ||
209 | }, | ||
210 | //////////////////////////////////////////////////////////////////// | ||
211 | // private helper to parse URIs and append them to the service URL | ||
212 | _prepareServiceURL: { | ||
213 | enumerable: false, | ||
214 | value: function(serviceURL, path) { | ||
215 | var urlOut = path.replace(/\\/g,"/"); | ||
216 | urlOut = urlOut.replace(/:/g,""); | ||
217 | urlOut = encodeURI(urlOut); | ||
218 | //add leading / if not already there | ||
219 | if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){ | ||
220 | urlOut = "/" + urlOut; | ||
221 | } | ||
222 | //remove extra / at the end | ||
223 | if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ | ||
224 | urlOut = urlOut.substring(0, (urlOut.length - 1)); | ||
225 | } | ||
226 | |||
227 | return serviceURL + urlOut; | ||
228 | } | ||
229 | }, | ||
230 | //////////////////////////////////////////////////////////////////// | ||
231 | // Checks for the existence of a file | ||
232 | // Parameters: | ||
233 | // the file parameter must contain the following properties | ||
234 | // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html" | ||
235 | // | ||
236 | // Return values: | ||
237 | // returns an object with two properties |