diff --git a/assets/src/js/functions/functions.js b/assets/src/js/functions/functions.js index aac7ca8b5..9b9ca1a76 100755 --- a/assets/src/js/functions/functions.js +++ b/assets/src/js/functions/functions.js @@ -12,9 +12,9 @@ function openModal(title, href) { // Generazione dinamica modal do { id = '#bs-popup-' + Math.floor(Math.random() * 100); - } while ($(id).length != 0); + } while ($(id).length !== 0); - if ($(id).length == 0) { + if ($(id).length === 0) { $('#modals').append(''); } @@ -40,14 +40,14 @@ function openModal(title, href) { '; // Lettura contenuto div - if (href.substr(0, 1) == '#') { + if (href.substr(0, 1) === '#') { var data = $(href).html(); $(id).html(content.replace("|data|", data)); $(id).modal('show'); } else { $.get(href, function (data, response) { - if (response == 'success') { + if (response === 'success') { $(id).html(content.replace("|data|", data)); $(id).modal('show'); } @@ -65,7 +65,7 @@ function openLink(event, link) { /** * Funzione per far scrollare la pagina fino a un offset - * @param integer offset + * @param offset */ function scrollToOffset(offset) { $('html,body').animate({ @@ -80,11 +80,9 @@ function getUrlVars() { var search = window.location.search.substring(1); if (!search) return {}; - var results = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}', function (key, value) { + return JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}', function (key, value) { return key === "" ? value : decodeURIComponent(value) }); - - return results; } // Data e ora (orologio) @@ -108,19 +106,18 @@ function session_set_array(session_array, value, inversed) { * Funzione per impostare un valore ad una sessione */ function session_set(session_array, value, clear, reload) { - if (clear == undefined) { + if (clear === undefined) { clear = 1; } - if (reload == undefined) { + if (reload === undefined) { reload = 0; } return $.get(globals.rootdir + "/ajax.php?op=session_set&session=" + session_array + "&value=" + value + "&clear=" + clear, function (data, status) { - - if (reload == 1) + if (reload === 1) { location.reload(); - + } }); } @@ -377,49 +374,52 @@ function buttonRestore(button, loadingResult) { } function submitAjax(form, data, callback, errorCallback) { - var valid = $(form).parsley().validate(); + let valid = $(form).parsley().validate(); + if (!valid) { + return valid; + } if (!data) data = {}; - if (valid) { - $("#main_loading").show(); + $("#main_loading").show(); + content_was_modified = false; - content_was_modified = false; + // Fix per gli id di default + data.id_module = data.id_module ? data.id_module : globals.id_module; + data.id_record = data.id_record ? data.id_record : globals.id_record; + data.id_plugin = data.id_plugin ? data.id_plugin : globals.id_plugin; + data.ajax = 1; - // Fix per gli id di default - data.id_module = data.id_module ? data.id_module : globals.id_module; - data.id_record = data.id_record ? data.id_record : globals.id_record; - data.id_plugin = data.id_plugin ? data.id_plugin : globals.id_plugin; - data.ajax = 1; + prepareForm(form); - prepareForm(form); + // Invio dei dati + $(form).ajaxSubmit({ + url: globals.rootdir + "/actions.php", + data: data, + type: "post", + success: function (data) { + let response = data.trim(); - // Invio dei dati - $(form).ajaxSubmit({ - url: globals.rootdir + "/actions.php", - data: data, - type: "post", - success: function (data) { - data = data.trim(); - - if (data) { - response = JSON.parse(data); - if (callback) callback(response); - } - - $("#main_loading").fadeOut(); - - renderMessages(); - }, - error: function (data) { - $("#main_loading").fadeOut(); - - toastr["error"](data); - - if (errorCallback) errorCallback(data); + // Tentativo di conversione da JSON + try { + response = JSON.parse(response); + } catch (e) { } - }); - } + + callback(response); + + $("#main_loading").fadeOut(); + + renderMessages(); + }, + error: function (data) { + $("#main_loading").fadeOut(); + + toastr["error"](data); + + if (errorCallback) errorCallback(data); + } + }); return valid; } @@ -522,3 +522,36 @@ function alertPush() { }); }); } + +function salvaForm(button, form) { + return new Promise(function (resolve, reject) { + // Caricamento visibile nel pulsante + let restore = buttonLoading(button); + + // Messaggio in caso di eventuali errori + let valid = $(form).parsley().validate(); + if (!valid) { + swal({ + type: "error", + title: globals.translations.ajax.missing.title, + text: globals.translations.ajax.missing.text, + }); + + resolve(false); + } + + submitAjax(form, {}, function (response) { + buttonRestore(button, restore); + resolve(true); + }, function (data) { + swal({ + type: "error", + title: globals.translations.ajax.error.title, + text: globals.translations.ajax.error.text, + }); + + buttonRestore(button, restore); + resolve(false); + }); + }); +} diff --git a/include/top.php b/include/top.php index 1d89e6617..867b96662 100755 --- a/include/top.php +++ b/include/top.php @@ -101,6 +101,16 @@ if (Auth::check()) { '.$key.': "'.addslashes($value).'",'; } echo ' + ajax: { + "missing": { + "title": "'.tr('Errore').'", + "text": "'.tr('Alcuni campi obbligatori non sono stati compilati correttamente').'", + }, + "error": { + "title": "'.tr('Errore').'", + "text": "'.tr('Errore durante il salvataggio del record').'", + } + }, password: { "wordMinLength": "'.tr('La password è troppo corta').'", "wordMaxLength": "'.tr('La password è troppo lunga').'", diff --git a/modules/contratti/edit.php b/modules/contratti/edit.php index 9f5594dbf..1fc173669 100755 --- a/modules/contratti/edit.php +++ b/modules/contratti/edit.php @@ -287,7 +287,8 @@ if (!empty($rs)) { echo ' '; } -?> + echo ' + @@ -295,52 +296,51 @@ if (!empty($rs)) { -
-

+

'.tr('Righe').'

-
-'; + if (!$block_edit) { echo ' - + '; echo ' - + '; echo ' - + '; echo ' - + '; echo ' - + '; } -?> + +echo '

-
-'; -include $docroot.'/modules/contratti/row-list.php'; +include $structure->filepath('row-list.php'); -?> +echo '
@@ -351,46 +351,76 @@ include $docroot.'/modules/contratti/row-list.php'; {( "name": "log_email", "id_module": "$id_module$", "id_record": "$id_record$" )} +$("#codice_cig, #codice_cup").bind("keyup change", function(e) { + + if ($("#codice_cig").val() == "" && $("#codice_cup").val() == "" ){ + $("#id_documento_fe").prop("required", false); + }else{ + $("#id_documento_fe").prop("required", true); + } +}); +'; -fetchArray('SELECT 0 AS `codice`, `co_documenti`.`id` AS `id`, `co_documenti`.`numero` AS `numero`, `co_documenti`.`numero_esterno` AS `numero_esterno`, `co_documenti`.`data`, `co_tipidocumento`.`descrizione` AS `tipo_documento`, `co_tipidocumento`.`dir` AS `dir` FROM `co_documenti` JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`id` IN (SELECT `iddocumento` FROM `co_righe_documenti` WHERE `idcontratto` = '.prepare($id_record).')'.' diff --git a/modules/contratti/row-list.php b/modules/contratti/row-list.php index 2bb1d1140..92d30b565 100755 --- a/modules/contratti/row-list.php +++ b/modules/contratti/row-list.php @@ -192,12 +192,18 @@ echo ' echo ' +function gestioneBarcode(button) { + gestioneRiga(button, "is_barcode"); +} + +function gestioneSconto(button) { + gestioneRiga(button, "is_sconto"); +} + +function gestioneDescrizione(button) { + gestioneRiga(button, "is_descrizione"); +} + +async function gestioneRiga(button, options) { + // Salvataggio via AJAX + let valid = await salvaForm(button, $("#edit-form")); + + // Apertura modal + if (valid) { + // Lettura titolo e chiusura tooltip + let title = $(button).tooltipster("content"); + $(button).tooltipster("close") + + // Apertura modal + options = options ? options : "is_riga"; + openModal(title, "'.$structure->fileurl('row-add.php').'?id_module='.$id_module.'&id_record='.$id_record.'&" + options); + } +} + +$("#idanagrafica").change(function() { + updateSelectOption("idanagrafica", $(this).val()); + session_set("superselect,idanagrafica", $(this).val(), 0); + + $("#idsede_'.($dir == 'uscita' ? 'partenza' : 'destinazione').'").selectReset(); +}); +'; -fetchArray('SELECT `co_documenti`.*, `co_tipidocumento`.`descrizione` AS tipo_documento, `co_tipidocumento`.`dir` FROM `co_documenti` JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`id` IN (SELECT `iddocumento` FROM `co_righe_documenti` WHERE `idddt` = '.prepare($id_record).') ORDER BY `data`'); diff --git a/modules/ddt/row-list.php b/modules/ddt/row-list.php index 1778ce7c7..aa6e9e96f 100755 --- a/modules/ddt/row-list.php +++ b/modules/ddt/row-list.php @@ -254,12 +254,18 @@ echo ' echo ' '; // Collegamenti diretti // Fatture o ddt collegati a questo ordine @@ -296,25 +349,3 @@ if (!empty($elementi)) { - diff --git a/modules/ordini/row-list.php b/modules/ordini/row-list.php index 0b47f5677..143d4b9d9 100755 --- a/modules/ordini/row-list.php +++ b/modules/ordini/row-list.php @@ -235,13 +235,18 @@ echo ' echo ' - - - {( "name": "filelist_and_upload", "id_module": "$id_module$", "id_record": "$id_record$" )} {( "name": "log_email", "id_module": "$id_module$", "id_record": "$id_record$" )} - +function gestioneArticolo(button) { + gestioneRiga(button, "is_articolo"); +} + +function gestioneBarcode(button) { + gestioneRiga(button, "is_barcode"); +} + +function gestioneSconto(button) { + gestioneRiga(button, "is_sconto"); +} + +function gestioneDescrizione(button) { + gestioneRiga(button, "is_descrizione"); +} + +async function gestioneRiga(button, options) { + // Salvataggio via AJAX + let valid = await salvaForm(button, $("#edit-form")); + + // Apertura modal + if (valid) { + // Lettura titolo e chiusura tooltip + let title = $(button).tooltipster("content"); + $(button).tooltipster("close") + + // Apertura modal + options = options ? options : "is_riga"; + openModal(title, "'.$structure->fileurl('row-add.php').'?id_module='.$id_module.'&id_record='.$id_record.'&" + options); + } +} + +$(document).ready(function() { + $("#idanagrafica").change(function() { + updateSelectOption("idanagrafica", $(this).val()); + session_set("superselect,idanagrafica", $(this).val(), 0); + + $("#idsede").selectReset(); + }); + + $("#data_accettazione").on("dp.change", function() { + if($(this).val()){ + $("#data_rifiuto").attr("disabled", true); + }else{ + $("#data_rifiuto").attr("disabled", false); + } + }); + + $("#data_rifiuto").on("dp.change", function() { + if($(this).val()){ + $("#data_accettazione").attr("disabled", true); + }else{ + $("#data_accettazione").attr("disabled", false); + } + }); + + $("#data_accettazione").trigger("dp.change"); + $("#data_rifiuto").trigger("dp.change"); + + $("#codice_cig, #codice_cup").bind("keyup change", function(e) { + + if ($("#codice_cig").val() == "" && $("#codice_cup").val() == "" ){ + $("#id_documento_fe").prop("required", false); + }else{ + $("#id_documento_fe").prop("required", true); + } + + }); + +}); +'; + //fatture, ordini collegate a questo preventivo $elementi = $dbo->fetchArray('SELECT `co_documenti`.`id`, `co_documenti`.`data`, `co_documenti`.`numero`, `co_documenti`.`numero_esterno`, `co_tipidocumento`.`descrizione` AS tipo_documento, `co_tipidocumento`.`dir` FROM `co_documenti` JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`id` IN (SELECT `iddocumento` FROM `co_righe_documenti` WHERE `idpreventivo` = '.prepare($id_record).') diff --git a/modules/preventivi/row-list.php b/modules/preventivi/row-list.php index 39e12c98f..3cebe5df7 100755 --- a/modules/preventivi/row-list.php +++ b/modules/preventivi/row-list.php @@ -218,13 +218,18 @@ echo ' echo '