diff --git a/assets/src/js/base/datatables-buttons.js b/assets/src/js/base/datatables-buttons.js index 5a1048abb..234f35ca7 100644 --- a/assets/src/js/base/datatables-buttons.js +++ b/assets/src/js/base/datatables-buttons.js @@ -66,7 +66,9 @@ $(document).ready(function () { type: 'GET', dataType: "json", success: function (response) { - var row_ids = response.data.map(function(a) {return a.id;}); + var row_ids = response.data.map(function (a) { + return a.id; + }); // Chiamata di selezione completa wrapper.addSelectedRows(row_ids); diff --git a/assets/src/js/base/sidebar.js b/assets/src/js/base/sidebar.js index 092144e40..545aa1ff3 100644 --- a/assets/src/js/base/sidebar.js +++ b/assets/src/js/base/sidebar.js @@ -64,11 +64,11 @@ $(document).ready(function () { }); // Mostra/nasconde sidebar sx - $(".sidebar-toggle").on("click", function(){ - if ($( "body" ).hasClass( "sidebar-collapse" )){ - session_set("settings,sidebar-collapse",0,1,0); - }else{ - session_set("settings,sidebar-collapse",1,0,0); + $(".sidebar-toggle").on("click", function () { + if ($("body").hasClass("sidebar-collapse")) { + session_set("settings,sidebar-collapse", 0, 1, 0); + } else { + session_set("settings,sidebar-collapse", 1, 0, 0); } }); diff --git a/assets/src/js/functions/datatables.js b/assets/src/js/functions/datatables.js index cdbbb9ba3..2635f3beb 100755 --- a/assets/src/js/functions/datatables.js +++ b/assets/src/js/functions/datatables.js @@ -415,7 +415,7 @@ function getTable(selector) { } // Aggiornamento del footer nel caso sia richiesto - if (globals.restrict_summables_to_selected){ + if (globals.restrict_summables_to_selected) { this.updateSelectedFooter(); } }, diff --git a/assets/src/js/functions/dates.js b/assets/src/js/functions/dates.js index 3193549ed..211079bf6 100755 --- a/assets/src/js/functions/dates.js +++ b/assets/src/js/functions/dates.js @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -function getCalendarIcons(){ - return { +function getCalendarIcons() { + return { time: 'fa fa-clock-o', date: 'fa fa-calendar', up: 'fa fa-chevron-up', diff --git a/assets/src/js/functions/functions.js b/assets/src/js/functions/functions.js index b676f5257..4526ed684 100755 --- a/assets/src/js/functions/functions.js +++ b/assets/src/js/functions/functions.js @@ -199,17 +199,6 @@ function setContrast(backgroundcolor) { } } -function confirmDelete(button, title, message) { - return swal({ - title: title ? title : globals.translations.deleteTitle, - html: message ? message : globals.translations.deleteMessage, - type: "warning", - showCancelButton: true, - confirmButtonText: globals.translations.delete, - confirmButtonClass: "btn btn-lg btn-danger", - }) -} - function message(element) { data = $.extend({}, $(element).data()); @@ -371,31 +360,6 @@ function getCookie(cname) { return ""; } -function buttonLoading(button) { - var $this = $(button); - - var result = [ - $this.html(), - $this.attr("class") - ]; - - $this.html(' Attendere...'); - $this.addClass("btn-warning"); - $this.prop("disabled", true); - - return result; -} - -function buttonRestore(button, loadingResult) { - var $this = $(button); - - $this.html(loadingResult[0]); - - $this.attr("class", ""); - $this.addClass(loadingResult[1]); - $this.prop("disabled", false); -} - function submitAjax(form, data, callback, errorCallback) { let valid = $(form).parsley().validate(); if (!valid) { @@ -469,23 +433,22 @@ function renderMessages() { $.ajax({ url: globals.rootdir + '/ajax.php', type: 'get', + dataType: 'JSON', data: { op: 'flash', }, - success: function (flash) { - messages = JSON.parse(flash); - - info = messages.info ? messages.info : []; + success: function (messages) { + let info = messages.info ? messages.info : []; info.forEach(function (element) { if (element) toastr["success"](element); }); - warning = messages.warning ? messages.warning : []; + let warning = messages.warning ? messages.warning : []; warning.forEach(function (element) { if (element) toastr["warning"](element); }); - error = messages.error ? messages.error : []; + let error = messages.error ? messages.error : []; error.forEach(function (element) { if (element) toastr["error"](element); }); @@ -512,7 +475,7 @@ function cleanup_inputs() { let $this = $(this); if ($this.data('select2')) { - $this.select2().select2("destroy") + input(this).destroy(); } }); } @@ -571,6 +534,80 @@ function alertPush() { } /** + * Fuinzione per l'apertura del messaggi di rimozione elemento standard. + * + * @param button + * @param title + * @param message + * @returns {*} + */ +function confirmDelete(button, title, message) { + return swal({ + title: title ? title : globals.translations.deleteTitle, + html: message ? message : globals.translations.deleteMessage, + type: "warning", + showCancelButton: true, + confirmButtonText: globals.translations.delete, + confirmButtonClass: "btn btn-lg btn-danger", + }) +} + +/** + * Funzione per la gestione delle animazioni di caricamento sui pulsanti cliccati e appositamente predisposti, + * + * @param button + * @returns {[*, *]} + */ +function buttonLoading(button) { + var $this = $(button); + + var result = [ + $this.html(), + $this.attr("class") + ]; + + $this.html(' Attendere...'); + $this.addClass("btn-warning"); + $this.prop("disabled", true); + + return result; +} + +/** + * Funzione per ripristinare un pulsante con animazioni allo stato precedente. + * + * @param button + * @param loadingResult + */ +function buttonRestore(button, loadingResult) { + var $this = $(button); + + $this.html(loadingResult[0]); + + $this.attr("class", ""); + $this.addClass(loadingResult[1]); + $this.prop("disabled", false); +} + +/** + * Funzione per serializzare i contenuti di un form in JSON. + * + * @param form + * @returns {object} + */ +function serializeForm(form) { + let obj = {}; + + let formData = new FormData(form); + for (let key of formData.keys()) { + obj[key] = formData.get(key); + } + + return obj; +} + +/** + * Funzione per salvare i contenuti di un form via AJAX, utilizzando una struttura più recente fondata sull'utilizzo di Promise. * * @param button * @param form @@ -669,7 +706,12 @@ function hideTableColumn(table, column) { } /** - * Loads a JavaScript file and returns a Promise for when it is loaded + * Funzione per caricare un file JavaScript ed eseguire delle operazioni al completamento. + * + * @param src + * @param async + * @param defer + * @returns {Promise} */ function loadScript(src, async = true, defer = true) { if (!globals.dynamicScripts) { @@ -715,6 +757,13 @@ function loadScript(src, async = true, defer = true) { }) } +/** + * Funzione per aggiungere in un *endpoint* il contenuto di uno specifico *template*, effettuando delle sostituzioni di base e inizializzando i campi aggiunti. + * @param endpoint_selector + * @param template_selector + * @param replaces + * @returns {*|jQuery|HTMLElement} + */ function aggiungiContenuto(endpoint_selector, template_selector, replaces = {}) { let template = $(template_selector); let endpoint = $(endpoint_selector); diff --git a/assets/src/js/functions/hooks.js b/assets/src/js/functions/hooks.js index aca744e66..78babb238 100755 --- a/assets/src/js/functions/hooks.js +++ b/assets/src/js/functions/hooks.js @@ -144,7 +144,7 @@ function updateHook(hook) { $("#hooks-notified").html(''); $("#hooks-label").removeClass(); $("#hooks-label").addClass('label').addClass('label-success'); - }else{ + } else { $("#hooks-notified").text(number); $("#hooks-label").removeClass(); $("#hooks-label").addClass('label').addClass('label-danger'); diff --git a/assets/src/js/functions/input.js b/assets/src/js/functions/input.js index 8b2908367..a7e76d96c 100644 --- a/assets/src/js/functions/input.js +++ b/assets/src/js/functions/input.js @@ -16,6 +16,15 @@ * along with this program. If not, see . */ +/** + * Funzione semplificata per accedere ad uno specifico input. + * Accetta un oggetto jQuery, oppure un elemento JS HTMLElement, oppure il nome dell'input di interesse. + * + * Attenzione: in caso di molteplici input individuati, viene restituito l'ultimo individuato. + * + * @param {string|jQuery|HTMLElement} name + * @returns {Input|*} + */ function input(name) { let element; @@ -66,7 +75,9 @@ function Input(element) { this.init(); } - +/** + * Effettua le operazioni di inizializzazione sull'input in base alla relativa tipologia. + */ Input.prototype.init = function () { let initCompleted = false; let htmlElement = this.element[0]; @@ -106,13 +117,24 @@ Input.prototype.init = function () { initCompleted = initMaskInput(htmlElement); } - this.element.data("input-init", initCompleted); + this.element.data("input-init", !!initCompleted); } +/** + * Restituisce l'elemento jQuery che rappresenta l'input. + * + * @returns {jQuery} + */ Input.prototype.getElement = function () { return this.element; } +/** + * Gestisce l'abilitazione e la disibilitazione dell'input sulla base del valore indicato. + * + * @param {bool} value + * @returns {Input} + */ Input.prototype.setDisabled = function (value) { if (value) { return this.disable(); @@ -121,6 +143,11 @@ Input.prototype.setDisabled = function (value) { } } +/** + * Disabilita l'input all'utilizzo grafico. + * + * @returns {Input} + */ Input.prototype.disable = function () { this.element.addClass("disabled") .attr("disabled", true) @@ -150,6 +177,11 @@ Input.prototype.disable = function () { return this; } +/** + * Abilita l'input all'utilizzo grafico. + * + * @returns {Input} + */ Input.prototype.enable = function () { this.element.removeClass("disabled") .attr("disabled", false) @@ -179,6 +211,11 @@ Input.prototype.enable = function () { return this; } +/** + * Restituisce un oggetto cotentente le caratteristiche dell'input. + * + * @returns {{value: (string|number)}|jQuery|any} + */ Input.prototype.getData = function () { if (this.element.is('select')) { return this.element.selectData(); @@ -237,6 +274,11 @@ Input.prototype.set = function (value) { return this; } +/** + * Imposta l'input per essere obbligatorio o meno. + * @param {bool} value + * @returns {Input} + */ Input.prototype.setRequired = function (value) { this.element.attr("required", value) .data("required", value); @@ -245,22 +287,60 @@ Input.prototype.setRequired = function (value) { } // Eventi permessi +/** + * Gestisce gli eventi di tipologia "change". + * + * @param callable + * @returns {Input} + */ Input.prototype.change = function (callable) { - return this.on("change", callable); + this.on("change", callable) + + return this; } +/** + * Gestisce l'ascolto a uno specifico evento sulla base dell'oggetto jQuery. + * + * @param {string} event + * @param callable + * + * @returns {Input} + */ Input.prototype.on = function (event, callable) { - return this.element.on(event, callable); + this.element.on(event, callable); + + return this; } +/** + * Gestisce la rimozione degli ascoltatori attivi per uno specifico evento sulla base dell'oggetto jQuery. + * + * @param {string} event + * + * @returns {Input} + */ Input.prototype.off = function (event) { - return this.element.off(event); + this.element.off(event); + + return this; } +/** + * Effettua il trigger di uno specifico evento sull'input. + * @param {string} event + * @param callable + * @returns {Input} + */ Input.prototype.trigger = function (event, callable) { - return this.element.trigger(event, callable); + this.element.trigger(event, callable); + + return this; } +/** + * Distrugge il gestore attuale per l'input e ne disabilita le funzionalità previste. + */ Input.prototype.destroy = function () { if (this.element.data('select2')) { this.element.select2().select2("destroy") @@ -273,6 +353,7 @@ Input.prototype.destroy = function () { } this.element.data("input-controller", null); + this.element.data("input-init", false); } /** diff --git a/assets/src/js/functions/inputmask.js b/assets/src/js/functions/inputmask.js index c42619150..dc5ce1b73 100644 --- a/assets/src/js/functions/inputmask.js +++ b/assets/src/js/functions/inputmask.js @@ -16,28 +16,32 @@ * along with this program. If not, see . */ +/** + * Funzione per l'inizializzazione delle maschere sui campi impostati. + * @param input + */ function initMaskInput(input) { let $input = $(input); - if ($input.hasClass('email-mask')){ + if ($input.hasClass('email-mask')) { $input.inputmask('Regex', { regex: "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$", }); - } else if ($input.hasClass('rea-mask')){ + } else if ($input.hasClass('rea-mask')) { $input.inputmask({ mask: "AA-999999{1,15}", casing: "upper", }); - } else if ($input.hasClass('provincia-mask')){ + } else if ($input.hasClass('provincia-mask')) { $input.inputmask({ mask: "AA", casing: "upper", }); - } else if ($input.hasClass('alphanumeric-mask')){ + } else if ($input.hasClass('alphanumeric-mask')) { $input.inputmask('Regex', { regex: "[A-Za-z0-9#_|\/\\-.]*", }); - } else if ($input.hasClass('math-mask')){ + } else if ($input.hasClass('math-mask')) { $input.inputmask('Regex', { regex: "[0-9,.+\-]*", }); @@ -47,7 +51,8 @@ function initMaskInput(input) { } /** - * Inputmask + * Inputmask. + * * @param element */ function start_inputmask(element) { @@ -57,7 +62,7 @@ function start_inputmask(element) { element = element + ' '; } - let masks = ['math-mask','alphanumeric-mask', 'provincia-mask','rea-mask', 'email-mask']; + let masks = ['math-mask', 'alphanumeric-mask', 'provincia-mask', 'rea-mask', 'email-mask']; let selector = element + '.' + masks.join(', ' + element + '.') $(selector).each(function () { diff --git a/assets/src/js/functions/numbers.js b/assets/src/js/functions/numbers.js index 6891b0a34..d687d7850 100644 --- a/assets/src/js/functions/numbers.js +++ b/assets/src/js/functions/numbers.js @@ -27,6 +27,10 @@ function initNumbers() { }); } +/** + * Funzione per l'inizializzazione dei campi numerici. + * @param input + */ function initNumberInput(input) { let $input = $(input); if (AutoNumeric.isManagedByAutoNumeric(input)) { diff --git a/assets/src/js/functions/prototypes.js b/assets/src/js/functions/prototypes.js index 1e91e7c97..08d176100 100755 --- a/assets/src/js/functions/prototypes.js +++ b/assets/src/js/functions/prototypes.js @@ -16,18 +16,6 @@ * along with this program. If not, see . */ -Number.prototype.formatMoney = function (c, d, t) { - var n = this, - c = isNaN(c = Math.abs(c)) ? 2 : c, - d = d == undefined ? "." : d, - t = t == undefined ? "," : t, - s = n < 0 ? "-" : "", - i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", - j = (j = i.length) > 3 ? j % 3 : 0; - - return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); -}; - String.prototype.toEnglish = function () { return numeral(this.toString()).value(); }; @@ -35,10 +23,3 @@ String.prototype.toEnglish = function () { Number.prototype.toLocale = function () { return numeral(this).format(); }; - -jQuery.fn.scrollTo = function (elem, speed) { - $(this).animate({ - scrollTop: $(this).scrollTop() - $(this).offset().top + $(elem).offset().top - }, speed === undefined ? 1000 : speed); - return this; -}; diff --git a/assets/src/js/functions/select.js b/assets/src/js/functions/select.js index bbc5d8bf1..2da53863d 100755 --- a/assets/src/js/functions/select.js +++ b/assets/src/js/functions/select.js @@ -27,6 +27,13 @@ function start_superselect() { }); } +/** + * Gestisce le operazioni di rendering per una singola opzione del select. + * + * @param data + * @param container + * @returns {*} + */ function selectOptionRender(data, container) { let bg; @@ -179,6 +186,8 @@ function updateSelectOption(name, value) { } /** + * Funzione per l'inizializzazione automatica del select. + * * @param input */ function initSelectInput(input) { @@ -190,11 +199,12 @@ function initSelectInput(input) { initDynamicSelectInput(input); } - return $input.data('select'); + return $input.data('select2'); } /** - * Statico. + * Funzione per l'inizializzazione del select statico. + * * @param input */ function initStaticSelectInput(input) { @@ -215,7 +225,8 @@ function initStaticSelectInput(input) { } /** - * Dinamico. + * Funzione per l'inizializzazione del select dinamico. + * * @param input */ function initDynamicSelectInput(input) { diff --git a/assets/src/js/functions/textarea.js b/assets/src/js/functions/textarea.js index 8c432b45b..e2c318f46 100644 --- a/assets/src/js/functions/textarea.js +++ b/assets/src/js/functions/textarea.js @@ -16,12 +16,20 @@ * along with this program. If not, see . */ +/** + * Funzione per l'inizializzazione dei campi textarea. + * @param input + */ function initTextareaInput(input) { autosize($(input)); return true; } +/** + * Funzione per l'inizializzazione dei campi editor. + * @param input + */ function initEditorInput(input) { let $input = $(input); let name = input.getAttribute("id"); diff --git a/modules/impianti/add.php b/modules/impianti/add.php index 51bca16aa..eb079f077 100644 --- a/modules/impianti/add.php +++ b/modules/impianti/add.php @@ -35,7 +35,7 @@ $id_anagrafica = filter('id_anagrafica');
- {[ "type": "select", "label": "", "name": "idanagrafica", "required": 1, "value": "", "ajax-source": "clienti", "icon-after": "add||tipoanagrafica=Cliente&readonly_tipo=1" ]} + {[ "type": "select", "label": "", "name": "idanagrafica", "id": "idanagrafica_impianto", "required": 1, "value": "", "ajax-source": "clienti", "icon-after": "add||tipoanagrafica=Cliente&readonly_tipo=1" ]}
diff --git a/modules/interventi/add.php b/modules/interventi/add.php index c72d677ba..72e35994f 100755 --- a/modules/interventi/add.php +++ b/modules/interventi/add.php @@ -303,9 +303,8 @@ echo '
- +'; -'; if (!empty($id_intervento)) { echo '