Miglioramento documentazione funzioni JS

Correzioni minori su modal di creazione Attività e Impianti.
This commit is contained in:
Dasc3er 2020-10-20 14:12:53 +02:00
parent 563a6f24c2
commit 7866fe25a5
14 changed files with 232 additions and 92 deletions

View File

@ -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);

View File

@ -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);
}
});

View File

@ -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();
}
},

View File

@ -16,8 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
function getCalendarIcons(){
return {
function getCalendarIcons() {
return {
time: 'fa fa-clock-o',
date: 'fa fa-calendar',
up: 'fa fa-chevron-up',

View File

@ -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('<i class="fa fa-spinner fa-pulse fa-fw"></i> 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('<i class="fa fa-spinner fa-pulse fa-fw"></i> 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<unknown>}
*/
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);

View File

@ -144,7 +144,7 @@ function updateHook(hook) {
$("#hooks-notified").html('<i class="fa fa-check" aria-hidden="true"></i>');
$("#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');

View File

@ -16,6 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* 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);
}
/**

View File

@ -16,28 +16,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* 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 () {

View File

@ -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)) {

View File

@ -16,18 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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;
};

View File

@ -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) {

View File

@ -16,12 +16,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* 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");

View File

@ -35,7 +35,7 @@ $id_anagrafica = filter('id_anagrafica');
</div>
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Cliente'); ?>", "name": "idanagrafica", "required": 1, "value": "<?php echo $id_anagrafica; ?>", "ajax-source": "clienti", "icon-after": "add|<?php echo Modules::get('Anagrafiche')['id']; ?>|tipoanagrafica=Cliente&readonly_tipo=1" ]}
{[ "type": "select", "label": "<?php echo tr('Cliente'); ?>", "name": "idanagrafica", "id": "idanagrafica_impianto", "required": 1, "value": "<?php echo $id_anagrafica; ?>", "ajax-source": "clienti", "icon-after": "add|<?php echo Modules::get('Anagrafiche')['id']; ?>|tipoanagrafica=Cliente&readonly_tipo=1" ]}
</div>
<div class="col-md-4">

View File

@ -303,9 +303,8 @@ echo '
</button>
</div>
</div>
</form>
</form>';
<script>$(document).ready(init)</script>';
if (!empty($id_intervento)) {
echo '