aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/js
diff options
context:
space:
mode:
authorJohannes Zellner <johannes@cloudron.io>2017-02-07 16:26:17 +0100
committerJohannes Zellner <johannes@cloudron.io>2017-02-07 16:26:19 +0100
commite628921a338684a4bc3f196c5c39beba8b8f9b68 (patch)
treea4112c316e69b4d0a302af23f5bb8f4396c15c30 /frontend/js
parent4b6cf0add4f4f89671f4553a9672a01fbb485df1 (diff)
downloadSurfer-e628921a338684a4bc3f196c5c39beba8b8f9b68.tar.gz
Surfer-e628921a338684a4bc3f196c5c39beba8b8f9b68.tar.zst
Surfer-e628921a338684a4bc3f196c5c39beba8b8f9b68.zip
Add rename functionality
This also break backwardscompat since PUT is now POST and PUT is used for renaming
Diffstat (limited to 'frontend/js')
-rw-r--r--frontend/js/app.js40
1 files changed, 36 insertions, 4 deletions
diff --git a/frontend/js/app.js b/frontend/js/app.js
index e0464f8..078473a 100644
--- a/frontend/js/app.js
+++ b/frontend/js/app.js
@@ -141,7 +141,7 @@ function upload() {
141 var formData = new FormData(); 141 var formData = new FormData();
142 formData.append('file', file); 142 formData.append('file', file);
143 143
144 superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) { 144 superagent.post('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) {
145 if (result && result.statusCode === 401) return logout(); 145 if (result && result.statusCode === 401) return logout();
146 if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode); 146 if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode);
147 if (error) console.error(error); 147 if (error) console.error(error);
@@ -149,8 +149,6 @@ function upload() {
149 app.uploadStatus.done += 1; 149 app.uploadStatus.done += 1;
150 app.uploadStatus.percentDone = Math.round(app.uploadStatus.done / app.uploadStatus.count * 100); 150 app.uploadStatus.percentDone = Math.round(app.uploadStatus.done / app.uploadStatus.count * 100);
151 151
152 console.log(Math.round(app.uploadStatus.done / app.uploadStatus.count * 100))
153
154 if (app.uploadStatus.done >= app.uploadStatus.count) { 152 if (app.uploadStatus.done >= app.uploadStatus.count) {
155 app.uploadStatus = { 153 app.uploadStatus = {
156 busy: false, 154 busy: false,
@@ -198,6 +196,33 @@ function del(entry) {
198 }); 196 });
199} 197}
200 198
199function renameAsk(entry) {
200 app.renameData.entry = entry;
201 app.renameData.error = null;
202 app.renameData.newFilePath = entry.filePath;
203
204 $('#modalRename').modal('show');
205}
206
207function rename(data) {
208 app.busy = true;
209
210 var path = encode(sanitize(app.path + '/' + data.entry.filePath));
211 var newFilePath = sanitize(app.path + '/' + data.newFilePath);
212
213 superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send({ newFilePath: newFilePath }).end(function (error, result) {
214 app.busy = false;
215
216 if (result && result.statusCode === 401) return logout();
217 if (result && result.statusCode !== 200) return console.error('Error renaming file: ', result.statusCode);
218 if (error) return console.error(error);
219
220 refresh();
221
222 $('#modalRename').modal('hide');
223 });
224}
225
201function createDirectoryAsk() { 226function createDirectoryAsk() {
202 $('#modalcreateDirectory').modal('show'); 227 $('#modalcreateDirectory').modal('show');
203 app.createDirectoryData = ''; 228 app.createDirectoryData = '';
@@ -210,7 +235,7 @@ function createDirectory(name) {
210 235
211 var path = encode(sanitize(app.path + '/' + name)); 236 var path = encode(sanitize(app.path + '/' + name));
212 237
213 superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password, directory: true }).end(function (error, result) { 238 superagent.post('/api/files' + path).query({ username: app.session.username, password: app.session.password, directory: true }).end(function (error, result) {
214 app.busy = false; 239 app.busy = false;
215 240
216 if (result && result.statusCode === 401) return logout(); 241 if (result && result.statusCode === 401) return logout();
@@ -258,6 +283,11 @@ var app = new Vue({
258 }, 283 },
259 loginData: {}, 284 loginData: {},
260 deleteData: {}, 285 deleteData: {},
286 renameData: {
287 entry: {},
288 error: null,
289 newFilePath: ''
290 },
261 createDirectoryData: '', 291 createDirectoryData: '',
262 createDirectoryError: null, 292 createDirectoryError: null,
263 entries: [] 293 entries: []
@@ -271,6 +301,8 @@ var app = new Vue({
271 upload: upload, 301 upload: upload,
272 delAsk: delAsk, 302 delAsk: delAsk,
273 del: del, 303 del: del,
304 renameAsk: renameAsk,
305 rename: rename,
274 createDirectoryAsk: createDirectoryAsk, 306 createDirectoryAsk: createDirectoryAsk,
275 createDirectory: createDirectory 307 createDirectory: createDirectory
276 } 308 }