dexter/app/public/.assets/main.js

72 lines
1.5 KiB
JavaScript

function upload_button(el) {
var form = get_adjacent_form(el);
toggle_hidden(form);
}
function upload_submit(el) {
var filename = el.upload.files[0].name;
el.target_path.value = filename;
}
function mkdir_button(el) {
var input = prompt('Enter a name or path for the directory:');
if (input === null || input === '') {
return;
}
var form = get_adjacent_form(el);
form.target_path.value = input;
form.submit();
}
function file_delete(el) {
var form = get_adjacent_form(el);
var name = get_file_name_from_url(form.target_path.value);
if (!confirm("Are you sure you want to delete '" + name + "'? Click OK to continue.")) {
return;
}
form.submit();
}
function file_move(el) {
var form = get_adjacent_form(el);
var dest_path = form.dest_path;
var name = get_file_name_from_url(form.target_path.value);
var input = prompt("Enter a new name or path for '" + name + "':", name);
if (input === null || input === '') {
return;
}
dest_path.value = input;
form.submit();
}
function get_adjacent_form(el) {
var parent = el.parentElement;
return parent.getElementsByTagName('form')[0];
}
function toggle_hidden(el) {
if (el.style.cssText === '') {
el.style.cssText = 'display: inline;';
} else {
el.style.cssText = '';
}
}
function get_file_name_from_url(url) {
var split = url.split('/');
var name = split.pop();
if (name === '') {
name = split.pop() + '/';
}
return name;
}