Skip to content

Commit 50b377d

Browse files
committed
Add deletion support and improved rename erroring
1 parent cf9a70d commit 50b377d

File tree

1 file changed

+60
-18
lines changed

1 file changed

+60
-18
lines changed

resources/views/server/js/filemanager/actions.blade.php

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,50 @@ class ActionsClass {
3030
}
3131

3232
move() {
33-
alert($(this.element).data('path'));
33+
const nameBlock = $(this.element).find('td[data-identifier="name"]');
34+
const currentName = decodeURIComponent(nameBlock.attr('data-name'));
35+
const currentPath = decodeURIComponent(nameBlock.data('path'));
36+
37+
swal({
38+
type: 'input',
39+
title: 'Move File',
40+
text: 'Please enter the new path for the file below.',
41+
showCancelButton: true,
42+
showConfirmButton: true,
43+
closeOnConfirm: false,
44+
showLoaderOnConfirm: true,
45+
inputValue: `${currentPath}${currentName}`,
46+
}, (val) => {
47+
$.ajax({
48+
type: 'POST',
49+
headers: {
50+
'X-Access-Token': '{{ $server->daemonSecret }}',
51+
'X-Access-Server': '{{ $server->uuid }}'
52+
},
53+
contentType: 'application/json; charset=utf-8',
54+
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/files/rename',
55+
timeout: 10000,
56+
data: JSON.stringify({
57+
from: `${currentPath}${currentName}`,
58+
to: `${val}`,
59+
}),
60+
}).done(data => {
61+
nameBlock.parent().addClass('warning').delay(200).fadeOut();
62+
swal.close();
63+
}).fail(jqXHR => {
64+
console.error(jqXHR);
65+
var error = 'An error occured while trying to process this request.';
66+
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
67+
error = jqXHR.responseJSON.error;
68+
}
69+
swal({
70+
type: 'error',
71+
title: '',
72+
text: error,
73+
});
74+
});
75+
});
76+
3477
}
3578

3679
download() {
@@ -56,17 +99,14 @@ class ActionsClass {
5699
inputField.focus();
57100
inputField.on('blur keypress', e => {
58101
// Save Field
59-
if (e.type === 'blur' || (e.type === 'keypress' && e.which !== 13)) {
60-
// Escape Key Pressed, don't save.
61-
if (e.which === 27 || e.type === 'blur') {
62-
if (!_.isEmpty(currentLink)) {
63-
nameBlock.html(currentLink);
64-
} else {
65-
nameBlock.html(currentName);
66-
}
67-
inputField.remove();
68-
ContextMenu.run();
102+
if (e.type === 'blur' || (e.type === 'keypress' && e.which === 27) || currentName === inputField.val()) {
103+
if (!_.isEmpty(currentLink)) {
104+
nameBlock.html(currentLink);
105+
} else {
106+
nameBlock.html(currentName);
69107
}
108+
inputField.remove();
109+
ContextMenu.run();
70110
return;
71111
}
72112

@@ -99,18 +139,20 @@ class ActionsClass {
99139
}
100140
inputField.remove();
101141
}).fail(jqXHR => {
102-
nameBlock.addClass('has-error');
103-
inputLoader.remove();
104142
console.error(jqXHR);
105143
var error = 'An error occured while trying to process this request.';
106144
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
107145
error = jqXHR.responseJSON.error;
108146
}
109-
swal({
110-
type: 'error',
111-
title: '',
112-
text: error,
147+
nameBlock.addClass('has-error').delay(2000).queue(() => {
148+
nameBlock.removeClass('has-error').dequeue();
113149
});
150+
inputField.popover({
151+
animation: true,
152+
placement: 'top',
153+
content: error,
154+
title: 'Save Error'
155+
}).popover('show');
114156
}).always(() => {
115157
inputLoader.remove();
116158
});
@@ -140,7 +182,7 @@ class ActionsClass {
140182
'X-Access-Server': '{{ $server->uuid }}'
141183
}
142184
}).done(data => {
143-
// nameBlock.parent().addClass('warning').delay(200).fadeOut();
185+
nameBlock.parent().addClass('warning').delay(200).fadeOut();
144186
swal({
145187
type: 'success',
146188
title: 'File Deleted'

0 commit comments

Comments
 (0)