diff options
Diffstat (limited to 'js/io/system')
-rwxr-xr-x | js/io/system/coreioapi.js | 111 | ||||
-rwxr-xr-x | js/io/system/fileio.js | 175 |
2 files changed, 222 insertions, 64 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index c99ebda7..5deeae73 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -7,7 +7,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
7 | /* ///////////////////////////////////////////////////////////////////// | 7 | /* ///////////////////////////////////////////////////////////////////// |
8 | //////////////////////////////////////////////////////////////////////// | 8 | //////////////////////////////////////////////////////////////////////// |
9 | NOTES: | 9 | NOTES: |
10 | These methods should only be access through the file and project IO classes. | ||
11 | //////////////////////////////////////////////////////////////////////// | 10 | //////////////////////////////////////////////////////////////////////// |
12 | ///////////////////////////////////////////////////////////////////// */ | 11 | ///////////////////////////////////////////////////////////////////// */ |
13 | var Montage = require("montage/core/core").Montage, | 12 | var Montage = require("montage/core/core").Montage, |
@@ -20,54 +19,64 @@ exports.CoreIoApi = Montage.create(Component, { | |||
20 | deserializedFromTemplate: { | 19 | deserializedFromTemplate: { |
21 | enumerable: false, | 20 | enumerable: false, |
22 | value: function () { | 21 | value: function () { |
23 | //////////////////////////////////////////////////////////// | 22 | //Checking for local storage of URL for IO |
24 | 23 | if (window.localStorage['ioRootUrl']) { | |
25 | //TODO: Add logic for getting rooUrl from local storage | 24 | //Getting URL from local storage |
26 | 25 | this.rootUrl = window.localStorage['ioRootUrl']; | |
27 | //////////////////////////////////////////////////////////// | 26 | //Checks for IO API to be active |
28 | 27 | this.ioServiceDetected = this.cloudAvailable(); | |
29 | 28 | // | |
30 | 29 | console.log('FileIO: localStorage URL detected | IO Service Detected: '+ this.ioServiceDetected); | |
31 | //Checking for status of I/O API | 30 | // |
32 | this.ioDetected = this.isActive(); | 31 | } else { |
33 | //TODO: Add welcome screen logic, probably externally | 32 | //TODO: Remove, automatically prompt user on welcome |
33 | this.rootUrl = 'http://localhost:16380'; | ||
34 | //TODO: Changed to false, welcome screen prompts user | ||
35 | this.ioServiceDetected = this.cloudAvailable(); | ||
36 | // | ||
37 | console.log('FileIO: localStorage URL NOT detected | IO Service Detected: '+ this.ioServiceDetected); | ||
38 | // | ||
39 | } | ||
34 | } | 40 | } |
35 | }, | 41 | }, |
36 | //////////////////////////////////////////////////////////////////// | 42 | //////////////////////////////////////////////////////////////////// |
37 | //Method to check status of I/O API, will return false if not active | 43 | //Method to check status of I/O API, will return false if not active |
38 | isActive: { | 44 | cloudAvailable: { |
39 | enumerable: false, | 45 | enumerable: false, |
40 | value: function () { | 46 | value: function () { |
41 | //Doing a directory root check, a 200 status means running | 47 | // |
42 | if (this.getDirectoryContents({uri:'/'}).status === 200) { | 48 | if (this.getCloudStatus().status === 200) { |
49 | //Active | ||
43 | return true; | 50 | return true; |
44 | } else { | 51 | } else { |
52 | //Inactive | ||
53 | //TODO: Logic to prompt the user for cloud, otherwise return false | ||
45 | return false; | 54 | return false; |
46 | } | 55 | } |
47 | } | 56 | } |
48 | }, | 57 | }, |
49 | //////////////////////////////////////////////////////////////////// | 58 | //////////////////////////////////////////////////////////////////// |
50 | //Root API URL | 59 | // |
51 | _ioDetected: { | 60 | _ioServiceDetected: { |
52 | enumerable: false, | 61 | enumerable: false, |
53 | value: false | 62 | value: false |
54 | }, | 63 | }, |
55 | //////////////////////////////////////////////////////////////////// | 64 | //////////////////////////////////////////////////////////////////// |
56 | // | 65 | //Checking for service availability on boot |
57 | ioDetected: { | 66 | ioServiceDetected: { |
58 | enumerable: false, | 67 | enumerable: false, |
59 | get: function() { | 68 | get: function() { |
60 | return this._ioDetected; | 69 | return this._ioServiceDetected; |
61 | }, | 70 | }, |
62 | set: function(value) { | 71 | set: function(value) { |
63 | this._ioDetected = value; | 72 | this._ioServiceDetected = value; |
64 | } | 73 | } |
65 | }, | 74 | }, |
66 | //////////////////////////////////////////////////////////////////// | 75 | //////////////////////////////////////////////////////////////////// |
67 | //Root API URL | 76 | //Root API URL |
68 | _rootUrl: { | 77 | _rootUrl: { |
69 | enumerable: false, | 78 | enumerable: false, |
70 | value: 'http://localhost:16380' | 79 | value: null |
71 | }, | 80 | }, |
72 | //////////////////////////////////////////////////////////////////// | 81 | //////////////////////////////////////////////////////////////////// |
73 | // | 82 | // |
@@ -77,7 +86,24 @@ exports.CoreIoApi = Montage.create(Component, { | |||
77 | return this._rootUrl; | 86 | return this._rootUrl; |
78 | }, | 87 | }, |
79 | set: function(value) { | 88 | set: function(value) { |
80 | this._rootUrl = value; | 89 | this._rootUrl = window.localStorage["ioRootUrl"] = value; |
90 | } | ||
91 | }, | ||
92 | //////////////////////////////////////////////////////////////////// | ||
93 | //API service URL | ||
94 | _apiServiceURL: { | ||
95 | enumerable: false, | ||
96 | value: '/cloudstatus' | ||
97 | }, | ||
98 | //////////////////////////////////////////////////////////////////// | ||
99 | // | ||
100 | apiServiceURL: { | ||
101 | enumerable: false, | ||
102 | get: function() { | ||
103 | return String(this.rootUrl+this._apiServiceURL); | ||
104 | }, | ||
105 | set: function(value) { | ||
106 | this._apiServiceURL = value; | ||
81 | } | 107 | } |
82 | }, | 108 | }, |
83 | //////////////////////////////////////////////////////////////////// | 109 | //////////////////////////////////////////////////////////////////// |
@@ -91,7 +117,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
91 | fileServiceURL: { | 117 | fileServiceURL: { |
92 | enumerable: false, | 118 | enumerable: false, |
93 | get: function() { | 119 | get: function() { |
94 | return this.rootUrl+this._fileServiceURL; | 120 | return String(this.rootUrl+this._fileServiceURL); |
95 | }, | 121 | }, |
96 | set: function(value) { | 122 | set: function(value) { |
97 | this._fileServiceURL = value; | 123 | this._fileServiceURL = value; |
@@ -108,7 +134,10 @@ exports.CoreIoApi = Montage.create(Component, { | |||
108 | directoryServiceURL: { | 134 | directoryServiceURL: { |
109 | enumerable: false, | 135 | enumerable: false, |
110 | get: function() { | 136 | get: function() { |
111 | return this.rootUrl+this._directoryServiceURL; | 137 | if(!this.rootUrl){ |
138 | this.rootUrl = 'http://localhost:16380'; | ||
139 | } | ||
140 | return String(this.rootUrl+this._directoryServiceURL); | ||
112 | }, | 141 | }, |
113 | set: function(value) { | 142 | set: function(value) { |
114 | this._directoryServiceURL = value; | 143 | this._directoryServiceURL = value; |
@@ -854,8 +883,38 @@ exports.CoreIoApi = Montage.create(Component, { | |||
854 | } | 883 | } |
855 | return retValue; | 884 | return retValue; |
856 | } | 885 | } |
886 | }, | ||
887 | //////////////////////////////////////////////////////////////////// | ||
888 | // | ||
889 | getCloudStatus: { | ||
890 | enumerable: false, | ||
891 | writable:false, | ||
892 | value: function() { | ||
893 | // | ||
894 | var retValue = {success:null, status:null}; | ||
895 | // | ||
896 | try { | ||
897 | var serviceURL = this._prepareServiceURL(this.apiServiceURL, '/'), | ||
898 | xhr = new XMLHttpRequest(); | ||
899 | // | ||
900 | xhr.open("GET", serviceURL, false); | ||
901 | xhr.send(); | ||
902 | // | ||
903 | if (xhr.readyState === 4) { | ||
904 | retValue.status = xhr.status; | ||
905 | retValue.success = true; | ||
906 | } | ||
907 | } | ||
908 | catch(error) { | ||
909 | xhr = null; | ||
910 | retValue.success = false; | ||
911 | } | ||
912 | // | ||
913 | return retValue; | ||
914 | } | ||
857 | } | 915 | } |
858 | 916 | //////////////////////////////////////////////////////////////////// | |
917 | //////////////////////////////////////////////////////////////////// | ||
859 | }); | 918 | }); |
860 | //////////////////////////////////////////////////////////////////////// | 919 | //////////////////////////////////////////////////////////////////////// |
861 | //////////////////////////////////////////////////////////////////////// \ No newline at end of file | 920 | //////////////////////////////////////////////////////////////////////// \ No newline at end of file |
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 1d76a91b..38ab05e8 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js | |||
@@ -3,22 +3,145 @@ 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/> | 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. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | /* ///////////////////////////////////////////////////////////////////// | ||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | NOTES: | ||
6 | 9 | ||
7 | //Required modules | 10 | For newFile, only the 'uri' is required, if contents is empty, such |
8 | var Serializer = require("montage/core/serializer").Serializer; | 11 | empty file will be created. 'contents' should be a string to be saved |
12 | as the file. 'contentType' is the mime type of the file. | ||
13 | |||
14 | //////////////////////////////////////////////////////////////////////// | ||
15 | ///////////////////////////////////////////////////////////////////// */ | ||
16 | // | ||
17 | var Montage = require("montage/core/core").Montage, | ||
18 | CoreIoApi = require("js/io/system/coreioapi").CoreIoApi; | ||
19 | //////////////////////////////////////////////////////////////////////// | ||
9 | //Exporting as File I/O | 20 | //Exporting as File I/O |
10 | exports.FileIo = (require("montage/core/core").Montage).create(Object.prototype, { | 21 | exports.FileIo = Montage.create(Object.prototype, { |
11 | /* | ||
12 | create: { | ||
13 | enumerable: true, | ||
14 | value: function (type) { | ||
15 | // | ||
16 | } | ||
17 |