diff options
Diffstat (limited to 'js/mediators')
-rw-r--r-- | js/mediators/io-mediator.js | 85 |
1 files changed, 56 insertions, 29 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 66fea8b3..f2f2f642 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -33,17 +33,23 @@ exports.IoMediator = Montage.create(Component, { | |||
33 | enumerable: false, | 33 | enumerable: false, |
34 | value: FileIo | 34 | value: FileIo |
35 | }, | 35 | }, |
36 | //////////////////////////////////////////////////////////////////// | ||
37 | // | ||
38 | pio: { | ||
39 | enumerable: false, | ||
40 | value: ProjectIo | ||
41 | }, | ||
36 | //////////////////////////////////////////////////////////////////// | 42 | //////////////////////////////////////////////////////////////////// |
37 | // | 43 | // |
38 | fileNew: { | 44 | fileNew: { |
39 | enumerable: false, | 45 | enumerable: false, |
40 | value: function (file, template, callback) { | 46 | value: function (file, template, callback) { |
41 | // | 47 | //Loading template from template URL |
42 | var xhr = new XMLHttpRequest(), result; | 48 | var xhr = new XMLHttpRequest(), result; |
43 | xhr.open("GET", template, false); | 49 | xhr.open("GET", template, false); |
44 | xhr.send(); | 50 | xhr.send(); |
45 | if (xhr.readyState === 4) { | 51 | if (xhr.readyState === 4) { |
46 | // | 52 | //Making call to create file, checking for return code |
47 | switch (this.fio.newFile({uri: file, contents: xhr.response})) { | 53 | switch (this.fio.newFile({uri: file, contents: xhr.response})) { |
48 | case 201: | 54 | case 201: |
49 | result = {status: 201, success: true, uri: file}; | 55 | result = {status: 201, success: true, uri: file}; |
@@ -61,8 +67,11 @@ exports.IoMediator = Montage.create(Component, { | |||
61 | } else { | 67 | } else { |
62 | result = {status: 500, success: false, uri: file}; | 68 | result = {status: 500, success: false, uri: file}; |
63 | } | 69 | } |
64 | // | 70 | //Sending result to callback if requested for handling |
65 | if (callback) callback(result); | 71 | if (callback) callback(result); |
72 | //Codes | ||
73 | // 204: File exists | 400: File exists | ||
74 | // 201: File succesfully created | 500: Unknown (Probably cloud API not running) | ||
66 | } | 75 | } |
67 | }, | 76 | }, |
68 | //////////////////////////////////////////////////////////////////// | 77 | //////////////////////////////////////////////////////////////////// |
@@ -70,23 +79,50 @@ exports.IoMediator = Montage.create(Component, { | |||
70 | fileOpen: { | 79 | fileOpen: { |
71 | enumerable: false, | 80 | enumerable: false, |
72 | value: function (file, callback) { | 81 | value: function (file, callback) { |
73 | var response = "", fileContent="", filename="", fileType="js", returnObj=null; | 82 | //Reading file (Ninja doesn't really open a file, all in browser memory) |
74 | 83 | var read = this.fio.readFile({uri: file}), result; | |
75 | response = this.application.ninja.coreIoApi.openFile({"uri":file.uri}); | 84 | //Checking for status |
76 | if((response.success === true) && ((response.status === 200) || (response.status === 304))){ | 85 | switch(read.status) { |
77 | fileContent = response.content; | 86 | case 204: |
78 | } | 87 | //Creating and formatting result object for callbak |
79 | 88 | result = read.file.details; | |
80 | 89 | //TODO: Add handling for converting HTML to Ninja format | |
81 | //TODO : format html content to render in design view | 90 | result.content = read.file.content; |
82 | 91 | result.status = read.status; | |
83 | 92 | // | |
84 | filename = this.getFileNameFromPath(file.uri); | 93 | if (callback) callback(result); |
85 | if(file.uri.indexOf('.') != -1){ | 94 | break; |
86 | fileType = file.uri.substr(file.uri.lastIndexOf('.') + 1); | 95 | case 404: |
87 | } | 96 | //File does not exists |
88 | returnObj = {"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": file.uri}; | 97 | if (callback) callback({status: read.status}); |
89 | callback(returnObj); | 98 | break; |
99 | default: | ||
100 | //Unknown | ||
101 | if (callback) callback({status: 500}); | ||
102 | break; | ||
103 | } | ||
104 | /* | ||
105 | //////////////////////////////////////////////////////////// | ||
106 | //////////////////////////////////////////////////////////// | ||
107 | //Return Object Description | ||
108 | Object.status (Always presents for handling) | ||
109 | 204: File exists (Success) | ||
110 | 404: File does not exists (Failure) | ||
111 | 500: Unknown (Probably cloud API not running) | ||
112 | |||
113 | (Below only present if succesfull 204) | ||
114 | |||
115 | Object.content | ||
116 | Object.extension | ||
117 | Object.name | ||
118 | Object.uri | ||
119 | Object.creationDate | ||
120 | Object.modifiedDate | ||
121 | Object.readOnly | ||
122 | Object.size | ||
123 | //////////////////////////////////////////////////////////// | ||
124 | //////////////////////////////////////////////////////////// | ||
125 | */ | ||
90 | } | 126 | } |
91 | }, | 127 | }, |
92 | //////////////////////////////////////////////////////////////////// | 128 | //////////////////////////////////////////////////////////////////// |
@@ -104,15 +140,6 @@ exports.IoMediator = Montage.create(Component, { | |||
104 | value: function (file, copy, callback) { | 140 | value: function (file, copy, callback) { |
105 | // | 141 | // |
106 | } | 142 | } |
107 | }, | ||
108 | //////////////////////////////////////////////////////////////////// | ||
109 | ///// Return the last part of a path (e.g. filename) | ||
110 | getFileNameFromPath : { | ||
111 | value: function(path) { | ||
112 | path = path.replace(/[/\\]$/g,""); | ||
113 | path = path.replace(/\\/g,"/"); | ||
114 | return path.substr(path.lastIndexOf('/') + 1); | ||
115 | } | ||
116 | } | 143 | } |
117 | //////////////////////////////////////////////////////////////////// | 144 | //////////////////////////////////////////////////////////////////// |
118 | }); | 145 | }); |