diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/io/system/coreioapi.js | 3 | ||||
-rwxr-xr-x | js/io/system/fileio.js | 17 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 40 |
3 files changed, 35 insertions, 25 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index bdba5240..d9505cd6 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -92,6 +92,9 @@ 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) { | ||
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 | }.bind(this); | ||
95 | } | 98 | } |
96 | }, | 99 | }, |
97 | //////////////////////////////////////////////////////////////////// | 100 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 2c49e849..7bf4d41f 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js | |||
@@ -17,15 +17,13 @@ NOTES: | |||
17 | //////////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////////// |
18 | ///////////////////////////////////////////////////////////////////// */ | 18 | ///////////////////////////////////////////////////////////////////// */ |
19 | // | 19 | // |
20 | var Montage = require("montage/core/core").Montage; | 20 | var Montage = require("montage/core/core").Montage, |
21 | Component = require("montage/ui/component").Component; | ||
21 | //////////////////////////////////////////////////////////////////////// | 22 | //////////////////////////////////////////////////////////////////////// |
22 | //Exporting as File I/O | 23 | //Exporting as File I/O |
23 | exports.FileIo = Montage.create(Object.prototype, { | 24 | exports.FileIo = Montage.create(Component, { |
24 | //////////////////////////////////////////////////////////////////// | 25 | //////////////////////////////////////////////////////////////////// |
25 | //newFile Object (*required): {uri*, contents, contentType} | 26 | //newFile Object (*required): {uri*, contents, contentType} |
26 | //Return codes | ||
27 | // 204: File exists | 400: File exists | 404: File does not exists | ||
28 | // 201: File succesfully created | 500: Unknown | undefined: Unknown | ||
29 | newFile: { | 27 | newFile: { |
30 | enumerable: true, | 28 | enumerable: true, |
31 | value: function(file) { | 29 | value: function(file) { |
@@ -35,7 +33,7 @@ exports.FileIo = Montage.create(Object.prototype, { | |||
35 | return null; | 33 | return null; |
36 | } | 34 | } |
37 | //Peforming check for file to exist | 35 | //Peforming check for file to exist |
38 | var check = this.application.ninja.coreIoApi.fileExists(file.uri), status, create; | 36 | var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), status, create; |
39 | //Upon successful check, handling results | 37 | //Upon successful check, handling results |
40 | if (check.success) { | 38 | if (check.success) { |
41 | //Handling status of check | 39 | //Handling status of check |
@@ -47,10 +45,7 @@ exports.FileIo = Montage.create(Object.prototype, { | |||
47 | case 404: | 45 | case 404: |
48 | //File does not exists, ready to be created | 46 | //File does not exists, ready to be created |
49 | create = this.application.ninja.coreIoApi.createFile(file); | 47 | create = this.application.ninja.coreIoApi.createFile(file); |
50 | //Storing status to be returned (for UI handling) | 48 | status = create.status; |
51 | if (create.success) { | ||
52 | status = check.status; | ||
53 | } | ||
54 | break; | 49 | break; |
55 | default: | 50 | default: |
56 | //Unknown Error | 51 | //Unknown Error |
@@ -61,6 +56,8 @@ exports.FileIo = Montage.create(Object.prototype, { | |||
61 | } | 56 | } |
62 | //Returning resulting code | 57 | //Returning resulting code |
63 | return status; | 58 | return status; |
59 | // 204: File exists | 400: File exists | 404: File does not exists | ||
60 | // 201: File succesfully created | 500: Unknown | undefined: Unknown | ||
64 | } | 61 | } |
65 | }, | 62 | }, |
66 | //////////////////////////////////////////////////////////////////// | 63 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index b6d0e598..66fea8b3 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -14,10 +14,17 @@ var Montage = require("montage/core/core").Montage, | |||
14 | // | 14 | // |
15 | exports.IoMediator = Montage.create(Component, { | 15 | exports.IoMediator = Montage.create(Component, { |
16 | //////////////////////////////////////////////////////////////////// | 16 | //////////////////////////////////////////////////////////////////// |
17 | // | ||
18 | hasTemplate: { | ||
19 | enumerable: false, | ||
20 | value: false | ||
21 | }, | ||
22 | //////////////////////////////////////////////////////////////////// | ||
17 | // | 23 | // |
18 | deserializedFromTemplate: { | 24 | deserializedFromTemplate: { |
19 | enumerable: false, | 25 | enumerable: false, |
20 | value: function () { | 26 | value: function () { |
27 | // | ||
21 | } | 28 | } |
22 | }, | 29 | }, |
23 | //////////////////////////////////////////////////////////////////// | 30 | //////////////////////////////////////////////////////////////////// |
@@ -32,27 +39,30 @@ exports.IoMediator = Montage.create(Component, { | |||
32 | enumerable: false, | 39 | enumerable: false, |
33 | value: function (file, template, callback) { | 40 | value: function (file, template, callback) { |
34 | // | 41 | // |
35 | var xhr = new XMLHttpRequest(); | 42 | var xhr = new XMLHttpRequest(), result; |
36 | xhr.open("GET", template, false); | 43 | xhr.open("GET", template, false); |
37 | xhr.send(); | 44 | xhr.send(); |
38 | if (xhr.readyState === 4) { | 45 | if (xhr.readyState === 4) { |
39 | // | 46 | // |
40 | console.log(this.fio.newFile({uri: file, contents: xhr.response})); | 47 | switch (this.fio.newFile({uri: file, contents: xhr.response})) { |
48 | case 201: | ||
49 | result = {status: 201, success: true, uri: file}; | ||
50 | break; | ||
51 | case 204: | ||
52 | result = {status: 204, success: false, uri: file}; | ||
53 | break; | ||
54 | case 400: | ||
55 | result = {status: 400, success: false, uri: file}; | ||
56 | break; | ||
57 | default: | ||
58 | result = {status: 500, success: false, uri: file}; | ||
59 | break; | ||
60 | } | ||
41 | } else { | 61 | } else { |
42 | //Error | 62 | result = {status: 500, success: false, uri: file}; |
43 | } | 63 | } |
44 | 64 | // | |
45 | 65 | if (callback) callback(result); | |
46 | |||
47 | |||
48 | |||
49 | |||
50 | |||
51 | //callback('win'); | ||
52 | /* | ||
53 | var returnObj = null; //like {"uri": "/gfdg/gdf/dfg.js", "success": true,...} | ||
54 | callback(returnObj); | ||
55 | */ | ||
56 | } | 66 | } |
57 | }, | 67 | }, |
58 | //////////////////////////////////////////////////////////////////// | 68 | //////////////////////////////////////////////////////////////////// |