diff options
Diffstat (limited to 'js/io/system/coreioapi.js')
-rwxr-xr-x | js/io/system/coreioapi.js | 127 |
1 files changed, 107 insertions, 20 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index c920d8cd..1585fc33 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -16,16 +16,103 @@ var Montage = require("montage/core/core").Montage, | |||
16 | //Exporting as Project I/O | 16 | //Exporting as Project I/O |
17 | exports.CoreIoApi = Montage.create(Component, { | 17 | exports.CoreIoApi = Montage.create(Component, { |
18 | //////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////// |
19 | // private property containing the file service URL to use for all file IO calls | 19 | // |
20 | deserializedFromTemplate: { | ||
21 | enumerable: false, | ||
22 | value: function () { | ||
23 | //////////////////////////////////////////////////////////// | ||
24 | |||
25 | //TODO: Add logic for getting rooUrl from local storage | ||
26 | |||
27 | //////////////////////////////////////////////////////////// | ||
28 | |||
29 | |||
30 | |||
31 | //Checking for status of I/O API | ||
32 | this.ioDetected = this.isActive(); | ||
33 | //TODO: Add welcome screen logic, probably externally | ||
34 | } | ||
35 | }, | ||
36 | //////////////////////////////////////////////////////////////////// | ||
37 | //Method to check status of I/O API, will return false if not active | ||
38 | isActive: { | ||
39 | enumerable: false, | ||
40 | value: function () { | ||
41 | //Doing a directory root check, a 200 status means running | ||
42 | if (this.getDirectoryContents({uri:'/'}).status === 200) { | ||
43 | return true; | ||
44 | } else { | ||
45 | return false; | ||
46 | } | ||
47 | } | ||
48 | }, | ||
49 | //////////////////////////////////////////////////////////////////// | ||
50 | //Root API URL | ||
51 | _ioDetected: { | ||
52 | enumerable: false, | ||
53 | value: false | ||
54 | }, | ||
55 | //////////////////////////////////////////////////////////////////// | ||
56 | // | ||
57 | ioDetected: { | ||
58 | enumerable: false, | ||
59 | get: function() { | ||
60 | return this._ioDetected; | ||
61 | }, | ||
62 | set: function(value) { | ||
63 | this._ioDetected = value; | ||
64 | } | ||
65 | }, | ||
66 | //////////////////////////////////////////////////////////////////// | ||
67 | //Root API URL | ||
68 | _rootUrl: { | ||
69 | enumerable: false, | ||
70 | value: 'http://localhost:16380' | ||
71 | }, | ||
72 | //////////////////////////////////////////////////////////////////// | ||
73 | // | ||
74 | rootUrl: { | ||
75 | enumerable: false, | ||
76 | get: function() { | ||
77 | return this._rootUrl; | ||
78 | }, | ||
79 | set: function(value) { | ||
80 | this._rootUrl = value; | ||
81 | } | ||
82 | }, | ||
83 | //////////////////////////////////////////////////////////////////// | ||
84 | //File service API URL | ||
20 | _fileServiceURL: { | 85 | _fileServiceURL: { |
21 | enumerable: false, | 86 | enumerable: false, |
22 | value: "http://localhost:16380/file" | 87 | value: '/file' |
88 | }, | ||
89 | //////////////////////////////////////////////////////////////////// | ||
90 | // | ||
91 | fileServiceURL: { | ||
92 | enumerable: false, | ||
93 | get: function() { | ||
94 | return this.rootUrl+this._fileServiceURL; | ||
95 | }, | ||
96 | set: function(value) { | ||
97 | this._fileServiceURL = value; | ||
98 | } | ||
23 | }, | 99 | }, |
24 | //////////////////////////////////////////////////////////////////// | 100 | //////////////////////////////////////////////////////////////////// |
25 | // private property containing the directory service URL to use for all file IO calls | 101 | //Directory service API URL |
26 | _directoryServiceURL: { | 102 | _directoryServiceURL: { |
27 | enumerable: false, | 103 | enumerable: false, |
28 | value: "http://localhost:16380/directory" | 104 | value: '/directory' |
105 | }, | ||
106 | //////////////////////////////////////////////////////////////////// | ||
107 | // | ||
108 | directoryServiceURL: { | ||
109 | enumerable: false, | ||
110 | get: function() { | ||
111 | return this.rootUrl+this._directoryServiceURL; | ||
112 | }, | ||
113 | set: function(value) { | ||
114 | this._directoryServiceURL = value; | ||
115 | } | ||
29 | }, | 116 | }, |
30 | //////////////////////////////////////////////////////////////////// | 117 | //////////////////////////////////////////////////////////////////// |
31 | // private helper to parse URIs and append them to the service URL | 118 | // private helper to parse URIs and append them to the service URL |
@@ -68,7 +155,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
68 | // | 155 | // |
69 | if(file && file.uri && file.uri.length) { | 156 | if(file && file.uri && file.uri.length) { |
70 | try { | 157 | try { |
71 | var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), | 158 | var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), |
72 | xhr = new XMLHttpRequest(); | 159 | xhr = new XMLHttpRequest(); |
73 | // | 160 | // |
74 | xhr.open("GET", serviceURL, false); | 161 | xhr.open("GET", serviceURL, false); |
@@ -111,7 +198,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
111 | var retValue = { success:null, status:null }; | 198 | var retValue = { success:null, status:null }; |
112 | if(file && file.uri && file.uri.length) { | 199 | if(file && file.uri && file.uri.length) { |
113 | try { | 200 | try { |
114 | var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), | 201 | var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), |
115 | xhr = new XMLHttpRequest(); | 202 | xhr = new XMLHttpRequest(); |
116 | // | 203 | // |
117 | xhr.open("POST", serviceURL, false); | 204 | xhr.open("POST", serviceURL, false); |
@@ -161,7 +248,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
161 | var retValue = { success:null, status:null }; | 248 | var retValue = { success:null, status:null }; |
162 | if(file && file.uri && file.uri.length && file.contents && file.contents.length) { | 249 | if(file && file.uri && file.uri.length && file.contents && file.contents.length) { |
163 | try { | 250 | try { |
164 | var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), | 251 | var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), |
165 | xhr = new XMLHttpRequest(); | 252 | xhr = new XMLHttpRequest(); |
166 | // | 253 | // |
167 | xhr.open("PUT", serviceURL, false); | 254 | xhr.open("PUT", serviceURL, false); |
@@ -208,7 +295,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
208 | var retValue = { success:null, status:null }; | 295 | var retValue = { success:null, status:null }; |
209 | if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) { | 296 | if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) { |
210 | try { | 297 | try { |
211 | var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.destUri), | 298 | var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.destUri), |
212 | xhr = new XMLHttpRequest(); | 299 | xhr = new XMLHttpRequest(); |
213 | // | 300 | // |
214 | xhr.open("PUT", serviceURL, false); | 301 | xhr.open("PUT", serviceURL, false); |
@@ -256,7 +343,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
256 | var retValue = { success:null, status:null }; | 343 | var retValue = { success:null, status:null }; |
257 | if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) { | 344 | if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) { |
258 | try { | 345 | try { |
259 | var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.destUri), | 346 | var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.destUri), |
260 | xhr = new XMLHttpRequest(); | 347 | xhr = new XMLHttpRequest(); |
261 | // | 348 | // |
262 | xhr.open("PUT", serviceURL, false); | 349 | xhr.open("PUT", serviceURL, false); |
@@ -302,7 +389,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
302 | var retValue = { success:null, status:null }; | 389 | var retValue = { success:null, status:null }; |
303 | if(file && file.uri && file.uri.length) { | 390 | if(file && file.uri && file.uri.length) { |
304 | try { | 391 | try { |
305 | var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), | 392 | var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), |
306 | xhr = new XMLHttpRequest(); | 393 | xhr = new XMLHttpRequest(); |
307 | // | 394 | // |
308 | xhr.open("DELETE", serviceURL, false); | 395 | xhr.open("DELETE", serviceURL, false); |
@@ -344,7 +431,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
344 | // | 431 | // |
345 | if(file && file.uri && file.uri.length) { | 432 | if(file && file.uri && file.uri.length) { |
346 | try { | 433 | try { |
347 | var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), | 434 | var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), |
348 | xhr = new XMLHttpRequest(); | 435 | xhr = new XMLHttpRequest(); |
349 | // | 436 | // |
350 | xhr.open("GET", serviceURL, false); | 437 | xhr.open("GET", serviceURL, false); |
@@ -386,7 +473,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
386 | var retValue = { success:null, status:null }; | 473 | var retValue = { success:null, status:null }; |
387 | if(dir && dir.uri && dir.uri.length) { | 474 | if(dir && dir.uri && dir.uri.length) { |
388 | try { | 475 | try { |
389 | var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri), | 476 | var serviceURL = this._prepareServiceURL(this.directoryServiceURL, dir.uri), |
390 | xhr = new XMLHttpRequest(); | 477 | xhr = new XMLHttpRequest(); |
391 | // | 478 | // |
392 | xhr.open("POST", serviceURL, false); | 479 | xhr.open("POST", serviceURL, false); |
@@ -425,7 +512,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
425 | var retValue = { success:null, status:null }; | 512 | var retValue = { success:null, status:null }; |
426 | if(dir && dir.uri && dir.uri.length) { | 513 | if(dir && dir.uri && dir.uri.length) { |
427 | try { | 514 | try { |
428 | var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri), | 515 | var serviceURL = this._prepareServiceURL(this.directoryServiceURL, dir.uri), |
429 | xhr = new XMLHttpRequest(); | 516 | xhr = new XMLHttpRequest(); |
430 | // | 517 | // |
431 | xhr.open("DELETE", serviceURL, false); | 518 | xhr.open("DELETE", serviceURL, false); |
@@ -468,7 +555,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
468 | var retValue = { success:null, content:null, status:null }; | 555 | var retValue = { success:null, content:null, status:null }; |
469 | if(!!dir && (typeof dir.uri !== "undefined") && (dir.uri !== null) ) { | 556 | if(!!dir && (typeof dir.uri !== "undefined") && (dir.uri !== null) ) { |
470 | try { | 557 | try { |
471 | var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri), | 558 | var serviceURL = this._prepareServiceURL(this.directoryServiceURL, dir.uri), |
472 | xhr = new XMLHttpRequest(); | 559 | xhr = new XMLHttpRequest(); |
473 | // | 560 | // |
474 | xhr.open("GET", serviceURL, false); | 561 | xhr.open("GET", serviceURL, false); |
@@ -526,7 +613,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
526 | var retValue = { success:null, content:null, status:null }; | 613 | var retValue = { success:null, content:null, status:null }; |