Migliorata procedura di salvataggio ajax

This commit is contained in:
Luca 2018-07-26 17:34:12 +02:00
parent b4da7bc278
commit dacf81a1ab
1 changed files with 57 additions and 2 deletions

View File

@ -410,25 +410,80 @@ if (!empty($note_accredito)) {
<?php
echo '
<script>
$( ".btn-sm[data-toggle=\"tooltip\"]" ).each(function() {
$(this).on("click", function(){
form = $("#edit-form");
btn = $(this);
prev_html = btn.html();
prev_class = btn.attr("class");
btn.html("<i class=\"fa fa-spinner fa-pulse fa-fw\"></i> Attendere...");
btn.addClass("btn-warning");
btn.prop("disabled", true);
function restore_btn(btn, prev_html, prev_class){
btn.attr("class", "");
btn.addClass(prev_class);
btn.html(prev_html);
btn.prop("disabled", false);
}
//Procedo al salvataggio solo se tutti i campi obbligatori sono compilati, altimenti mostro avviso
if (form.parsley().isValid()){
content_was_modified = false;
form.find("input:disabled, select:disabled").removeAttr("disabled");
$.ajax({
url: "'.ROOTDIR.'/modules/fatture/actions.php?id_module=" + globals.id_module ,
cache: false,
type: "POST",
processData: false,
dataType : "html",
data: $("#edit-form").serialize(),
data: form.serialize(),
success: function(data) {
$("#main_loading").fadeOut();
restore_btn(btn, prev_html, prev_class);
},
error: function(data) {
$("#main_loading").fadeOut();
swal("'.tr('Errore').'", "'.tr('Errore durante il salvataggio').'", "error");
session_set ("errors,0", 0, 1);
restore_btn(btn, prev_html, prev_class);
}
})
});
}else{
swal({
type: "error",
text: "'.tr('Alcuni campi obbligatori non sono stati compilati correttamente.').'",
title: "'.tr('Errore').'",
onClose: hide_popup
}).then(function () {
});
function hide_popup(){
$("#bs-popup").modal("hide");
session_set ("errors,0", 0, 1);
form.parsley().validate();
}
restore_btn(btn, prev_html, prev_class);
}
});
});
</script>';