diff options
Diffstat (limited to 'js/io/system/fileio.js')
-rwxr-xr-x | js/io/system/fileio.js | 266 |
1 files changed, 20 insertions, 246 deletions
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index f363ef9f..f78ad173 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js | |||
@@ -23,7 +23,7 @@ var Montage = require("montage/core/core").Montage, | |||
23 | //Exporting as File I/O | 23 | //Exporting as File I/O |
24 | exports.FileIo = Montage.create(Component, { | 24 | exports.FileIo = Montage.create(Component, { |
25 | //////////////////////////////////////////////////////////////////// | 25 | //////////////////////////////////////////////////////////////////// |
26 | //newFile Object (*required): {uri*, contents, contentType} | 26 | //Creating new file |
27 | newFile: { | 27 | newFile: { |
28 | enumerable: true, | 28 | enumerable: true, |
29 | value: function(file) { | 29 | value: function(file) { |
@@ -49,19 +49,21 @@ exports.FileIo = Montage.create(Component, { | |||
49 | break; | 49 | break; |
50 | default: | 50 | default: |
51 | //Unknown Error | 51 | //Unknown Error |
52 | status = 500; | ||
52 | break; | 53 | break; |
53 | } | 54 | } |
54 | } else { | 55 | } else { |
55 | //Unknown Error | 56 | //Unknown Error |
57 | status = 500; | ||
56 | } | 58 | } |
57 | //Returning resulting code | 59 | //Returning resulting code |
58 | return status; | 60 | return status; |
59 | // 204: File exists | 400: File exists | 404: File does not exists | 61 | // 204: File exists (not created) | 400: File exists | 404: File does not exists |
60 | // 201: File succesfully created | 500: Unknown | undefined: Unknown | 62 | // 201: File succesfully created | 500: Unknown |
61 | } | 63 | } |
62 | }, | 64 | }, |
63 | //////////////////////////////////////////////////////////////////// | 65 | //////////////////////////////////////////////////////////////////// |
64 | // | 66 | //Reading contents from file |
65 | readFile: { | 67 | readFile: { |
66 | enumerable: true, | 68 | enumerable: true, |
67 | value: function(file) { | 69 | value: function(file) { |
@@ -84,7 +86,7 @@ exports.FileIo = Montage.create(Component, { | |||
84 | status = check.status; | 86 | status = check.status; |
85 | break; | 87 | break; |
86 | case 404: | 88 | case 404: |
87 | //File does not exists, ready to be created | 89 | //File does not exists |
88 | status = check.status; | 90 | status = check.status; |
89 | break; | 91 | break; |
90 | default: | 92 | default: |
@@ -96,12 +98,14 @@ exports.FileIo = Montage.create(Component, { | |||
96 | //Unknown Error | 98 | //Unknown Error |
97 | status = 500; | 99 | status = 500; |
98 | } | 100 | } |
99 | //Returning resulting code | 101 | //Returning status and result (null if none) |
100 | return {status: status, file: result}; | 102 | return {status: status, file: result}; |
103 | //Status Codes | ||
104 | // 204: File exists | 404: File does not exists | 500: Unknown | ||
101 | } | 105 | } |
102 | }, | 106 | }, |
103 | //////////////////////////////////////////////////////////////////// | 107 | //////////////////////////////////////////////////////////////////// |
104 | // | 108 | //Saving file (existing file or creates and saves if none exists) |
105 | saveFile: { | 109 | saveFile: { |
106 | enumerable: true, | 110 | enumerable: true, |
107 | value: function(file) { | 111 | value: function(file) { |
@@ -121,7 +125,7 @@ exports.FileIo = Montage.create(Component, { | |||
121 | result = this.application.ninja.coreIoApi.updateFile(file); | 125 | result = this.application.ninja.coreIoApi.updateFile(file); |
122 | status = 204; | 126 | status = 204; |
123 | break; | 127 | break; |
124 | case 404://createFile | 128 | case 404: |
125 | //File does not exists, ready to be created | 129 | //File does not exists, ready to be created |
126 | result = this.application.ninja.coreIoApi.createFile(file); | 130 | result = this.application.ninja.coreIoApi.createFile(file); |
127 | status = 404; | 131 | status = 404; |
@@ -135,8 +139,10 @@ exports.FileIo = Montage.create(Component, { | |||
135 | //Unknown Error | 139 | //Unknown Error |
136 | status = 500; | 140 | status = 500; |
137 | } | 141 | } |
138 | // | 142 | //Returning status and result (null if none) |
139 | return {status: status, result: result}; | 143 | return {status: status, result: result}; |
144 | //Status Codes | ||
145 | // 204: File exists | 404: File does not exists | 500: Unknown | ||
140 | } | 146 | } |
141 | }, | 147 | }, |
142 | //////////////////////////////////////////////////////////////////// | 148 | //////////////////////////////////////////////////////////////////// |
@@ -187,19 +193,20 @@ exports.FileIo = Montage.create(Component, { | |||
187 | details.uri = file.uri; | 193 | details.uri = file.uri; |
188 | details.name = this.getFileNameFromPath(file.uri); | 194 | details.name = this.getFileNameFromPath(file.uri); |
189 | details.extension = details.name.split('.')[details.name.split('.').length-1]; | 195 | details.extension = details.name.split('.')[details.name.split('.').length-1]; |
196 | details.status = 204; | ||
190 | break; | 197 | break; |
191 | case 404: | 198 | case 404: |
192 | //File does not exists, ready to be created | 199 | //File does not exists, ready to be created |
193 | 200 | details = {status: 404, uri: file.uri, name: this.getFileNameFromPath(file.uri)}; | |
194 | break; | 201 | break; |
195 | default: | 202 | default: |
196 | //Unknown Error | 203 | //Unknown Error |
197 | 204 | details = {status: 500, uri: file.uri, name: this.getFileNameFromPath(file.uri)}; | |
198 | break; | 205 | break; |
199 | } | 206 | } |
200 | } else { | 207 | } else { |
201 | //Unknown Error | 208 | //Unknown Error |
202 | 209 | details = {status: 500, uri: file.uri, name: this.getFileNameFromPath(file.uri)}; | |
203 | } | 210 | } |
204 | return details; | 211 | return details; |
205 | } | 212 | } |
@@ -214,240 +221,7 @@ exports.FileIo = Montage.create(Component, { | |||
214 | } | 221 | } |
215 | } | 222 | } |
216 | //////////////////////////////////////////////////////////////////// | 223 | //////////////////////////////////////////////////////////////////// |
217 | //////////////////////////////////////////////////////////////////// | 224 | //////////////////////////////////////////////////////////////////// |
218 | |||
219 | |||
220 | |||
221 | |||
222 | |||
223 | |||
224 | |||
225 | |||
226 | |||
227 | |||
228 | |||
229 | |||
230 | |||
231 | |||
232 | |||
233 | |||
234 | |||
235 | |||
236 | |||
237 | |||
238 | |||
239 | |||
240 | |||
241 | |||
242 | |||
243 | |||
244 | |||
245 | |||
246 | |||
247 | |||
248 | |||
249 | |||
250 | |||
251 | |||
252 | |||
253 | |||
254 | |||
255 | |||
256 | |||
257 | |||
258 | |||
259 | |||
260 | |||
261 | |||
262 | |||
263 | |||
264 | |||
265 | |||
266 | |||
267 | |||
268 | |||
269 | |||
270 | |||
271 | |||
272 | /* | ||
273 | open: { | ||
274 | enumerable: true, | ||
275 | value: function(doc, type, uri, server) { | ||
276 | // | ||
277 | var file = {}, head, body, h, b; | ||
278 | file.uri = uri; | ||
279 | file.server = server; | ||
280 | // | ||
281 | if (doc.content) { | ||
282 | if (type === 'html' || type === 'htm') { | ||
283 | // | ||
284 | h = doc.content.split('</head>'); | ||
285 | h = h[0].split('<head>'); | ||
286 | head = h[1]; | ||
287 | // | ||
288 | b = doc.content.split('</body>'); | ||
289 | b = b[0].split('<body>'); | ||
290 | body = b[1]; | ||
291 | // | ||
292 | file.type = 'html'; | ||
293 | file.head = head; | ||
294 | file.body = body; | ||
295 | } else { | ||
296 | //TODO: Add other file type routines | ||
297 | file.type = type; | ||
298 | file.content = doc.content; | ||
299 | } | ||
300 | } else { | ||
301 | //TODO: File is empty | ||
302 | if (type === 'html' || type === 'htm') { | ||
303 | head = ''; | ||
304 | body = ''; | ||
305 | // | ||
306 | file.type = 'html'; | ||
307 | file.head = head; | ||
308 | file.body = body; | ||
309 | } else { | ||
310 | //TODO: Add other file type routines | ||
311 | file.type = type; | ||
312 | file.content = doc.content; | ||
313 | } | ||
314 | } | ||
315 | //TODO: Load contents into App | ||
316 | //documentManagerModule.DocumentManager. |