diff options
Diffstat (limited to 'js/io/system')
-rw-r--r-- | js/io/system/config.xml | 6 | ||||
-rwxr-xr-x[-rw-r--r--] | js/io/system/coreioapi.js (renamed from js/io/system/shellapi.js) | 286 | ||||
-rwxr-xr-x[-rw-r--r--] | js/io/system/fileio.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | js/io/system/filesystem.js | 78 | ||||
-rwxr-xr-x[-rw-r--r--] | js/io/system/projectio.js | 0 |
5 files changed, 228 insertions, 142 deletions
diff --git a/js/io/system/config.xml b/js/io/system/config.xml deleted file mode 100644 index 4660d647..00000000 --- a/js/io/system/config.xml +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <!-- COPY TO 'MainApp/cloud' and set your own URLs --> | ||
3 | <services> | ||
4 | <file><![CDATA[http://file.services.ninja.motorola.com/]]></file> | ||
5 | <directory><![CDATA[http://directory.services.ninja.motorola.com/]]></directory> | ||
6 | </services> | ||
diff --git a/js/io/system/shellapi.js b/js/io/system/coreioapi.js index 9976dbed..1585fc33 100644..100755 --- a/js/io/system/shellapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -6,104 +6,113 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | /* ///////////////////////////////////////////////////////////////////// | 7 | /* ///////////////////////////////////////////////////////////////////// |
8 | //////////////////////////////////////////////////////////////////////// | 8 | //////////////////////////////////////////////////////////////////////// |
9 | NOTES: All logic should be handled in the FileSystem and I/O classes | 9 | NOTES: |
10 | 10 | These methods should only be access through the file and project IO classes. | |
11 | Dialog methods on NativeShellApp | ||
12 | ShowFileOpenDialog(initialDir) - shows a file open dialog | ||
13 | initialDir is optional and if specified will cause the dialog to initially display that directory as the open location | ||
14 | ShowFileSaveAsDialog(initialURI) - shows a file Save As dialog | ||
15 | initialURI is optional and if specified will cause the dialog to initially display the directory as the default location | ||
16 | and the filename as the current filename. | ||
17 | ShowSelectDirectoryDialog(initialDir, dialogTitle) - displays a directory select/chooser dialog | ||
18 | intitalDir is optional and specifies the directory that should be selected/shown when the dialog opens | ||
19 | dialogTitle is optional and specifies the title that should appear in the dialog caption | ||
20 | //////////////////////////////////////////////////////////////////////// | 11 | //////////////////////////////////////////////////////////////////////// |
21 | ///////////////////////////////////////////////////////////////////// */ | 12 | ///////////////////////////////////////////////////////////////////// */ |
13 | var Montage = require("montage/core/core").Montage, | ||
14 | Component = require("montage/ui/component").Component; | ||
15 | //////////////////////////////////////////////////////////////////////// | ||
22 | //Exporting as Project I/O | 16 | //Exporting as Project I/O |
23 | exports.ShellApi = (require("montage/core/core").Montage).create(require("montage/ui/component").Component, { | 17 | exports.CoreIoApi = Montage.create(Component, { |
24 | //////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////// |
25 | // | 19 | // |
26 | init: { | 20 | deserializedFromTemplate: { |
27 | enumerable: false, | 21 | enumerable: false, |
28 | value: function() { | 22 | value: function () { |
29 | try { | 23 | //////////////////////////////////////////////////////////// |
30 | var xhr = new XMLHttpRequest(), file, directory; | 24 | |
31 | // | 25 | //TODO: Add logic for getting rooUrl from local storage |
32 | xhr.open("GET", 'cloud/config.xml', false); | 26 | |
33 | xhr.send(); | 27 | //////////////////////////////////////////////////////////// |
34 | // | 28 | |
35 | if (xhr.readyState === 4) { | 29 | |
36 | file = xhr.responseXML.getElementsByTagName('file')[0].firstChild.nodeValue; | 30 | |
37 | directory = xhr.responseXML.getElementsByTagName('directory')[0].firstChild.nodeValue; | 31 | //Checking for status of I/O API |
38 | if (file.length) | 32 | this.ioDetected = this.isActive(); |
39 | this._fileServiceURL = file; | 33 | //TODO: Add welcome screen logic, probably externally |
40 | if (directory.length) | 34 | } |
41 | this._directoryServiceURL = directory; | 35 | }, |
42 | // | 36 | //////////////////////////////////////////////////////////////////// |
43 | //console.log(file, directory); | 37 | //Method to check status of I/O API, will return false if not active |
44 | } | 38 | isActive: { |
45 | } | 39 | enumerable: false, |
46 | catch(error) { | 40 | value: function () { |
47 | console.log(error); | 41 | //Doing a directory root check, a 200 status means running |
48 | } | 42 | if (this.getDirectoryContents({uri:'/'}).status === 200) { |
49 | } | 43 | return true; |
44 | } else { | ||
45 | return false; | ||
46 | } | ||
47 | } | ||
48 | }, | ||
49 | //////////////////////////////////////////////////////////////////// | ||
50 | //Root API URL | ||
51 | _ioDetected: { | ||
52 | enumerable: false, | ||
53 | value: false | ||
50 | }, | 54 | }, |
51 | //////////////////////////////////////////////////////////////////// | 55 | //////////////////////////////////////////////////////////////////// |
52 | // | 56 | // |
53 | openShellDialog: { | 57 | ioDetected: { |
54 | enumerable: false, | 58 | enumerable: false, |
55 | value: function(dialog) { | 59 | get: function() { |
56 | //Initializing return variable | 60 | return this._ioDetected; |
57 | var input = null; | 61 | }, |
58 | //Checking for the type of prompt set via object | 62 | set: function(value) { |
59 | switch (dialog.type) { | 63 | this._ioDetected = value; |
60 | case 'file': | 64 | } |
61 | //Checking for action the prompt will ask the user | 65 | }, |
62 | if (dialog.action.toLowerCase() == 'open') { | 66 | //////////////////////////////////////////////////////////////////// |
63 | //File open dialog | 67 | //Root API URL |
64 | input = window.NativeShellApp.ShowFileOpenDialog(); | 68 | _rootUrl: { |
65 | } else if (dialog.action.toLowerCase() == 'new') { | 69 | enumerable: false, |
66 | //File new dialog | 70 | value: 'http://localhost:16380' |
67 | input = window.NativeShellApp.ShowFileSaveAsDialog(); | ||
68 | } | ||
69 | break; | ||
70 | case 'directory': | ||
71 | //Checking for action the prompt will ask the user | ||
72 | if (dialog.action.toLowerCase() == 'open') { | ||
73 | //Directory open dialog | ||
74 | input = window.NativeShellApp.ShowSelectDirectoryDialog(); | ||
75 | } else if (dialog.action.toLowerCase() == 'new') { | ||
76 | //Directory new dialog | ||
77 | input = window.NativeShellApp.ShowSelectDirectoryDialog(); | ||
78 | } | ||
79 | break; | ||
80 | break; | ||
81 | default: | ||
82 | break; | ||
83 | } | ||
84 | return input; | ||
85 | } | ||
86 | }, | 71 | }, |
87 | //////////////////////////////////////////////////////////////////// | 72 | //////////////////////////////////////////////////////////////////// |
88 | // | 73 | // |
89 | startServer: { | 74 | rootUrl: { |
90 | enumerable: false, | 75 | enumerable: false, |
91 | value: function (dir) { | 76 | get: function() { |
92 | var server = window.NativeShellApp.StartWebServer(dir); | 77 | return this._rootUrl; |
93 | return server; | 78 | }, |
79 | set: function(value) { | ||
80 | this._rootUrl = value; | ||
94 | } | 81 | } |
95 | }, | 82 | }, |
96 | //////////////////////////////////////////////////////////////////// | 83 | //////////////////////////////////////////////////////////////////// |
97 | // private property containing the file service URL to use for all file IO calls | 84 | //File service API URL |
98 | _fileServiceURL: { | 85 | _fileServiceURL: { |
99 | enumerable: false, | 86 | enumerable: false, |
100 | value: "http://localhost:16380/file" //default value.. updated with base uri in config.xml | 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 | } | ||
101 | }, | 99 | }, |
102 | //////////////////////////////////////////////////////////////////// | 100 | //////////////////////////////////////////////////////////////////// |
103 | // private property containing the directory service URL to use for all file IO calls | 101 | //Directory service API URL |
104 | _directoryServiceURL: { | 102 | _directoryServiceURL: { |
105 | enumerable: false, | 103 | enumerable: false, |
106 | value: "http://localhost:16380/directory" //default value.. updated with base uri in config.xml | 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 | } | ||
107 | }, | 116 | }, |
108 | //////////////////////////////////////////////////////////////////// | 117 | //////////////////////////////////////////////////////////////////// |
109 | // 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 |
@@ -117,6 +126,11 @@ exports.ShellApi = (require("montage/core/core").Montage).create(require("montag | |||
117 | if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){ | 126 | if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){ |
118 | urlOut = "/" + urlOut; | 127 | urlOut = "/" + urlOut; |
119 | } | 128 | } |
129 | //remove extra / at the end | ||
130 | if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ | ||
131 | urlOut = urlOut.substring(0, (urlOut.length - 1)); | ||
132 | } | ||
133 | |||
120 | return serviceURL + urlOut; | 134 | return serviceURL + urlOut; |
121 | } | 135 | } |
122 | }, | 136 | }, |
@@ -141,7 +155,7 @@ exports.ShellApi = (require("montage/core/core").Montage).create(require("montag | |||
141 | // | 155 | // |
142 | if(file && file.uri && file.uri.length) { | 156 | if(file && file.uri && file.uri.length) { |
143 | try { | 157 | try { |
144 | var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), | 158 | var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), |
145 | xhr = new XMLHttpRequest(); | 159 | xhr = new XMLHttpRequest(); |
146 | // | 160 | // |
147 | xhr.open("GET", serviceURL, false); | 161 | xhr.open("GET", serviceURL, false); |
@@ -184,7 +198,7 @@ exports.ShellApi = (require("montage/core/core").Montage).create(require("montag | |||
184 | var retValue = { success:null, status:null }; | 198 | var retValue = { success:null, status:null }; |
185 | if(file && file.uri && file.uri.length) { | 199 | if(file && f |