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 <?php
echo ' echo '
<script> <script>
$( ".btn-sm[data-toggle=\"tooltip\"]" ).each(function() { $( ".btn-sm[data-toggle=\"tooltip\"]" ).each(function() {
$(this).on("click", 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; content_was_modified = false;
form.find("input:disabled, select:disabled").removeAttr("disabled");
$.ajax({ $.ajax({
url: "'.ROOTDIR.'/modules/fatture/actions.php?id_module=" + globals.id_module , url: "'.ROOTDIR.'/modules/fatture/actions.php?id_module=" + globals.id_module ,
cache: false, cache: false,
type: "POST", type: "POST",
processData: false, processData: false,
dataType : "html", dataType : "html",
data: $("#edit-form").serialize(), data: form.serialize(),
success: function(data) { success: function(data) {
$("#main_loading").fadeOut(); $("#main_loading").fadeOut();
restore_btn(btn, prev_html, prev_class);
}, },
error: function(data) { error: function(data) {
$("#main_loading").fadeOut(); $("#main_loading").fadeOut();
swal("'.tr('Errore').'", "'.tr('Errore durante il salvataggio').'", "error"); swal("'.tr('Errore').'", "'.tr('Errore durante il salvataggio').'", "error");
session_set ("errors,0", 0, 1); 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>'; </script>';