Correzione JS minori

This commit is contained in:
Dasc3er 2020-09-23 13:59:50 +02:00
parent 099cda6fcb
commit 9285750655
4 changed files with 39 additions and 22 deletions

View File

@ -1,13 +1,19 @@
function initNumbers() { function initNumbers() {
$('.decimal-number').not('.bound').each(function () { let inputs = $('.decimal-number').not('.bound');
let $this = $(this);
let min = $this.attr('min-value') && $this.attr('min-value') !== "undefined" ? $this.attr('min-value') : null; for (const input of inputs) {
let max = $this.attr('max-value') && $this.attr('max-value') !== "undefined" ? $this.attr('max-value') : null; let $input = $(input);
let decimals = $this.attr('decimals') ? $this.attr('decimals') : globals.cifre_decimali; if (AutoNumeric.isManagedByAutoNumeric(input)) {
continue;
}
let autonumeric = new AutoNumeric(this, { 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", caretPositionOnFocus: "decimalLeft",
allowDecimalPadding: true, allowDecimalPadding: true,
currencySymbolPlacement: "s", currencySymbolPlacement: "s",
@ -26,6 +32,7 @@ function initNumbers() {
decimalPlaces: decimals, decimalPlaces: decimals,
}); });
$this.data("autonumeric", autonumeric); $input.data("autonumeric", autonumeric)
}).addClass('bound'); .addClass('bound');
}
} }

View File

@ -118,6 +118,7 @@ function selectBackground(data, container) {
return data.text; return data.text;
} }
/** /**
* Reimposta i contenuti di un <select> creato con select2. * Reimposta i contenuti di un <select> creato con select2.
*/ */
@ -206,11 +207,16 @@ jQuery.fn.selectData = function () {
let selectData = this.select2('data'); let selectData = this.select2('data');
if (this.prop('multiple')) { if (this.prop('multiple')) {
return selectData; let results = [];
for (const option of selectData) {
results.push(option.element.dataset);
}
return results;
} else if (selectData.length === 0) { } else if (selectData.length === 0) {
return undefined; return undefined;
} else { } else {
return selectData[0]; return selectData[0].element.dataset;
} }
}; };

View File

@ -184,7 +184,9 @@ include_once __DIR__.'/../../core.php';
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA'); $prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
if (empty($prezzi_ivati)) { if (empty($prezzi_ivati)) {
echo ' echo '
<button type="button" class="btn btn-info btn-xs pull-right tip pull-right" title="'.tr('Scorpora iva dal prezzo di vendita.').'" id="scorpora_iva"><i class="fa fa-calculator" aria-hidden="true"></i></button>'; <button type="button" class="btn btn-info btn-xs pull-right tip pull-right" title="'.tr('Scorpora iva dal prezzo di vendita.').'" id="scorporaIva">
<i class="fa fa-calculator"></i>
</button>';
} }
echo ' echo '
@ -331,15 +333,17 @@ $("#categoria").change(function() {
$("#subcategoria").val(null).trigger("change"); $("#subcategoria").val(null).trigger("change");
}); });
function scorpora_iva() { function scorporaIva() {
if ($("#idiva_vendita").val()!=''){ let iva_vendita = $("#idiva_vendita");
var percentuale = parseFloat($("#idiva_vendita").selectData().percentuale);
if (iva_vendita.val()) {
let percentuale = parseFloat(iva_vendita.selectData().percentuale);
if(!percentuale) return; if(!percentuale) return;
var input = $("#prezzo_vendita"); let input = $("#prezzo_vendita");
var prezzo = input.val().toEnglish(); let prezzo = input.val().toEnglish();
var scorporato = prezzo * 100 / (100 + percentuale); let scorporato = prezzo * 100 / (100 + percentuale);
input.val(scorporato); input.val(scorporato);
}else{ }else{
@ -347,8 +351,8 @@ function scorpora_iva() {
} }
} }
$("#scorpora_iva").click( function() { $("#scorporaIva").click( function() {
scorpora_iva(); scorporaIva();
}); });
</script> </script>

View File

@ -190,7 +190,7 @@ class FileManager implements ManagerInterface
{[ "type": "text", "placeholder": "'.tr('Nome file').'", "name": "nome_allegato", "class": "unblockable" ]} {[ "type": "text", "placeholder": "'.tr('Nome file').'", "name": "nome_allegato", "class": "unblockable" ]}
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{[ "type": "text", "placeholder": "'.tr('Categoria').'", "name": "categoria", "class": "unblockable" ]} {[ "type": "text", "placeholder": "'.tr('Categoria').'", "name": "categoria_allegato", "id": "categoria_allegato", "class": "unblockable" ]}
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<div class="dropzone dz-clickable" id="dragdrop"> <div class="dropzone dz-clickable" id="dragdrop">
@ -244,7 +244,7 @@ $(document).ready(function() {
url: "'.ROOTDIR.'/actions.php?op=link_file&id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id_plugin='.$options['id_plugin'].'", url: "'.ROOTDIR.'/actions.php?op=link_file&id_module='.$options['id_module'].'&id_record='.$options['id_record'].'&id_plugin='.$options['id_plugin'].'",
init: function (file, xhr, formData) { init: function (file, xhr, formData) {
this.on("sending", function(file, xhr, formData) { this.on("sending", function(file, xhr, formData) {
formData.append("categoria", $("#categoria").val()); formData.append("categoria", $("#categoria_allegato").val());
formData.append("nome_allegato", $("#nome_allegato").val()); formData.append("nome_allegato", $("#nome_allegato").val());
}); });
@ -323,7 +323,7 @@ $(document).ready(function() {
}); });
// Autocompletamento categoria // Autocompletamento categoria
$("#'.$attachment_id.' #categoria").autocomplete({ $("#'.$attachment_id.' #categoria_allegato").autocomplete({
source: '.json_encode($source).', source: '.json_encode($source).',
minLength: 0 minLength: 0
}).focus(function() { }).focus(function() {