Miglioramento della gestione JS dei campi di input
Correzioni per inizializzazione dei campi dalla funzione input
This commit is contained in:
parent
7e1c4d0b01
commit
cfc8c5512b
|
@ -16,8 +16,8 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function start_datepickers() {
|
function getCalendarIcons(){
|
||||||
var icons = {
|
return {
|
||||||
time: 'fa fa-clock-o',
|
time: 'fa fa-clock-o',
|
||||||
date: 'fa fa-calendar',
|
date: 'fa fa-calendar',
|
||||||
up: 'fa fa-chevron-up',
|
up: 'fa fa-chevron-up',
|
||||||
|
@ -28,64 +28,79 @@ function start_datepickers() {
|
||||||
clear: 'fa fa-trash',
|
clear: 'fa fa-trash',
|
||||||
close: 'fa fa-times'
|
close: 'fa fa-times'
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var date_format = dateFormatMoment(globals.date_format);
|
function initDateInput(input) {
|
||||||
var timestamp_format = dateFormatMoment(globals.timestamp_format);
|
let date_format = dateFormatMoment(globals.date_format);
|
||||||
var time_format = dateFormatMoment(globals.time_format);
|
let calendar_icons = getCalendarIcons();
|
||||||
|
|
||||||
$('.timestamp-picker').each(function () {
|
$(input).datetimepicker({
|
||||||
$this = $(this);
|
format: date_format,
|
||||||
$this.datetimepicker({
|
locale: globals.locale,
|
||||||
format: timestamp_format,
|
icons: calendar_icons,
|
||||||
locale: globals.locale,
|
useCurrent: false,
|
||||||
icons: icons,
|
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
|
||||||
collapse: false,
|
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
|
||||||
sideBySide: true,
|
});
|
||||||
useCurrent: false,
|
}
|
||||||
stepping: 5,
|
|
||||||
widgetPositioning: {
|
function initTimestampInput(input) {
|
||||||
horizontal: 'left',
|
let $this = $(input);
|
||||||
vertical: 'auto'
|
let timestamp_format = dateFormatMoment(globals.timestamp_format);
|
||||||
},
|
let calendar_icons = getCalendarIcons();
|
||||||
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
|
|
||||||
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
|
$this.datetimepicker({
|
||||||
});
|
format: timestamp_format,
|
||||||
|
locale: globals.locale,
|
||||||
|
icons: calendar_icons,
|
||||||
|
collapse: false,
|
||||||
|
sideBySide: true,
|
||||||
|
useCurrent: false,
|
||||||
|
stepping: 5,
|
||||||
|
widgetPositioning: {
|
||||||
|
horizontal: 'left',
|
||||||
|
vertical: 'auto'
|
||||||
|
},
|
||||||
|
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
|
||||||
|
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
//fix per timestamp-picker non visibile con la classe table-responsive
|
// fix per timestamp-picker non visibile con la classe table-responsive
|
||||||
|
$this.on("dp.show", function (e) {
|
||||||
|
$('#tecnici > div').removeClass('table-responsive');
|
||||||
|
});
|
||||||
|
|
||||||
|
$this.on("dp.hide", function (e) {
|
||||||
|
$('#tecnici > div').addClass('table-responsive');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function initTimeInput(input) {
|
||||||
|
let time_format = dateFormatMoment(globals.time_format);
|
||||||
|
let calendar_icons = getCalendarIcons();
|
||||||
|
|
||||||
|
$(input).datetimepicker({
|
||||||
|
format: time_format,
|
||||||
|
locale: globals.locale,
|
||||||
|
icons: calendar_icons,
|
||||||
|
useCurrent: false,
|
||||||
|
stepping: 5,
|
||||||
|
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
|
||||||
|
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function start_datepickers() {
|
||||||
$('.timestamp-picker').each(function () {
|
$('.timestamp-picker').each(function () {
|
||||||
$this = $(this);
|
initTimestampInput(this);
|
||||||
$this.on("dp.show", function (e) {
|
|
||||||
$('#tecnici > div').removeClass('table-responsive');
|
|
||||||
});
|
|
||||||
$this.on("dp.hide", function (e) {
|
|
||||||
$('#tecnici > div').addClass('table-responsive');
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.datepicker').each(function () {
|
$('.datepicker').each(function () {
|
||||||
$this = $(this);
|
initDateInput(this);
|
||||||
$this.datetimepicker({
|
|
||||||
format: date_format,
|
|
||||||
locale: globals.locale,
|
|
||||||
icons: icons,
|
|
||||||
useCurrent: false,
|
|
||||||
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
|
|
||||||
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.timepicker').each(function () {
|
$('.timepicker').each(function () {
|
||||||
$this = $(this);
|
initTimeInput(this);
|
||||||
$this.datetimepicker({
|
|
||||||
format: time_format,
|
|
||||||
locale: globals.locale,
|
|
||||||
icons: icons,
|
|
||||||
useCurrent: false,
|
|
||||||
stepping: 5,
|
|
||||||
minDate: moment($this.attr('min-date')).isValid() ? $this.attr('min-date') : false,
|
|
||||||
maxDate: moment($this.attr('max-date')).isValid() ? $this.attr('max-date') : false,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -515,7 +515,7 @@ function restart_inputs() {
|
||||||
start_superselect();
|
start_superselect();
|
||||||
|
|
||||||
// Autosize per le textarea
|
// Autosize per le textarea
|
||||||
autosize($('.autosize'));
|
initTextareaInput($('.autosize'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -648,3 +648,7 @@ function hideTableColumn(table, column) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initTextareaInput(input){
|
||||||
|
autosize($(input));
|
||||||
|
}
|
||||||
|
|
|
@ -17,29 +17,79 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function input(name) {
|
function input(name) {
|
||||||
return new Input(name);
|
let element;
|
||||||
}
|
|
||||||
|
|
||||||
function Input(name) {
|
|
||||||
// Selezione tramite jQuery
|
// Selezione tramite jQuery
|
||||||
if (name instanceof jQuery) {
|
if (name instanceof jQuery) {
|
||||||
this.element = name.last();
|
element = name.last();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Selezione tramite JS diretto
|
||||||
|
else if (isElement(name)) {
|
||||||
|
element = $(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selezione per nome
|
// Selezione per nome
|
||||||
else {
|
else {
|
||||||
this.element = $("[name='" + name + "']").last();
|
element = $("[name='" + name + "']").last();
|
||||||
|
|
||||||
// Fix per select multipli
|
// Fix per select multipli
|
||||||
if (this.element.length === 0) {
|
if (element.length === 0) {
|
||||||
this.element = $("[name='" + name + "[]']").last();
|
element = $("[name='" + name + "[]']").last();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!element.data("input-controller")) {
|
||||||
|
return new Input(element);
|
||||||
|
} else {
|
||||||
|
return element.data("input-controller");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @param {jQuery} element
|
||||||
|
*/
|
||||||
|
function Input(element) {
|
||||||
|
this.element = element;
|
||||||
|
|
||||||
// Controllo sulla gestione precedente
|
// Controllo sulla gestione precedente
|
||||||
if (!this.element.data("input-set")) {
|
if (!this.element.data("input-set")) {
|
||||||
this.element.data("input-set", 1);
|
return;
|
||||||
this.element.data("required", this.element.attr("required"));
|
}
|
||||||
|
|
||||||
|
this.element.data("input-set", 1);
|
||||||
|
this.element.data("required", this.element.attr("required"));
|
||||||
|
|
||||||
|
// Operazioni di inizializzazione per input specifici
|
||||||
|
// Inizializzazione per date
|
||||||
|
if (this.element.hasClass('timestamp-picker')) {
|
||||||
|
initTimestampInput(this.element);
|
||||||
|
} else if (this.element.hasClass('datepicker')) {
|
||||||
|
initDateInput(this.element);
|
||||||
|
} else if (this.element.hasClass('timepicker')) {
|
||||||
|
initTimeInput(this.element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inizializzazione per campi numerici
|
||||||
|
else if (this.element.hasClass('decimal-number')) {
|
||||||
|
initNumberInput(this.element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inizializzazione per textarea
|
||||||
|
else if (this.element.hasClass('autosize')) {
|
||||||
|
initTextareaInput(this.element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inizializzazione per select
|
||||||
|
else if (this.element.hasClass('superselect') || this.element.hasClass('superselectajax')) {
|
||||||
|
initSelectInput(this.element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inizializzazione alternativa per maschere
|
||||||
|
else {
|
||||||
|
initMaskInput(this.element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,24 +161,42 @@ Input.prototype.getData = function () {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restituisce il valore corrente dell'input.
|
||||||
|
*
|
||||||
|
* @returns {string|number}
|
||||||
|
*/
|
||||||
Input.prototype.get = function () {
|
Input.prototype.get = function () {
|
||||||
let value = this.element.val();
|
let value = this.element.val();
|
||||||
|
|
||||||
// Conversione del valore per le checkbox
|
// Conversione del valore per le checkbox
|
||||||
let group = this.element.closest(".form-group");
|
let group = this.element.closest(".form-group");
|
||||||
if (group.find("input[type=checkbox]").length) {
|
if (group.find("input[type=checkbox]").length) {
|
||||||
value = parseInt(value) ? 1 : 0;
|
return parseInt(value) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestione dei valori numerici
|
// Gestione dei valori numerici
|
||||||
const autonumeric = this.element.data("autonumeric");
|
if (this.element.hasClass("decimal-number")) {
|
||||||
if (autonumeric) {
|
const autonumeric = this.element.data("autonumeric");
|
||||||
value = parseFloat(autonumeric.rawValue);
|
|
||||||
|
if (autonumeric) {
|
||||||
|
return parseFloat(autonumeric.rawValue);
|
||||||
|
}
|
||||||
|
// In attesa dell'inizializzazione per autonumeric, il valore registrato è interpretabile
|
||||||
|
else {
|
||||||
|
return parseFloat(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imposta il valore per l'input.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @returns {Input}
|
||||||
|
*/
|
||||||
Input.prototype.set = function (value) {
|
Input.prototype.set = function (value) {
|
||||||
this.element.val(value).trigger("change");
|
this.element.val(value).trigger("change");
|
||||||
|
|
||||||
|
@ -154,3 +222,33 @@ Input.prototype.on = function (event, action) {
|
||||||
Input.prototype.off = function (event) {
|
Input.prototype.off = function (event) {
|
||||||
return this.element.off(event);
|
return this.element.off(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if it is a DOM node.
|
||||||
|
*
|
||||||
|
* @param o
|
||||||
|
* @returns boolean
|
||||||
|
*
|
||||||
|
* @source https://stackoverflow.com/a/384380
|
||||||
|
*/
|
||||||
|
function isNode(o) {
|
||||||
|
return (
|
||||||
|
typeof Node === "object" ? o instanceof Node :
|
||||||
|
o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName === "string"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if it is a DOM element.
|
||||||
|
*
|
||||||
|
* @param o
|
||||||
|
* @returns boolean
|
||||||
|
*
|
||||||
|
* @source https://stackoverflow.com/a/384380
|
||||||
|
*/
|
||||||
|
function isElement(o) {
|
||||||
|
return (
|
||||||
|
typeof HTMLElement === "object" ? o instanceof HTMLElement : // DOM2
|
||||||
|
o && typeof o === "object" && o.nodeType === 1 && typeof o.nodeName === "string"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -16,82 +16,54 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Inputmask
|
function initMaskInput(input) {
|
||||||
|
let $input = $(input);
|
||||||
|
if ($input.hasClass('bound')){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$input.addClass('bound');
|
||||||
|
|
||||||
|
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')){
|
||||||
|
$input.inputmask({
|
||||||
|
mask: "AA-999999{1,15}",
|
||||||
|
casing: "upper",
|
||||||
|
});
|
||||||
|
} else if ($input.hasClass('provincia-mask')){
|
||||||
|
$input.inputmask({
|
||||||
|
mask: "AA",
|
||||||
|
casing: "upper",
|
||||||
|
});
|
||||||
|
} else if ($input.hasClass('alphanumeric-mask')){
|
||||||
|
$input.inputmask('Regex', {
|
||||||
|
regex: "[A-Za-z0-9#_|\/\\-.]*",
|
||||||
|
});
|
||||||
|
} else if ($input.hasClass('math-mask')){
|
||||||
|
$input.inputmask('Regex', {
|
||||||
|
regex: "[0-9,.+\-]*",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inputmask
|
||||||
|
* @param element
|
||||||
|
*/
|
||||||
function start_inputmask(element) {
|
function start_inputmask(element) {
|
||||||
if (element == undefined) {
|
if (element === undefined) {
|
||||||
element = '';
|
element = '';
|
||||||
} else {
|
} else {
|
||||||
element = element + ' ';
|
element = element + ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
var date = dateFormatMoment(globals.date_format).toLowerCase();
|
let masks = ['math-mask','alphanumeric-mask', 'provincia-mask','rea-mask', 'email-mask'];
|
||||||
|
|
||||||
$(element + ".date-mask").not('.bound').inputmask(date, {
|
let selector = element + '.' + masks.join(', ' + element + '.')
|
||||||
placeholder: date
|
$(selector).each(function () {
|
||||||
}).addClass('bound');
|
initMaskInput(this);
|
||||||
|
});
|
||||||
$(element + '.email-mask').not('.bound').inputmask('Regex', {
|
|
||||||
regex: "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$",
|
|
||||||
}).addClass('bound');
|
|
||||||
|
|
||||||
$(element + '.rea-mask').not('.bound').inputmask( {
|
|
||||||
mask: "AA-999999{1,15}",
|
|
||||||
casing: "upper",
|
|
||||||
}).addClass('bound');
|
|
||||||
|
|
||||||
$(element + '.provincia-mask').not('.bound').inputmask( {
|
|
||||||
mask: "AA",
|
|
||||||
casing: "upper",
|
|
||||||
}).addClass('bound');
|
|
||||||
|
|
||||||
$(element + '.alphanumeric-mask').not('.bound').inputmask('Regex', {
|
|
||||||
regex: "[A-Za-z0-9#_|\/\\-.]*",
|
|
||||||
}).addClass('bound');
|
|
||||||
|
|
||||||
$(element + '.math-mask').not('.bound').inputmask('Regex', {
|
|
||||||
regex: "[0-9,.+\-]*",
|
|
||||||
}).addClass('bound');
|
|
||||||
|
|
||||||
if (globals.is_mobile) {
|
|
||||||
$(element + '.inputmask-decimal, ' + element + '.date-mask, ' + element + '.timestamp-mask').each(function () {
|
|
||||||
$(this).attr('type', 'tel');
|
|
||||||
}).addClass('bound');
|
|
||||||
} else {
|
|
||||||
$(element + '.inputmask-decimal').not('.bound').each(function () {
|
|
||||||
var $this = $(this);
|
|
||||||
|
|
||||||
var min = $this.attr('min-value');
|
|
||||||
if (min == 'undefined') {
|
|
||||||
min = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var max = $this.attr('max-value');
|
|
||||||
if (max == 'undefined') {
|
|
||||||
max = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this.inputmask("decimal", {
|
|
||||||
min: min ? min : undefined,
|
|
||||||
allowMinus: !min || min < 0 ? true : false,
|
|
||||||
max: max ? max : undefined,
|
|
||||||
allowPlus: !max || max < 0 ? true : false,
|
|
||||||
digits: $this.attr('decimals') ? $this.attr('decimals') : globals.cifre_decimali,
|
|
||||||
digitsOptional: true, // Necessario per un problema di inputmask con i numeri negativi durante l'init
|
|
||||||
enforceDigitsOnBlur: true,
|
|
||||||
rightAlign: true,
|
|
||||||
autoGroup: true,
|
|
||||||
radixPoint: globals.decimals,
|
|
||||||
groupSeparator: globals.thousands,
|
|
||||||
onUnMask: function (maskedValue, unmaskedValue) {
|
|
||||||
return maskedValue.toEnglish();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
$this.on('keyup', function () {
|
|
||||||
if (min && $(this).val().toEnglish() < min) {
|
|
||||||
$(this).val(min);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).addClass('bound');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,37 +23,41 @@ function initNumbers() {
|
||||||
let inputs = $('.decimal-number').not('.bound');
|
let inputs = $('.decimal-number').not('.bound');
|
||||||
|
|
||||||
for (const input of inputs) {
|
for (const input of inputs) {
|
||||||
let $input = $(input);
|
initNumberInput(input);
|
||||||
|
|
||||||
if (AutoNumeric.isManagedByAutoNumeric(input)) {
|
$(input).addClass('bound');
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let min = $input.attr('min-value') && $input.attr('min-value') !== "undefined" ? $input.attr('min-value') : null;
|
|
||||||
let max = $input.attr('max-value') && $input.attr('max-value') !== "undefined" ? $input.attr('max-value') : null;
|
|
||||||
|
|
||||||
let decimals = $input.attr('decimals') ? $input.attr('decimals') : globals.cifre_decimali;
|
|
||||||
|
|
||||||
let autonumeric = new AutoNumeric(input, {
|
|
||||||
caretPositionOnFocus: "decimalLeft",
|
|
||||||
allowDecimalPadding: true,
|
|
||||||
currencySymbolPlacement: "s",
|
|
||||||
negativePositiveSignPlacement: "p",
|
|
||||||
decimalCharacter: globals.decimals,
|
|
||||||
decimalCharacterAlternative: ".",
|
|
||||||
digitGroupSeparator: globals.thousands,
|
|
||||||
emptyInputBehavior: min ? min : "zero",
|
|
||||||
overrideMinMaxLimits: "ignore",
|
|
||||||
modifyValueOnWheel: false,
|
|
||||||
outputFormat: "string",
|
|
||||||
unformatOnSubmit: true,
|
|
||||||
watchExternalChanges: true,
|
|
||||||
minimumValue: min ? min : "-10000000000000",
|
|
||||||
maximumValue: max ? max : "10000000000000",
|
|
||||||
decimalPlaces: decimals,
|
|
||||||
});
|
|
||||||
|
|
||||||
$input.data("autonumeric", autonumeric)
|
|
||||||
.addClass('bound');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initNumberInput(input){
|
||||||
|
let $input = $(input);
|
||||||
|
if (AutoNumeric.isManagedByAutoNumeric(input)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let min = $input.attr('min-value') && $input.attr('min-value') !== "undefined" ? $input.attr('min-value') : null;
|
||||||
|
let max = $input.attr('max-value') && $input.attr('max-value') !== "undefined" ? $input.attr('max-value') : null;
|
||||||
|
|
||||||
|
let decimals = $input.attr('decimals') ? $input.attr('decimals') : globals.cifre_decimali;
|
||||||
|
|
||||||
|
let autonumeric = new AutoNumeric(input, {
|
||||||
|
caretPositionOnFocus: "decimalLeft",
|
||||||
|
allowDecimalPadding: true,
|
||||||
|
currencySymbolPlacement: "s",
|
||||||
|
negativePositiveSignPlacement: "p",
|
||||||
|
decimalCharacter: globals.decimals,
|
||||||
|
decimalCharacterAlternative: ".",
|
||||||
|
digitGroupSeparator: globals.thousands,
|
||||||
|
emptyInputBehavior: min ? min : "zero",
|
||||||
|
overrideMinMaxLimits: "ignore",
|
||||||
|
modifyValueOnWheel: false,
|
||||||
|
outputFormat: "string",
|
||||||
|
unformatOnSubmit: true,
|
||||||
|
watchExternalChanges: true,
|
||||||
|
minimumValue: min ? min : "-10000000000000",
|
||||||
|
maximumValue: max ? max : "10000000000000",
|
||||||
|
decimalPlaces: decimals,
|
||||||
|
});
|
||||||
|
|
||||||
|
$input.data("autonumeric", autonumeric);
|
||||||
|
}
|
||||||
|
|
|
@ -16,87 +16,12 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Select
|
/**
|
||||||
|
* Select.
|
||||||
|
*/
|
||||||
function start_superselect() {
|
function start_superselect() {
|
||||||
// Statico
|
$('.superselect, .superselectajax').each(function () {
|
||||||
$('.superselect').each(function () {
|
initSelectInput(this);
|
||||||
let $this = $(this);
|
|
||||||
|
|
||||||
$(this).select2({
|
|
||||||
theme: "bootstrap",
|
|
||||||
language: "it",
|
|
||||||
width: '100%',
|
|
||||||
maximumSelectionLength: $this.data('maximum') ? $this.data('maximum') : -1,
|
|
||||||
minimumResultsForSearch: $this.hasClass('no-search') ? -1 : 0,
|
|
||||||
allowClear: !$this.hasClass('no-search'),
|
|
||||||
escapeMarkup: function (text) {
|
|
||||||
return text;
|
|
||||||
},
|
|
||||||
templateResult: selectBackground,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Dinamico (AJAX, per tabelle con molti record)
|
|
||||||
$('.superselectajax').each(function () {
|
|
||||||
let $this = $(this);
|
|
||||||
|
|
||||||
$(this).select2({
|
|
||||||
theme: "bootstrap",
|
|
||||||
language: "it",
|
|
||||||
maximumSelectionLength: $this.data('maximum') ? $this.data('maximum') : -1,
|
|
||||||
minimumInputLength: $this.data('heavy') ? 3 : 0,
|
|
||||||
allowClear: true,
|
|
||||||
escapeMarkup: function (text) {
|
|
||||||
return text;
|
|
||||||
},
|
|
||||||
templateResult: selectBackground,
|
|
||||||
ajax: {
|
|
||||||
url: globals.rootdir + "/ajax_select.php?op=" + $this.data('source'),
|
|
||||||
dataType: 'json',
|
|
||||||
delay: 250,
|
|
||||||
data: function (params) {
|
|
||||||
return {
|
|
||||||
search: params.term,
|
|
||||||
page: params.page || 0,
|
|
||||||
length: params.length || 100,
|
|
||||||
options: this.data('select-options'), // Dati aggiuntivi
|
|
||||||
};
|
|
||||||
},
|
|
||||||
processResults: function (data, params) {
|
|
||||||
params.page = params.page || 0;
|
|
||||||
params.length = params.length || 100;
|
|
||||||
|
|
||||||
let results = data.results;
|
|
||||||
|
|
||||||
// Interpretazione forzata per campi optgroup
|
|
||||||
if (results && results[0] && [0]['optgroup']) {
|
|
||||||
let groups = results.reduce(function (r, a) {
|
|
||||||
r[a.optgroup] = r[a.optgroup] || [];
|
|
||||||
r[a.optgroup].push(a);
|
|
||||||
return r;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
let results_groups = [];
|
|
||||||
for (const key in groups) {
|
|
||||||
results_groups.push({
|
|
||||||
text: key,
|
|
||||||
children: groups[key],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
results = results_groups;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
results: results,
|
|
||||||
pagination: {
|
|
||||||
more: (params.page + 1) * params.length < data.recordsFiltered,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
cache: false
|
|
||||||
},
|
|
||||||
width: '100%'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,3 +167,99 @@ function updateSelectOption(name, value) {
|
||||||
$(this).setSelectOption(name, value);
|
$(this).setSelectOption(name, value);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initSelectInput(input){
|
||||||
|
if ($(input).hasClass('superselect')){
|
||||||
|
initStaticSelectInput(input);
|
||||||
|
} else {
|
||||||
|
initDynamicSelectInput(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Statico.
|
||||||
|
* @param input
|
||||||
|
*/
|
||||||
|
function initStaticSelectInput(input){
|
||||||
|
let $input = $(input);
|
||||||
|
|
||||||
|
$input.select2({
|
||||||
|
theme: "bootstrap",
|
||||||
|
language: "it",
|
||||||
|
width: '100%',
|
||||||
|
maximumSelectionLength: $input.data('maximum') ? $input.data('maximum') : -1,
|
||||||
|
minimumResultsForSearch: $input.hasClass('no-search') ? -1 : 0,
|
||||||
|
allowClear: !$input.hasClass('no-search'),
|
||||||
|
escapeMarkup: function (text) {
|
||||||
|
return text;
|
||||||
|
},
|
||||||
|
templateResult: selectBackground,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dinamico.
|
||||||
|
* @param input
|
||||||
|
*/
|
||||||
|
function initDynamicSelectInput(input){
|
||||||
|
let $input = $(input);
|
||||||
|
|
||||||
|
$input.select2({
|
||||||
|
theme: "bootstrap",
|
||||||
|
language: "it",
|
||||||
|
maximumSelectionLength: $input.data('maximum') ? $input.data('maximum') : -1,
|
||||||
|
minimumInputLength: $input.data('heavy') ? 3 : 0,
|
||||||
|
allowClear: true,
|
||||||
|
escapeMarkup: function (text) {
|
||||||
|
return text;
|
||||||
|
},
|
||||||
|
templateResult: selectBackground,
|
||||||
|
ajax: {
|
||||||
|
url: globals.rootdir + "/ajax_select.php?op=" + $input.data('source'),
|
||||||
|
dataType: 'json',
|
||||||
|
delay: 250,
|
||||||
|
data: function (params) {
|
||||||
|
return {
|
||||||
|
search: params.term,
|
||||||
|
page: params.page || 0,
|
||||||
|
length: params.length || 100,
|
||||||
|
options: this.data('select-options'), // Dati aggiuntivi
|
||||||
|
};
|
||||||
|
},
|
||||||
|
processResults: function (data, params) {
|
||||||
|
params.page = params.page || 0;
|
||||||
|
params.length = params.length || 100;
|
||||||
|
|
||||||
|
let results = data.results;
|
||||||
|
|
||||||
|
// Interpretazione forzata per campi optgroup
|
||||||
|
if (results && results[0] && [0]['optgroup']) {
|
||||||
|
let groups = results.reduce(function (r, a) {
|
||||||
|
r[a.optgroup] = r[a.optgroup] || [];
|
||||||
|
r[a.optgroup].push(a);
|
||||||
|
return r;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
let results_groups = [];
|
||||||
|
for (const key in groups) {
|
||||||
|
results_groups.push({
|
||||||
|
text: key,
|
||||||
|
children: groups[key],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
results = results_groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
results: results,
|
||||||
|
pagination: {
|
||||||
|
more: (params.page + 1) * params.length < data.recordsFiltered,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
cache: false
|
||||||
|
},
|
||||||
|
width: '100%'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ echo '
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<script>
|
<script>
|
||||||
var formatted_zero = "'.Translator::numberToLocale(0).'";
|
var formatted_zero = "'.numberFormat(0).'";
|
||||||
var n = '.$counter.';
|
var n = '.$counter.';
|
||||||
|
|
||||||
function addRiga(btn) {
|
function addRiga(btn) {
|
||||||
|
@ -196,25 +196,25 @@ function addRiga(btn) {
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function controllaConti() {
|
function controllaConti() {
|
||||||
var continuare = true;
|
let continuare = true;
|
||||||
|
|
||||||
// Controlli sullo stato dei raggruppamenti
|
// Controlli sullo stato dei raggruppamenti
|
||||||
$(".raggruppamento_primanota").each(function() {
|
$(".raggruppamento_primanota").each(function() {
|
||||||
var bilancio = calcolaBilancio(this);
|
let bilancio = calcolaBilancio(this);
|
||||||
|
|
||||||
continuare &= bilancio == 0;
|
continuare &= bilancio === 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Blocco degli input con valore non impostato
|
// Blocco degli input con valore non impostato
|
||||||
$("input[id*=dare], input[id*=avere]").each(function() {
|
$("input[id*=dare], input[id*=avere]").each(function() {
|
||||||
var conto_relativo = $(this).parent().parent().find("select").val();
|
let conto_relativo = $(this).parent().parent().find("select").val();
|
||||||
|
|
||||||
if (!conto_relativo) {
|
if (!conto_relativo) {
|
||||||
$(this).prop("disabled", true);
|
$(this).prop("disabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($(this).val().toEnglish()){
|
if ($(this).val().toEnglish()){
|
||||||
continuare &= conto_relativo ? true : false;
|
continuare &= !!conto_relativo;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -237,38 +237,37 @@ function controllaConti() {
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function calcolaBilancio(gruppo) {
|
function calcolaBilancio(gruppo) {
|
||||||
var raggruppamento = $(gruppo);
|
let raggruppamento = $(gruppo);
|
||||||
|
|
||||||
var totale_dare = 0.00;
|
let totale_dare = 0.00;
|
||||||
var totale_avere = 0.00;
|
let totale_avere = 0.00;
|
||||||
|
|
||||||
// Calcolo il totale dare
|
// Calcolo il totale dare
|
||||||
raggruppamento.find("input[id*=dare]").each(function() {
|
raggruppamento.find("input[id*=dare]").each(function() {
|
||||||
valore = $(this).val() ? $(this).val().toEnglish() : 0;
|
totale_dare += input(this).get();
|
||||||
|
|
||||||
totale_dare += valore;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calcolo il totale avere
|
// Calcolo il totale avere
|
||||||
raggruppamento.find("input[id*=avere]").each(function() {
|
raggruppamento.find("input[id*=avere]").each(function() {
|
||||||
valore = $(this).val() ? $(this).val().toEnglish() : 0;
|
totale_avere += input(this).get();
|
||||||
|
|
||||||
totale_avere += valore;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
totale_dare = parseFloat(totale_dare);
|
||||||
|
totale_avere = parseFloat(totale_avere);
|
||||||
|
|
||||||
// Visualizzazione dei totali
|
// Visualizzazione dei totali
|
||||||
raggruppamento.find(".totale_dare").text(totale_dare.toLocale());
|
raggruppamento.find(".totale_dare").text(totale_dare.toLocale());
|
||||||
raggruppamento.find(".totale_avere").text(totale_avere.toLocale());
|
raggruppamento.find(".totale_avere").text(totale_avere.toLocale());
|
||||||
|
|
||||||
// Calcolo il bilancio
|
// Calcolo il bilancio
|
||||||
var bilancio = totale_dare.toFixed(2) - totale_avere.toFixed(2);
|
let bilancio = totale_dare.toFixed(2) - totale_avere.toFixed(2);
|
||||||
|
|
||||||
// Visualizzazione dello sbilancio eventuale
|
// Visualizzazione dello sbilancio eventuale
|
||||||
var sbilancio = raggruppamento.find(".sbilancio");
|
let sbilancio = raggruppamento.find(".sbilancio");
|
||||||
var valore_sbilancio = sbilancio.find(".money");
|
let valore_sbilancio = sbilancio.find(".money");
|
||||||
valore_sbilancio.text(bilancio.toLocale());
|
valore_sbilancio.text(bilancio.toLocale());
|
||||||
|
|
||||||
if (bilancio == 0) {
|
if (bilancio === 0) {
|
||||||
sbilancio.addClass("hide");
|
sbilancio.addClass("hide");
|
||||||
} else {
|
} else {
|
||||||
sbilancio.removeClass("hide");
|
sbilancio.removeClass("hide");
|
||||||
|
@ -282,7 +281,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// Fix per l\'inizializzazione degli input
|
// Fix per l\'inizializzazione degli input
|
||||||
$("input[id*=dare], input[id*=avere]").each(function() {
|
$("input[id*=dare], input[id*=avere]").each(function() {
|
||||||
if ($(this).val() == formatted_zero) {
|
if (input(this).get() === 0) {
|
||||||
$(this).prop("disabled", true);
|
$(this).prop("disabled", true);
|
||||||
} else {
|
} else {
|
||||||
$(this).prop("disabled", false);
|
$(this).prop("disabled", false);
|
||||||
|
@ -298,30 +297,30 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("change", "select", function() {
|
$(document).on("change", "select", function() {
|
||||||
var row = $(this).parent().parent();
|
let row = $(this).parent().parent();
|
||||||
|
|
||||||
if ($(this).parent().parent().find("input[disabled]").length != 1) {
|
if (row.find("input[disabled]").length > 1) {
|
||||||
row.find("input").prop("disabled", $(this).val() ? false : true);
|
row.find("input").prop("disabled", !$(this).val());
|
||||||
}
|
}
|
||||||
|
|
||||||
controllaConti();
|
controllaConti();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("keyup change", "input[id*=dare]", function() {
|
$(document).on("keyup change", "input[id*=dare]", function() {
|
||||||
var row = $(this).parent().parent();
|
let row = $(this).parent().parent();
|
||||||
|
|
||||||
if (!$(this).prop("disabled")) {
|
if (!$(this).prop("disabled")) {
|
||||||
row.find("input[id*=avere]").prop("disabled", $(this).val() ? true : false);
|
row.find("input[id*=avere]").prop("disabled", !!$(this).val());
|
||||||
|
|
||||||
controllaConti();
|
controllaConti();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("keyup change", "input[id*=avere]", function() {
|
$(document).on("keyup change", "input[id*=avere]", function() {
|
||||||
var row = $(this).parent().parent();
|
let row = $(this).parent().parent();
|
||||||
|
|
||||||
if (!$(this).prop("disabled")) {
|
if (!$(this).prop("disabled")) {
|
||||||
row.find("input[id*=dare]").prop("disabled", $(this).val() ? true : false);
|
row.find("input[id*=dare]").prop("disabled", !!$(this).val());
|
||||||
|
|
||||||
controllaConti();
|
controllaConti();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ include_once __DIR__.'/../../core.php';
|
||||||
{[ "type": "select", "label": "<?php echo tr('Tipo'); ?>", "name": "tipo", "required": 1, "ajax-source": "tipi_scadenze", "icon-after": "add|<?php echo Modules::get('Tipi scadenze')['id']; ?>" ]}
|
{[ "type": "select", "label": "<?php echo tr('Tipo'); ?>", "name": "tipo", "required": 1, "ajax-source": "tipi_scadenze", "icon-after": "add|<?php echo Modules::get('Tipi scadenze')['id']; ?>" ]}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
{[ "type": "date", "label": "<?php echo tr('Data scadenza'); ?>", "name": "data", "required": 1, "value": "-now-" ]}
|
{[ "type": "date", "label": "<?php echo tr('Data scadenza'); ?>", "name": "data", "required": 1, "value": "-now-" ]}
|
||||||
</div>
|
</div>
|
||||||
|
@ -52,5 +51,4 @@ include_once __DIR__.'/../../core.php';
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='clearfix'></div>
|
<div class='clearfix'></div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -137,11 +137,11 @@ foreach ($scadenze as $i => $scadenza) {
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
{[ "type": "number", "name": "da_pagare['.$i.']", "decimals": 2, "value": "'.Translator::numberToLocale($scadenza['da_pagare'], 2).'", "onchange": "controlloTotale()" ]}
|
{[ "type": "number", "name": "da_pagare['.$i.']", "decimals": 2, "value": "'.numberFormat($scadenza['da_pagare'], 2).'", "onchange": "controlloTotale()" ]}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
{[ "type": "number", "name": "pagato['.$i.']", "decimals": 2, "value": "'.Translator::numberToLocale($scadenza['pagato']).'" ]}
|
{[ "type": "number", "name": "pagato['.$i.']", "decimals": 2, "value": "'.numberFormat($scadenza['pagato']).'" ]}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td align="center">
|
<td align="center">
|
||||||
|
@ -155,7 +155,7 @@ echo '
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-right"><b>'.tr('Totale').'</b></td>
|
<td class="text-right"><b>'.tr('Totale').'</b></td>
|
||||||
<td class="text-right" id="totale_utente">'.Translator::numberToLocale($totale_da_pagare).'</td>
|
<td class="text-right" id="totale_utente">'.numberFormat($totale_da_pagare).'</td>
|
||||||
<td class="text-right"></td>
|
<td class="text-right"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>';
|
</tfoot>';
|
||||||
|
@ -179,7 +179,7 @@ echo '
|
||||||
]); ?>.
|
]); ?>.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" id="totale_da_pagare" value="<?php echo Translator::numberToLocale($totale_da_pagare, 2); ?>">
|
<input type="hidden" id="totale_da_pagare" value="<?php echo numberFormat($totale_da_pagare, 2); ?>">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -253,13 +253,11 @@ if (!empty($documento)) {
|
||||||
});
|
});
|
||||||
|
|
||||||
function controlloTotale() {
|
function controlloTotale() {
|
||||||
totale_da_pagare = $("#totale_da_pagare").val().toEnglish();
|
totale_da_pagare = input("totale_da_pagare").get();
|
||||||
totale_utente = 0;
|
totale_utente = 0;
|
||||||
|
|
||||||
$("input[name*=da_pagare]").each(function() {
|
$("input[name*=da_pagare]").each(function() {
|
||||||
|
totale_utente += input(this).get();
|
||||||
totale_utente += $(this).val().toEnglish();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isNaN(totale_utente)) {
|
if (isNaN(totale_utente)) {
|
||||||
|
|
|
@ -112,7 +112,6 @@ class DateHandler implements HandlerInterface
|
||||||
{
|
{
|
||||||
$values['class'][] = 'text-center';
|
$values['class'][] = 'text-center';
|
||||||
$values['class'][] = 'timestamp-picker';
|
$values['class'][] = 'timestamp-picker';
|
||||||
$values['class'][] = 'timestamp-mask';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,7 +127,6 @@ class DateHandler implements HandlerInterface
|
||||||
{
|
{
|
||||||
$values['class'][] = 'text-center';
|
$values['class'][] = 'text-center';
|
||||||
$values['class'][] = 'datepicker';
|
$values['class'][] = 'datepicker';
|
||||||
$values['class'][] = 'date-mask';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue