diff options
author | Jose Antonio Marquez | 2012-02-09 15:02:16 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-09 15:02:16 -0800 |
commit | 74efc1238f51e9c0ffdeffe2a349f66011ef9f17 (patch) | |
tree | e50598ebfe139b7cda4a3ff9702d7d3243cbd6b2 /js/io | |
parent | 44c65bc6bbd5b754f9073f93a3afca8dd9acc864 (diff) | |
download | ninja-74efc1238f51e9c0ffdeffe2a349f66011ef9f17.tar.gz |
File Open
Adding file open functionality.
Diffstat (limited to 'js/io')
-rwxr-xr-x | js/io/system/coreioapi.js | 10 | ||||
-rwxr-xr-x | js/io/system/fileio.js | 68 |
2 files changed, 73 insertions, 5 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index d9505cd6..f62133ac 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -92,9 +92,15 @@ exports.CoreIoApi = Montage.create(Component, { | |||
92 | //TODO: Remove test | 92 | //TODO: Remove test |
93 | //this.ninjaLibrary.copyLibToCloud('Users/kgq387/Desktop/Ninja Cloud/Disk', 'montage0.6.0'); | 93 | //this.ninjaLibrary.copyLibToCloud('Users/kgq387/Desktop/Ninja Cloud/Disk', 'montage0.6.0'); |
94 | //this.ninjaLibrary.deleteLibraries(); | 94 | //this.ninjaLibrary.deleteLibraries(); |
95 | window.hack = function (name, type) { | 95 | /* |
96 | window.hack = function (name, type) { | ||
96 | this.application.ninja.ioMediator.fileNew('Users/kgq387/Desktop/Ninja Cloud/Disk/'+name+'.'+type, '/js/io/templates/files/'+type+'.txt', function (status) {console.log(status)}); | 97 | this.application.ninja.ioMediator.fileNew('Users/kgq387/Desktop/Ninja Cloud/Disk/'+name+'.'+type, '/js/io/templates/files/'+type+'.txt', function (status) {console.log(status)}); |
97 | }.bind(this); | 98 | }.bind(this); |
99 | */ | ||
100 | window.hack = function (path) { | ||
101 | // | ||
102 | this.application.ninja.ioMediator.fileOpen('Users/kgq387/Desktop/Ninja Cloud/Disk/'+path, function (result) {console.log(result)}); | ||
103 | }.bind(this); | ||
98 | } | 104 | } |
99 | }, | 105 | }, |
100 | //////////////////////////////////////////////////////////////////// | 106 | //////////////////////////////////////////////////////////////////// |
@@ -621,7 +627,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
621 | // 200 - the file was read and its contents were returned | 627 | // 200 - the file was read and its contents were returned |
622 | // 404 - the file does not exist | 628 | // 404 - the file does not exist |
623 | // 500 - unknown server error occurred | 629 | // 500 - unknown server error occurred |
624 | openFile: { | 630 | readFile: { |
625 | enumerable: false, | 631 | enumerable: false, |
626 | value: function(file) { | 632 | value: function(file) { |
627 | // | 633 | // |
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 7bf4d41f..045fa2fd 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js | |||
@@ -64,13 +64,40 @@ exports.FileIo = Montage.create(Component, { | |||
64 | // | 64 | // |
65 | readFile: { | 65 | readFile: { |
66 | enumerable: true, | 66 | enumerable: true, |
67 | value: function() { | 67 | value: function(file) { |
68 | //Checking for API to be available | 68 | //Checking for API to be available |
69 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | 69 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { |
70 | //API not available, no IO action taken | 70 | //API not available, no IO action taken |
71 | return null; | 71 | return null; |
72 | } | 72 | } |
73 | // | 73 | //Peforming check for file to exist |
74 | var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), status, create, result; | ||
75 | //Upon successful check, handling results | ||
76 | if (check.success) { | ||
77 | //Handling status of check | ||
78 | switch (check.status) { | ||
79 | case 204: | ||
80 | //File exists | ||
81 | result = {}; | ||
82 | result.content = this.application.ninja.coreIoApi.readFile(file).content; | ||
83 | result.details = this.infoFile(file); | ||
84 | status = check.status; | ||
85 | break; | ||
86 | case 404: | ||
87 | //File does not exists, ready to be created | ||
88 | status = check.status; | ||
89 | break; | ||
90 | default: | ||
91 | //Unknown Error | ||
92 | status = 500; | ||
93 | break; | ||
94 | } | ||
95 | } else { | ||
96 | //Unknown Error | ||
97 | status = 500; | ||
98 | } | ||
99 | //Returning resulting code | ||
100 | return {status: status, file: result}; | ||
74 | } | 101 | } |
75 | }, | 102 | }, |
76 | //////////////////////////////////////////////////////////////////// | 103 | //////////////////////////////////////////////////////////////////// |
@@ -116,14 +143,49 @@ exports.FileIo = Montage.create(Component, { | |||
116 | // | 143 | // |
117 | infoFile: { | 144 | infoFile: { |
118 | enumerable: true, | 145 | enumerable: true, |
119 | value: function() { | 146 | value: function(file) { |
120 | //Checking for API to be available | 147 | //Checking for API to be available |
121 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | 148 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { |
122 | //API not available, no IO action taken | 149 | //API not available, no IO action taken |
123 | return null; | 150 | return null; |
124 | } | 151 | } |
125 | // | 152 | // |
153 | var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), details; | ||
154 | // | ||
155 | if (check.success) { | ||
156 | //Handling status of check | ||
157 | switch (check.status) { | ||
158 | case 204: | ||
159 | //File exists | ||
160 | details = JSON.parse(this.application.ninja.coreIoApi.isFileWritable(file).content); | ||
161 | details.uri = file.uri; | ||
162 | details.name = this.getFileNameFromPath(file.uri); | ||
163 | details.extension = details.name.split('.')[details.name.split('.').length-1]; | ||
164 | break; | ||
165 | case 404: | ||
166 | //File does not exists, ready to be created | ||
167 | |||
168 | break; | ||
169 | default: | ||
170 | //Unknown Error | ||
171 | |||
172 | break; | ||
173 | } | ||
174 | } else { | ||
175 | //Unknown Error | ||
176 | |||
177 | } | ||
178 | return details; | ||
126 | } | 179 | } |
180 | }, | ||
181 | //////////////////////////////////////////////////////////////////// | ||
182 | // | ||
183 | getFileNameFromPath : { | ||
184 | value: function(path) { | ||
185 | path = path.replace(/[/\\]$/g,""); | ||
186 | path = path.replace(/\\/g,"/"); | ||
187 | return path.substr(path.lastIndexOf('/') + 1); | ||
188 | } | ||
127 | } | 189 | } |
128 | //////////////////////////////////////////////////////////////////// | 190 | //////////////////////////////////////////////////////////////////// |
129 | //////////////////////////////////////////////////////////////////// | 191 | //////////////////////////////////////////////////////////////////// |