From dea2d1dbdc7672186fd2756b1c04db8ee8846d65 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 26 Jul 2019 17:40:52 +0200 Subject: [PATCH] Miglioramento organizzazione JS --- actions.php | 2 +- add.php | 21 +- assets/src/js/alert.js | 30 + assets/src/js/custom.js | 122 +- assets/src/js/datatables-buttons.js | 89 + assets/src/js/functions/datatables.js | 429 ++++ assets/src/js/functions/dates.js | 101 + assets/src/js/functions/functions.js | 488 +++++ assets/src/js/functions/hooks.js | 56 + {lib => assets/src/js/functions}/init.js | 6 +- assets/src/js/functions/input.js | 66 + assets/src/js/functions/prototypes.js | 19 + assets/src/js/functions/select.js | 183 ++ assets/src/js/navigation.js | 51 + assets/src/js/sidebar.js | 47 + assets/src/js/slider.js | 47 + assets/src/js/widgets.js | 33 + editor.php | 19 +- gulpfile.js | 7 + include/common/form.php | 2 +- include/common/importa.php | 2 +- include/init/init.php | 2 +- include/top.php | 3 +- lib/functions.js | 1804 ----------------- mail.php | 8 +- .../widgets/stampa_calendario.dashboard.php | 2 +- modules/ddt/add_ordine.php | 2 +- modules/fatture/add_contratto.php | 2 +- modules/fatture/add_ddt.php | 2 +- modules/fatture/add_intervento.php | 2 +- modules/fatture/add_ordine.php | 2 +- modules/fatture/add_preventivo.php | 2 +- modules/fatture/add_serial.php | 2 +- modules/fatture/fe/document-fe.php | 16 +- modules/fatture/fe/row-fe.php | 8 +- modules/interventi/add.php | 4 +- modules/interventi/add_articolo.php | 2 +- modules/interventi/add_righe.php | 2 +- modules/interventi/ajax_costi.php | 2 +- modules/interventi/ajax_tecnici.php | 2 +- modules/interventi/manage_sessione.php | 2 +- modules/pagamenti/edit.php | 6 +- modules/scadenzario/edit.php | 12 +- modules/statistiche/js/functions.js | 31 +- modules/stato_servizi/actions.php | 20 +- modules/utenti/self.php | 2 +- modules/utenti/user.php | 2 +- modules/viste/fields.php | 8 +- modules/viste/filters.php | 6 +- .../add_articolo.php | 2 +- .../pianificazione_interventi/add_righe.php | 2 +- .../pianficazione.php | 2 +- src/App.php | 9 +- src/HTMLBuilder/Manager/ChecklistManager.php | 4 +- src/HTMLBuilder/Manager/FileManager.php | 2 +- 55 files changed, 1805 insertions(+), 1994 deletions(-) create mode 100644 assets/src/js/alert.js create mode 100644 assets/src/js/datatables-buttons.js create mode 100644 assets/src/js/functions/datatables.js create mode 100644 assets/src/js/functions/dates.js create mode 100644 assets/src/js/functions/functions.js create mode 100644 assets/src/js/functions/hooks.js rename {lib => assets/src/js/functions}/init.js (96%) create mode 100644 assets/src/js/functions/input.js create mode 100644 assets/src/js/functions/prototypes.js create mode 100644 assets/src/js/functions/select.js create mode 100644 assets/src/js/navigation.js create mode 100644 assets/src/js/sidebar.js create mode 100644 assets/src/js/slider.js create mode 100644 assets/src/js/widgets.js delete mode 100644 lib/functions.js diff --git a/actions.php b/actions.php index 734066ef3..2e9ae4088 100644 --- a/actions.php +++ b/actions.php @@ -2,8 +2,8 @@ include_once __DIR__.'/core.php'; -use Models\Note; use Models\Checklist; +use Models\Note; use Models\User; if (empty($structure) || empty($structure['enabled'])) { diff --git a/add.php b/add.php index fd89dcdb9..1ca81cd72 100644 --- a/add.php +++ b/add.php @@ -36,17 +36,10 @@ echo ' '; @@ -99,4 +90,4 @@ $(document).ready(function(){ } echo ' - '; +'; diff --git a/assets/src/js/alert.js b/assets/src/js/alert.js new file mode 100644 index 000000000..7b96623d3 --- /dev/null +++ b/assets/src/js/alert.js @@ -0,0 +1,30 @@ +$(document).ready(function () { + // Messaggio di avviso salvataggio a comparsa sulla destra solo nella versione a desktop intero + if ($(window).width() > 1023) { + var i = 0; + + $('.alert-success.push').each(function () { + i++; + tops = 60 * i + 95; + + $(this).css({ + 'position': 'fixed', + 'z-index': 3, + 'right': '10px', + 'top': -100, + }).delay(1000).animate({ + 'top': tops, + }).delay(3000).animate({ + 'top': -100, + }); + }); + } + + // Nascondo la notifica se passo sopra col mouse + $('.alert-success.push').on('mouseover', function () { + $(this).stop().animate({ + 'top': -100, + 'opacity': 0 + }); + }); +}); diff --git a/assets/src/js/custom.js b/assets/src/js/custom.js index 79bd20a51..b358188c9 100644 --- a/assets/src/js/custom.js +++ b/assets/src/js/custom.js @@ -1,61 +1,83 @@ + +// Aggiunta dell'ingranaggio all'unload della pagina +$(window).on("beforeunload", function () { + $("#main_loading").show(); +}); + +// Rimozione dell'ingranaggio al caricamento completo della pagina +$(window).on("load", function () { + $("#main_loading").fadeOut(); +}); + +// Fix multi-modal +$(document).on('hidden.bs.modal', '.modal', function () { + $('.modal:visible').length && $(document.body).addClass('modal-open'); +}); + $(document).ready(function () { - // Fix per il menu principale - $('.sidebar-menu').tree({ - followLink: true, - }); + // Imposta la lingua per la gestione automatica delle date dei diversi plugin + moment.locale(globals.locale); + globals.timestampFormat = moment.localeData().longDateFormat('L') + ' ' + moment.localeData().longDateFormat('LT'); - // Pulsante per il ritorno a inizio pagina - var slideToTop = $("
"); - slideToTop.html(''); - slideToTop.css({ - position: 'fixed', - bottom: '20px', - right: '25px', - width: '40px', - height: '40px', - color: '#eee', - 'font-size': '', - 'line-height': '40px', - 'text-align': 'center', - 'background-color': 'rgba(255, 78, 0)', - 'box-shadow': '0 0 10px rgba(0, 0, 0, 0.05)', - cursor: 'pointer', - 'z-index': '99999', - opacity: '.7', - 'display': 'none' - }); + // Standard per i popup + toastr.options = { + "closeButton": true, + "debug": false, + "newestOnTop": false, + "progressBar": true, + "positionClass": "toast-top-right", + "preventDuplicates": true, + "onclick": null, + "showDuration": "300", + "hideDuration": "1000", + "timeOut": "12000", + "extendedTimeOut": "8000", + "showEasing": "swing", + "hideEasing": "linear", + "showMethod": "fadeIn", + "hideMethod": "fadeOut" + }; - slideToTop.on('mouseenter', function () { - $(this).css('opacity', '1'); - }); - - slideToTop.on('mouseout', function () { - $(this).css('opacity', '.7'); - }); - - $('.wrapper').append(slideToTop); - $(window).scroll(function () { - if ($(window).scrollTop() >= 150) { - if (!$(slideToTop).is(':visible')) { - $(slideToTop).fadeIn(500); - } - } else { - $(slideToTop).fadeOut(500); + // Imposta lo standard per la conversione dei numeri + numeral.register('locale', 'it', { + delimiters: { + thousands: globals.thousands, + decimal: globals.decimals, + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + currency: { + symbol: '€' } }); + numeral.locale('it'); + numeral.defaultFormat('0,0.' + ('0').repeat(globals.cifre_decimali)); - $(slideToTop).click(function () { - $("html, body").animate({ - scrollTop: 0 - }, 500); + // Orologio + clock(); + + // Richiamo alla generazione di Datatables + start_datatables(); + + init(); + + // Calendario principale + start_complete_calendar("#daterange", function (start, end) { + // Esegue il submit del periodo selezionato e ricarica la pagina + $.get(globals.rootdir + '/core.php?period_start=' + start.format('YYYY-MM-DD') + '&period_end=' + end.format('YYYY-MM-DD'), function (data) { + location.reload(); + }); }); - - $(".sidebar-toggle").click(function(){ - setTimeout(function(){ - window.dispatchEvent(new Event('resize')); - }, 350); + + // Messaggi automatici di eliminazione + $(document).on('click', '.ask', function () { + message(this); }); - + // Forza l'evento "blur" nei campi di testo per formattare i numeri con // jquery inputmask prima del submit setTimeout( function(){ diff --git a/assets/src/js/datatables-buttons.js b/assets/src/js/datatables-buttons.js new file mode 100644 index 000000000..b6b939f07 --- /dev/null +++ b/assets/src/js/datatables-buttons.js @@ -0,0 +1,89 @@ +$(document).ready(function () { +// Pulsanti di Datatables + $(".btn-csv").click(function (e) { + var table = $(document).find("#" + $(this).closest("[data-target]").data("target")).DataTable(); + + table.buttons(0).trigger(); + }); + + $(".btn-excel").click(function (e) { + var table = $(document).find("#" + $(this).closest("[data-target]").data("target")).DataTable(); + + table.buttons(3).trigger(); + }); + + $(".btn-pdf").click(function (e) { + var table = $(document).find("#" + $(this).closest("[data-target]").data("target")).DataTable(); + + table.buttons(4).trigger(); + }); + + $(".btn-copy").click(function (e) { + var table = $(document).find("#" + $(this).closest("[data-target]").data("target")).DataTable(); + + table.buttons(1).trigger(); + }); + + $(".btn-print").click(function (e) { + var table = $(document).find("#" + $(this).closest("[data-target]").data("target")).DataTable(); + + table.buttons(2).trigger(); + }); + + $(".btn-select-all").click(function () { + var id = $(document).find("#" + $(this).parent().parent().parent().data("target")); + var table = id.DataTable(); + + $("#main_loading").show(); + table.clear().draw(); + + $(id).data('page-length', table.page.len()); + + table.page.len(-1).draw(); + }); + + $(".btn-select-none").click(function () { + var id = $(document).find("#" + $(this).parent().parent().parent().data("target")); + var table = id.DataTable(); + + table.rows().deselect(); + + table.page.len($(id).data('page-length')); + }); + + $(".bulk-action").click(function () { + var table = $(document).find("#" + $(this).parent().parent().parent().parent().data("target")); + + if (table.data('selected')) { + $(this).attr("data-id_records", table.data('selected')); + $(this).data("id_records", table.data('selected')); + + if ($(this).data("type") == "modal") { + var data = JSON.parse(JSON.stringify($(this).data())); + var href = data.url; + + delete data.url; + delete data.title; + delete data.op; + delete data.backto; + delete data.blank; + + var values = []; + for (var name in data) { + values.push(name + '=' + data[name]); + } + + var link = href + (href.indexOf('?') !== -1 ? '&' : '?') + values.join('&'); + + launch_modal($(this).data("title"), link); + } else { + message(this); + } + + $(this).attr("data-id_records", ""); + $(this).data("id_records", ""); + } else { + swal(globals.translations.waiting, globals.translations.waiting_msg, "error"); + } + }); +}); diff --git a/assets/src/js/functions/datatables.js b/assets/src/js/functions/datatables.js new file mode 100644 index 000000000..a1890ece4 --- /dev/null +++ b/assets/src/js/functions/datatables.js @@ -0,0 +1,429 @@ + +function start_local_datatables(){ + $('.datatables').each(function () { + if (!$.fn.DataTable.isDataTable($(this))) { + $(this).DataTable({ + language: { + url: globals.js + "/i18n/datatables/" + globals.locale + ".min.json" + }, + retrieve: true, + ordering: true, + searching: true, + paging: false, + order: [], + lengthChange: false, + scrollY: "70vh", + }); + } + }); +} + +// Datatable +function start_datatables() { + start_local_datatables(); + + $('.main-records').each(function () { + var $this = $(this); + + $this.data('selected', ''); + + // Controlla che la tabella non sia già inizializzata + if (!$.fn.DataTable.isDataTable('#' + $this.attr('id'))) { + var id_module = $this.data('idmodule'); + var id_plugin = $this.data('idplugin'); + var id_parent = $this.data('idparent'); + + // Parametri di ricerca da url o sessione + var search = getUrlVars(); + + globals.search.forEach(function (value, index, array) { + if (search[array[index]] == undefined) { + search.push(array[index]); + search[array[index]] = array[value]; + } + }); + + // Fix per l'URL encoding + search.forEach(function (value, index, array) { + search[array[index]] = decodeURIComponent(array[value]); + }); + + var res = []; + $this.find("th").each(function () { + var id = $(this).attr('id').replace("th_", ""); + + sear = search["search_" + id] ? search["search_" + id] : ""; + + res.push({ + "sSearch": sear + }); + }); + + var sum; + var tempo; + var tempo_attesa_ricerche = (globals.tempo_attesa_ricerche * 1000); + + var table = $this.DataTable({ + language: { + url: globals.js + '/i18n/datatables/' + globals.locale + '.min.json' + }, + autoWidth: true, + dom: "ti", + serverSide: true, + deferRender: true, + ordering: true, + searching: true, + aaSorting: [], + aoSearchCols: res, + scrollY: "60vh", + scrollX: '100%', + retrieve: true, + stateSave: true, + stateSaveCallback: function (settings, data) { + sessionStorage.setItem('DataTables_' + id_module + '-' + id_plugin + '-' + id_parent, JSON.stringify(data)); + }, + stateLoadCallback: function (settings) { + return JSON.parse(sessionStorage.getItem('DataTables_' + id_module + '-' + id_plugin + '-' + id_parent)); + }, + columnDefs: [{ + searchable: false, + orderable: false, + width: '1%', + className: 'select-checkbox', + targets: 0 + }], + select: { + style: 'multi', + selector: 'td:first-child' + }, + buttons: [{ + extend: 'csv', + fieldSeparator: ";", + exportOptions: { + modifier: { + selected: true + } + } + }, + { + extend: 'copy', + exportOptions: { + modifier: { + selected: true + } + } + }, + { + extend: 'print', + autoPrint: true, + customize: function (win) { + $(win.document.body) + .css('font-size', '10pt') + .append( + '
' + $('#summable').text() + '
' + ); + $(win.document.body).find('table') + .addClass('compact') + .css('font-size', 'inherit'); + $(win.document.body).find('td:first-child') + .addClass('hide'); + $(win.document.body).find('th:first-child') + .addClass('hide'); + }, + exportOptions: { + modifier: { + selected: true + } + } + }, + { + extend: 'excel', + exportOptions: { + modifier: { + selected: true + }, + format: { + body: function(data, row, column, node) { + data = $('

' + data + '

').text(); + data_edit = data.replace('.', ''); + data_edit = data_edit.replace(',', '.'); + + return data_edit.match(/^[0-9\.]+$/) ? data_edit : data; + } + } + } + }, + { + extend: 'pdf', + exportOptions: { + modifier: { + selected: true + } + } + }, + ], + scroller: { + loadingIndicator: true, + displayBuffer: globals.dataload_page_buffer, + }, + ajax: { + url: "ajax_dataload.php?id_module=" + id_module + "&id_plugin=" + id_plugin + "&id_parent=" + id_parent, + type: 'GET', + dataSrc: function (data) { + sum = data; + return data.data; + } + }, + initComplete: function (settings) { + var api = this.api(); + + api.columns('.search').every(function () { + var column = this; + $('
') + .appendTo(column.header()) + .on('keyup', function (e) { + + clearInterval(tempo); + + // Fix del pulsante di pulizia ricerca e del messaggio sulla ricerca lenta + if (e.which != 9) { + if (!$(this).val()) { + if ($(this).parent().data("slow") != undefined) $("#slow").remove(); + $(this).removeClass('input-searching'); + $(this).next('.deleteicon').addClass('hide'); + } else { + if ($(this).parent().data("slow") != undefined && $("#slow").length == 0) { + $("#" + $this.attr('id') + "_info").parent().append(' ' + globals.translations.long + ''); + } + $(this).addClass('input-searching'); + $(this).next('.deleteicon').removeClass('hide'); + } + } + + function start_search(module_id, field, search_value) { + searchTable(module_id, field, search_value); + column.search(search_value).draw(); + } + + // Impostazione delle sessioni per le ricerche del modulo e del campo specificati + var module_id = $this.data('idmodule'); //+ "-" + $this.data('idplugin'); + var field = $(this).parent().attr('id').replace('th_', ''); + var value = $(this).val(); + if (e.keyCode == 13 || $(this).val() == '') { + start_search(module_id, field, value); + } else { + tempo = window.setTimeout(start_search, tempo_attesa_ricerche, module_id, field, value); + } + }); + }); + + // Disabilito l'ordinamento alla pressione del tasto invio sull' + $("thead input, .search").on('keypress', function (e) { + stopTableSorting(e); + }); + + // Disabilito l'ordinamento al click sull' + $("thead input, .deleteicon").click(function (e) { + stopTableSorting(e); + }); + + $('.deleteicon').on("click", function (e) { + resetTableSearch($(this).parent().attr("id").replace("th_", "")); + + if (api.page.len() == -1){ + api.page.len($(id).data('page-length')); + } + }); + + // Ricerca di base ereditata dalla sessione + search.forEach(function (value, index, array) { + var exists = setInterval(function () { + input = $('#th_' + array[index].replace('search_', '') + ' input'); + if (input.length || array[index] == 'id_module' || array[index] == 'id_record') { + clearInterval(exists); + if (input.val() == '') input.val(array[value]).trigger('keyup'); + } + }, 100); + }); + }, + rowCallback: function (row, data, index) { + if ($(data[0]).data('id') && $.inArray($(data[0]).data('id'), $this.data('selected').split(';')) !== -1) { + table.row(index).select(); + } + }, + drawCallback: function (settings) { + var api = new $.fn.dataTable.Api(settings); + + $(".dataTables_sizing .deleteicon").addClass('hide'); + + $("[data-background]").each(function () { + $(this).parent().css("background", $(this).data("background")); + }); + + $("[data-color]").each(function () { + $(this).parent().css("color", $(this).data("color")); + }); + + $("[data-link]").each(function () { + var $link = $(this); + $(this).parent().not('.bound').addClass('bound').click(function (event) { + if ($link.data('type') == 'dialog') { + launch_modal(globals.translations.details, $link.data('link')); + } else { + openLink(event, $link.data('link')) + } + }); + $(this).parent().addClass("clickable"); + }); + + var container = $(document).find('[data-target=' + $this.attr('id') + ']'); + + if (api.rows({ + selected: true + }).count() > 0) { + container.find('.table-btn').removeClass('disabled').attr('disabled', false); + } else { + container.find('.table-btn').addClass('disabled').attr('disabled', true); + } + + // Seleziona tutto + if (api.page.len() == -1) { + api.rows({ + search: "applied" + }).select(); + + if (this.fnSettings().fnRecordsDisplay() == api.rows({ + selected: true + }).count()) { + $("#main_loading").fadeOut(); + } + } + }, + footerCallback: function (row, data, start, end, display) { + var i = -1; + this.api().columns().every(function () { + if (sum.summable[i] != undefined) { + $(this.footer()).addClass("text-right"); + $(this.footer()).attr("id", "summable"); + $(this.footer()).html(sum.summable[i]); + } + i++; + }); + } + }); + + table.on('select deselect', function (e, dt, type, indexes) { + if (type === 'row') { + var selected = $this.data('selected').split(';'); + + selected = selected.filter(function (value, index, self) { + return value != '' && self.indexOf(value) === index; + }); + + var data = table.rows(indexes).data(); + + data.each(function (item) { + var id = $(item[0]).data('id'); + + if (id) { + if (e.type == 'select') { + selected.push(id); + } else { + var index = selected.indexOf("" + id); + if (index > -1) { + delete selected[index]; + } + } + } + }); + + selected = selected.filter(function (value, index, self) { + return value != '' && self.indexOf(value) === index; + }); + + $this.data('selected', selected.join(';')); + + var container = $(document).find('[data-target=' + $this.attr('id') + ']'); + + if (selected.length > 0) { + container.find('.bulk-container').removeClass('disabled'); + container.find('.bulk-container').attr('disabled', false); + } else { + container.find('.bulk-container').addClass('disabled'); + container.find('.bulk-container').attr('disabled', true); + } + + if (table.rows({ + selected: true + }).count() > 0) { + container.find('.table-btn').removeClass('disabled').attr('disabled', false); + } else { + container.find('.table-btn').addClass('disabled').attr('disabled', true); + } + } + }); + + table.on('processing.dt', function (e, settings, processing) { + if (processing) { + $('#mini-loader').show(); + } else { + $('#mini-loader').hide(); + + //Reimposto il flag sulle righe ricaricate selezionate in precedenza + var selected = $this.data('selected').split(';'); + + table.rows().every(function (rowIdx, tableLoop, rowLoop) { + var object_span = $.parseHTML(this.data()[0])[0]; + var id = $(object_span).data('id'); + + for (i = 0; i < selected.length; i++) { + var value = selected[i]; + if (value == id) { + table.row(':eq(' + rowIdx + ')', { + page: 'current' + }).select(); + } + } + }); + } + }) + } + }); +} + +function stopTableSorting(e) { + if (!e) var e = window.event; + e.cancelBubble = true; + if (e.stopPropagation) e.stopPropagation(); +} + +function resetTableSearch(type) { + if (type == null) $('[id^=th_] input').val('').trigger('keyup'); + else $('[id^=th_' + type + '] input').val('').trigger('keyup'); +} + +function reset(type) { + return resetTableSearch(type); +} + +/** + * Sostituisce i caratteri speciali per la ricerca attraverso le tabelle Datatables. + * + * @param string field + * + * @return string + */ +function searchFieldName(field) { + return field.replace(' ', '-').replace('.', ''); +} + +/** + * Salva nella sessione la ricerca per le tabelle Datatables. + * + * @param int module_id + * @param string field + * @param mixed value + */ +function searchTable(module_id, field, value) { + session_set('module_' + module_id + ',' + 'search_' + searchFieldName(field), value, 0); +} diff --git a/assets/src/js/functions/dates.js b/assets/src/js/functions/dates.js new file mode 100644 index 000000000..8f97499df --- /dev/null +++ b/assets/src/js/functions/dates.js @@ -0,0 +1,101 @@ + +function start_datepickers() { + var icons = { + time: 'fa fa-clock-o', + date: 'fa fa-calendar', + up: 'fa fa-chevron-up', + down: 'fa fa-chevron-down', + previous: 'fa fa-chevron-left', + next: 'fa fa-chevron-right', + today: 'fa fa-street-view', + clear: 'fa fa-trash', + close: 'fa fa-times' + }; + + $('.timestamp-picker').each(function () { + $this = $(this); + $this.datetimepicker({ + locale: globals.locale, + icons: icons, + collapse: false, + sideBySide: true, + useCurrent: false, + stepping: 5, + widgetPositioning: { + horizontal: 'left', + vertical: 'bottom' + }, + 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 + $('.timestamp-picker').each(function () { + $this = $(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 () { + $this = $(this); + $this.datetimepicker({ + locale: globals.locale, + icons: icons, + useCurrent: false, + format: 'L', + 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 () { + $this = $(this); + $this.datetimepicker({ + locale: globals.locale, + icons: icons, + useCurrent: false, + format: 'LT', + 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_complete_calendar(id, callback) { + var ranges = {}; + ranges[globals.translations.today] = [moment(), moment()]; + ranges[globals.translations.firstThreemester] = [moment("01", "MM"), moment("03", "MM").endOf('month')]; + ranges[globals.translations.secondThreemester] = [moment("04", "MM"), moment("06", "MM").endOf('month')]; + ranges[globals.translations.thirdThreemester] = [moment("07", "MM"), moment("09", "MM").endOf('month')]; + ranges[globals.translations.fourthThreemester] = [moment("10", "MM"), moment("12", "MM").endOf('month')]; + ranges[globals.translations.firstSemester] = [moment("01", "MM"), moment("06", "MM").endOf('month')]; + ranges[globals.translations.secondSemester] = [moment("06", "MM"), moment("12", "MM").endOf('month')]; + ranges[globals.translations.thisMonth] = [moment().startOf('month'), moment().endOf('month')]; + ranges[globals.translations.lastMonth] = [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]; + ranges[globals.translations.thisYear] = [moment().startOf('year'), moment().endOf('year')]; + ranges[globals.translations.lastYear] = [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')]; + + $(id).daterangepicker({ + locale: { + customRangeLabel: globals.translations.custom, + applyLabel: globals.translations.apply, + cancelLabel: globals.translations.cancel, + fromLabel: globals.translations.from, + toLabel: globals.translations.to, + }, + ranges: ranges, + startDate: globals.start_date_formatted, + endDate: globals.end_date_formatted, + applyClass: 'btn btn-success btn-sm', + cancelClass: 'btn btn-danger btn-sm', + linkedCalendars: false + }, + callback + ); +} diff --git a/assets/src/js/functions/functions.js b/assets/src/js/functions/functions.js new file mode 100644 index 000000000..280bc979f --- /dev/null +++ b/assets/src/js/functions/functions.js @@ -0,0 +1,488 @@ +// Modal +function launch_modal(title, href, init_modal, id) { + // Fix - Select2 does not function properly when I use it inside a Bootstrap modal. + $.fn.modal.Constructor.prototype.enforceFocus = function () { + }; + + if (id == null) { + id = '#bs-popup'; + + // Generazione dinamica modal + /* + id = 'bs-popup-' + Math.floor(Math.random() * 100); + $('#modals').append(''); + + id = '#' + id; + */ + } + + if (init_modal == null) { + init_modal = 1; + } + + $(id).on('hidden.bs.modal', function () { + if ($('.modal-backdrop').length < 1) { + $(this).html(''); + $(this).data('modal', null); + } + }); + + // Lettura contenuto div + if (href.substr(0, 1) == '#') { + data = $(href).html(); + + $(id).html( + '