Eliminazione allegati via AJAX

This commit is contained in:
Thomas Zilio 2018-08-31 18:06:44 +02:00
parent 2e33090197
commit c35ea2c836
4 changed files with 35 additions and 6 deletions

View File

@ -75,6 +75,8 @@ if (Auth::check()) {
'delete' => tr('Elimina'),
'deleteTitle' => tr('Sei sicuro?'),
'deleteMessage' => tr('Eliminare questo elemento?'),
'errorTitle' => tr('Errore'),
'errorMessage' => tr("Si è verificato un errore nell'esecuzione dell'operazione richiesta"),
'close' => tr('Chiudi'),
'filter' => tr('Filtra'),
'long' => tr('La ricerca potrebbe richiedere del tempo'),

View File

@ -1310,7 +1310,30 @@ function message(element) {
blank = data.blank != undefined && data.blank;
delete data.blank;
redirect(href, data, method, blank);
if (data.callback) {
$.ajax({
type: method,
crossDomain: true,
url: href,
data: data,
success: function (response) {
var callback = window[data.callback];
if (typeof callback === 'function') {
callback(response);
}
},
error: function (xhr, ajaxOptions, error) {
swal({
title: globals.translations.errorTitle,
html: globals.translations.errorMessage,
type: "error",
})
},
});
} else {
redirect(href, data, method, blank);
}
},
function (dismiss) {}
);

View File

@ -26,7 +26,7 @@ class FileManager implements ManagerInterface
$options['id_plugin'] = !empty($options['id_plugin']) ? $options['id_plugin'] : null;
// ID del form
$attachment_id = 'attachments_'.$options['id_module'].'-'.$options['id_plugin'];
$attachment_id = 'attachments_'.$options['id_module'].'_'.$options['id_plugin'];
// Cartella delle anteprime
$directory = \Uploads::getDirectory($options['id_module'], $options['id_plugin']);
@ -121,7 +121,7 @@ class FileManager implements ManagerInterface
if (!$options['readonly']) {
$result .= '
<a class="btn btn-xs btn-danger ask" data-backto="record-edit" data-msg="'.tr('Vuoi eliminare questo file?').'" data-op="unlink_file" data-id="'.$r['id'].'" data-filename="'.$r['filename'].'">
<a class="btn btn-xs btn-danger ask" data-backto="record-edit" data-msg="'.tr('Vuoi eliminare questo file?').'" data-op="unlink_file" data-id="'.$r['id'].'" data-filename="'.$r['filename'].'" data-callback="reload_'.$attachment_id.'">
<i class="fa fa-trash"></i>
</a>';
}
@ -222,7 +222,7 @@ $(document).ready(function(){
$("#'.$attachment_id.' #upload").prop("disabled", true).html(percentComplete + "%").removeClass("btn-success").addClass("btn-info");
},
success: function(data){
$("#'.$attachment_id.'").load(globals.rootdir + "/ajax.php?op=list_attachments&id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id_plugin='.$options['id_plugin'].'");
reload_'.$attachment_id.'();
},
error: function(data) {
alert("'.tr('Errore').': " + data);
@ -230,6 +230,10 @@ $(document).ready(function(){
});
});
});
function reload_'.$attachment_id.'() {
$("#'.$attachment_id.'").load(globals.rootdir + "/ajax.php?op=list_attachments&id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id_plugin='.$options['id_plugin'].'");
}
</script>';
return $result;

View File

@ -193,12 +193,12 @@ class Uploads
{
$database = Database::getConnection();
$name = $database->selectOne('zz_files', ['nome'], [
$name = $database->selectOne('zz_files', ['name'], [
'filename' => $filename,
'id_module' => !empty($data['id_module']) ? $data['id_module'] : null,
'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null,
'id_record' => $data['id_record'],
])['nome'];
])['name'];
$fileinfo = self::fileInfo($filename);
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);