More updates to file manager
Not doing individual commits for this, tons of changes for tons of different aspects across multiple files.
This commit is contained in:
parent
fe9c573533
commit
fb4d122a2a
12 changed files with 308 additions and 164 deletions
|
@ -21,7 +21,7 @@
|
|||
// SOFTWARE.
|
||||
class FileActions {
|
||||
constructor() {
|
||||
//
|
||||
this.activeLine = null;
|
||||
}
|
||||
|
||||
run() {
|
||||
|
@ -31,53 +31,67 @@ class FileActions {
|
|||
|
||||
makeMenu() {
|
||||
$(document).find('#fileOptionMenu').remove();
|
||||
return $('<ul id="fileOptionMenu" class="dropdown-menu" role="menu" style="display:none" > \
|
||||
if (!_.isNull(this.activeLine)) this.activeLine.removeClass('active');
|
||||
return '<ul id="fileOptionMenu" class="dropdown-menu" role="menu" style="display:none" > \
|
||||
<li data-action="move"><a tabindex="-1" href="#"><i class="fa fa-arrow-right"></i> Move</a></li> \
|
||||
<li data-action="rename"><a tabindex="-1" href="#"><i class="fa fa-pencil-square-o"></i> Rename</a></li> \
|
||||
<li data-action="compress" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-file-archive-o"></i> Compress</a></li> \
|
||||
<li data-action="decompress" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-expand"></i> Decompress</a></li> \
|
||||
<li class="divider"></li> \
|
||||
<li data-action="download" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-download"></i> Download</a></li> \
|
||||
<li data-action="delete"><a tabindex="-1" href="#"><i class="fa fa-trash-o"></i> Delete</a></li> \
|
||||
</ul>');
|
||||
<li data-action="download" class="hidden"><a tabindex="-1" href="/server/{{ $server->uuidShort }}/files/download/"><i class="fa fa-download"></i> Download</a></li> \
|
||||
<li data-action="delete" class="bg-danger"><a tabindex="-1" href="#"><i class="fa fa-trash-o"></i> Delete</a></li> \
|
||||
</ul>';
|
||||
}
|
||||
|
||||
rightClick() {
|
||||
$('#file_listing > tbody').on('contextmenu', event => {
|
||||
$('#file_listing > tbody td').on('contextmenu', event => {
|
||||
|
||||
const parent = $(event.target).parent();
|
||||
const menu = this.makeMenu();
|
||||
const menu = $(this.makeMenu());
|
||||
|
||||
if (parent.data('type') === 'disabled') return;
|
||||
event.preventDefault();
|
||||
|
||||
menu.appendTo('body');
|
||||
menu.data('invokedOn', $(event.target)).show().css({
|
||||
$(menu).appendTo('body');
|
||||
$(menu).data('invokedOn', $(event.target)).show().css({
|
||||
position: 'absolute',
|
||||
left: event.pageX,
|
||||
top: event.pageY,
|
||||
});
|
||||
|
||||
this.activeLine = parent;
|
||||
this.activeLine.addClass('active');
|
||||
|
||||
if (parent.data('type') === 'file') {
|
||||
menu.find('li[data-action="download"]').removeClass('hidden');
|
||||
$(menu).find('li[data-action="download"]').removeClass('hidden');
|
||||
}
|
||||
|
||||
if (parent.data('type') === 'folder') {
|
||||
$(menu).find('li[data-action="compress"]').removeClass('hidden');
|
||||
}
|
||||
|
||||
if (_.without(['application/zip', 'application/gzip', 'application/x-gzip'], parent.data('mime')).length < 3) {
|
||||
menu.find('li[data-action="decompress"]').removeClass('hidden');
|
||||
$(menu).find('li[data-action="decompress"]').removeClass('hidden');
|
||||
}
|
||||
|
||||
// Handle Events
|
||||
var Context = new ContextMenuActions(parent);
|
||||
menu.find('li[data-action="move"]').unbind().on('click', e => {
|
||||
var Context = new ContextMenuActions(parent, menu);
|
||||
$(menu).find('li[data-action="move"]').unbind().on('click', e => {
|
||||
Context.move();
|
||||
});
|
||||
|
||||
menu.find('li[data-action="rename"]').unbind().on('click', e => {
|
||||
$(menu).find('li[data-action="rename"]').unbind().on('click', e => {
|
||||
Context.rename();
|
||||
});
|
||||
|
||||
$(menu).find('li[data-action="download"]').unbind().on('click', e => {
|
||||
e.preventDefault();
|
||||
Context.download();
|
||||
});
|
||||
|
||||
$(window).on('click', () => {
|
||||
menu.remove();
|
||||
$(menu).remove();
|
||||
if(!_.isNull(this.activeLine)) this.activeLine.removeClass('active');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -85,7 +99,12 @@ class FileActions {
|
|||
directoryClick() {
|
||||
$('a[data-action="directory-view"]').on('click', function (event) {
|
||||
event.preventDefault();
|
||||
window.location.hash = encodeURIComponent($(this).parent().data('hash') || '');
|
||||
|
||||
const path = $(this).parent().data('path') || '';
|
||||
const name = $(this).parent().data('name') || '';
|
||||
|
||||
console.log('changing hash');
|
||||
window.location.hash = encodeURIComponent(path + name);
|
||||
Files.list();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
class ContextMenuActions {
|
||||
constructor(element) {
|
||||
constructor(element, menu) {
|
||||
this.element = element;
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
@ -32,28 +33,46 @@ class ContextMenuActions {
|
|||
alert($(this.element).data('path'));
|
||||
}
|
||||
|
||||
download() {
|
||||
var baseURL = $(this.menu).find('li[data-action="download"] a').attr('href');
|
||||
var toURL = baseURL + $(this.element).find('td[data-identifier="name"]').data('name');
|
||||
|
||||
window.location = toURL;
|
||||
}
|
||||
|
||||
rename() {
|
||||
var desiredElement = $(this.element).find('td[data-identifier="name"]');
|
||||
var linkElement = desiredElement.find('a');
|
||||
var currentName = linkElement.html();
|
||||
var editField = `<input class="form-control input-sm" type="text" value="${currentName}" />`;
|
||||
desiredElement.find('a').remove();
|
||||
desiredElement.html(editField);
|
||||
const nameBlock = $(this.element).find('td[data-identifier="name"]');
|
||||
const currentLink = nameBlock.find('a');
|
||||
const currentName = decodeURIComponent(nameBlock.attr('data-name'));
|
||||
const attachEditor = `
|
||||
<input class="form-control input-sm" type="text" value="${currentName}" />
|
||||
<span class="input-loader"><i class="fa fa-refresh fa-spin fa-fw"></i></span>
|
||||
`;
|
||||
|
||||
nameBlock.html(attachEditor);
|
||||
const inputField = nameBlock.find('input');
|
||||
const inputLoader = nameBlock.find('.input-loader');
|
||||
|
||||
const inputField = desiredElement.find('input');
|
||||
inputField.focus();
|
||||
|
||||
inputField.on('blur keypress', e => {
|
||||
// Save Field
|
||||
if (e.type === 'blur' || (e.type === 'keypress' && e.which !== 13)) {
|
||||
// Escape Key Pressed, don't save.
|
||||
if (e.which === 27 || e.type === 'blur') {
|
||||
desiredElement.html(linkElement);
|
||||
if (!_.isEmpty(currentLink)) {
|
||||
nameBlock.html(currentLink);
|
||||
} else {
|
||||
nameBlock.html(currentName);
|
||||
}
|
||||
inputField.remove();
|
||||
Actions.run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
inputLoader.show();
|
||||
const currentPath = decodeURIComponent(nameBlock.data('path'));
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
headers: {
|
||||
|
@ -64,16 +83,24 @@ class ContextMenuActions {
|
|||
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server/files/rename',
|
||||
timeout: 10000,
|
||||
data: JSON.stringify({
|
||||
from: currentName,
|
||||
to: inputField.val(),
|
||||
from: `${currentPath}${currentName}`,
|
||||
to: `${currentPath}${inputField.val()}`,
|
||||
}),
|
||||
}).done(data => {
|
||||
this.element.attr('data-path', inputField.val());
|
||||
desiredElement.attr('data-hash', inputField.val());
|
||||
desiredElement.html(linkElement.html(inputField.val()));
|
||||
nameBlock.attr('data-name', inputField.val());
|
||||
if (!_.isEmpty(currentLink)) {
|
||||
const newLink = currentLink.attr('href').substr(0, currentLink.attr('href').lastIndexOf('/')) + '/' + inputField.val();
|
||||
currentLink.attr('href', newLink);
|
||||
nameBlock.html(
|
||||
currentLink.html(inputField.val())
|
||||
);
|
||||
} else {
|
||||
nameBlock.html(inputField.val());
|
||||
}
|
||||
inputField.remove();
|
||||
Actions.run();
|
||||
}).fail(jqXHR => {
|
||||
nameBlock.addClass('has-error');
|
||||
inputLoader.remove();
|
||||
console.error(jqXHR);
|
||||
var error = 'An error occured while trying to process this request.';
|
||||
if (typeof jqXHR.responseJSON !== 'undefined' && typeof jqXHR.responseJSON.error !== 'undefined') {
|
||||
|
@ -84,6 +111,8 @@ class ContextMenuActions {
|
|||
title: '',
|
||||
text: error,
|
||||
});
|
||||
}).always(() => {
|
||||
inputLoader.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -44,11 +44,13 @@ class FileManager {
|
|||
directory: path,
|
||||
},
|
||||
}).done(data => {
|
||||
$('#load_files').slideUp().html(data).slideDown(() => {
|
||||
this.loader(false);
|
||||
$('#load_files').slideUp().html(data).slideDown(100, () => {
|
||||
Actions.run();
|
||||
});
|
||||
$('#internal_alert').slideUp();
|
||||
}).fail(jqXHR => {
|
||||
this.loader(false);
|
||||
swal({
|
||||
type: 'error',
|
||||
title: 'File Error',
|
||||
|
@ -56,9 +58,7 @@ class FileManager {
|
|||
});
|
||||
if (!isError) this.list('/', true);
|
||||
console.log(jqXHR);
|
||||
}).always(() => {
|
||||
this.loader(false);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
loader(show) {
|
||||
|
@ -76,9 +76,9 @@ class FileManager {
|
|||
'font-size': '60px'
|
||||
});
|
||||
|
||||
$('.ajax_loading_box').css('height', (height + 5)).fadeIn();
|
||||
$('.ajax_loading_box').css('height', (height + 5)).show();
|
||||
} else {
|
||||
$('.ajax_loading_box').fadeOut(100);
|
||||
$('.ajax_loading_box').hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue