From 10e1301eb73e61ede8189521b8b6f2f55ab470bf Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Tue, 20 Jul 2021 15:23:39 +0200 Subject: [PATCH 1/6] Rimozione dipendenza UI Autocomplete Rimozione della dipendenza UI Autocomplete in favore di una libreria indipendente, aggiornamento funzioni JS per la gestione degli allegati. --- assets/src/css/style.css | 22 +- assets/src/js/base/datatables-buttons.js | 2 +- assets/src/js/base/supersearch.js | 127 +++++----- assets/src/js/functions/allegati.js | 308 +++++++++++++++++++++++ gulpfile.js | 4 +- include/modifica_allegato.php | 32 ++- include/top.php | 16 +- mail.php | 58 ++--- modules/preventivi/ajax/search.php | 4 +- package.json | 2 + src/HTMLBuilder/Manager/FileManager.php | 191 ++++---------- 11 files changed, 508 insertions(+), 258 deletions(-) create mode 100644 assets/src/js/functions/allegati.js diff --git a/assets/src/css/style.css b/assets/src/css/style.css index ce3c6ff71..0ba672be8 100755 --- a/assets/src/css/style.css +++ b/assets/src/css/style.css @@ -81,7 +81,8 @@ input[type=file] { position: fixed; } -.ui-autocomplete { +.autocomplete, .ui-autocomplete { + background: white; z-index: 10000; min-width: 160px; padding: 10px; @@ -94,8 +95,23 @@ input[type=file] { border-radius: 5px; } -.ui-autocomplete-category { - font-size: 150%; +.autocomplete .group, .ui-autocomplete-category { + font-size: 1.5em; + background: inherit; +} + +.autocomplete > div { + padding: 5px; +} + +.highlight { + background: #FFFF66; +} + +.autocomplete > div:hover:not(.group), +.autocomplete > div.selected { + background: #F5F5F5; + cursor: pointer; } .ui-autocomplete-scrollable { diff --git a/assets/src/js/base/datatables-buttons.js b/assets/src/js/base/datatables-buttons.js index ce35069f5..9838dd939 100644 --- a/assets/src/js/base/datatables-buttons.js +++ b/assets/src/js/base/datatables-buttons.js @@ -138,7 +138,7 @@ $(document).ready(function () { $(this).attr("data-id_records", ""); $(this).data("id_records", ""); } else { - swal(globals.translations.waiting, globals.translations.waiting_msg, "error"); + swal(globals.translations.waiting, globals.translations.waitingMessage, "error"); } }); }); diff --git a/assets/src/js/base/supersearch.js b/assets/src/js/base/supersearch.js index 37f153c09..23212355a 100644 --- a/assets/src/js/base/supersearch.js +++ b/assets/src/js/base/supersearch.js @@ -17,88 +17,75 @@ */ $(document).ready(function () { - $('#supersearch').keyup(function () { - $(document).ajaxStop(); + const searchInput = $('#supersearch'); + const searchButton = searchInput.parent().find('i'); + const searches = []; - if ($(this).val() == '') { - $(this).removeClass('wait'); - } else { - $(this).addClass('wait'); - } - }); + autocomplete({ + minLength: 1, + input: searchInput[0], + emptyMsg: globals.translations.noResults, + debounceWaitMs: 500, + fetch: function(text, update) { + text = text.toLowerCase(); - $.widget("custom.supersearch", $.ui.autocomplete, { - _create: function () { - this._super(); - this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)"); - }, - _renderMenu: function (ul, items) { - if (items[0].value == undefined) { - $('#supersearch').removeClass('wait'); - ul.html(''); - } else { - var that = this, - currentCategory = ""; + // Registrazione ricerca + searches.push(text); + searchButton + .removeClass('fa-search') + .addClass('fa-spinner fa-spin'); - ul.addClass('ui-autocomplete-scrollable'); - ul.css('z-index', '999'); - - $.each(items, function (index, item) { - - if (item.category != currentCategory) { - ul.append("
  • " + item.category + "
  • "); - currentCategory = item.category; - } - - that._renderItemData(ul, item); - }); - } - }, - _renderItem: function (ul, item) { - return $("
  • ") - .append("" + item.value + "
    " + item.label + "
    ") - .appendTo(ul); - } - }); - - // Configurazione supersearch - var $super = $('#supersearch').supersearch({ - minLength: 3, - select: function (event, ui) { - location.href = ui.item.link; - }, - source: function (request, response) { $.ajax({ url: globals.rootdir + '/ajax_search.php', - dataType: "json", + dataType: "JSON", data: { - term: request.term + term: text, }, - - complete: function (jqXHR) { - $('#supersearch').removeClass('wait'); - }, - success: function (data) { - if (data == null) { - response($.map(['a'], function (item) { - return false; - })); - } else { - response($.map(data, function (item) { - labels = (item.labels).toString(); - labels = labels.replace('
    ,', '
    '); + // Fix per gestione risultati null + data = data ? data : []; - return { - label: labels, - category: item.category, - link: item.link, - value: item.title - } - })); + // Trasformazione risultati in formato leggibile + const results = data.map(function (result) { + return { + label: result.label ? result.label : '

    ' + result.title + '

    ' + result.labels + .join('').split('
    ,').join('
    '), + group: result.category, + link: result.link, + value: result.title + } + }); + + // Rimozione ricerca in corso + searches.pop(); + if (searches.length === 0) { + searchButton + .removeClass('fa-spinner fa-spin') + .addClass('fa-search'); } + + update(results); + }, + error: function (){ + searchButton + .removeClass('fa-spinner fa-spin') + .addClass('fa-exclamation-triangle'); } }); + }, + preventSubmit: true, + disableAutoSelect: true, + onSelect: function(item) { + window.location.href = item.link; + }, + customize: function(input, inputRect, container, maxHeight) { + container.style.width = '600px'; + }, + render: function(item, currentValue){ + const itemElement = document.createElement("div"); + itemElement.innerHTML = item.label; + // " + item.value + "
    " + item.label + "
    + return itemElement; } }); }); diff --git a/assets/src/js/functions/allegati.js b/assets/src/js/functions/allegati.js new file mode 100644 index 000000000..f15708843 --- /dev/null +++ b/assets/src/js/functions/allegati.js @@ -0,0 +1,308 @@ +/* + * OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione + * Copyright (C) DevCode s.r.l. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Disabling autoDiscover, otherwise Dropzone will try to attach twice. +Dropzone.autoDiscover = false; + +/** + * Restituisce filename ed estensione di un file indicato. + * @param path + * @returns [string, string] + */ +function getFilenameAndExtension(path) { + let filename_extension = path.replace(/^.*[\\\/]/, ''); + let filename = filename_extension.substring(0, filename_extension.lastIndexOf('.')); + let ext = filename_extension.split('.').pop(); + + return [filename, ext]; +} + +/** + * Inizializza la gestione degli allegati. + * @param gestione + */ +function initGestioneAllegati(gestione) { + const dropzone_id = '#' + gestione.attr('id') + ' .dropzone'; + const maxFilesize = gestione.data('max_filesize'); + if ($(dropzone_id).length === 0) { + return; + } + + let params = new URLSearchParams({ + op: "aggiungi-allegato", + id_module: gestione.data('id_module'), + id_plugin: gestione.data('id_plugin'), + id_record: gestione.data('id_record'), + }).toString(); + + let dragdrop = new Dropzone(dropzone_id, { + dictDefaultMessage: globals.translations.allegati.messaggio + ".
    (" + globals.translations.allegati.maxFilesize.replace('_SIZE_', maxFilesize) + ")", + paramName: "file", + maxFilesize: maxFilesize, // MB + uploadMultiple: false, + parallelUploads: 2, + addRemoveLinks: false, + autoProcessQueue: true, + autoQueue: true, + url: globals.rootdir + "/actions.php?" + params, + init: function (file, xhr, formData) { + this.on("success", function (file) { + dragdrop.removeFile(file); + }); + + this.on("complete", function (file) { + // Ricarico solo quando ho finito + if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) { + ricaricaAllegati(gestione); + } + }); + } + }); +} + +/** + * Funzione per l'apertura della schermata di modifica per una categoria di allegati. + * @param gestione + * @param pulsanteModifica + */ +function modificaCategoriaAllegati(gestione, pulsanteModifica) { + const categoria = $(pulsanteModifica).parent().parent(); + console.log(categoria) + + const nome = categoria.find(".box-title"); + nome.addClass('hidden'); + $(pulsanteModifica).addClass('hidden'); + + const pulsanteSalva = categoria.find(".category-save"); + const pulsanteAnnulla = categoria.find(".category-cancel"); + const inputNome = categoria.find(".category-name"); + pulsanteSalva.removeClass("hidden"); + pulsanteAnnulla.removeClass("hidden"); + inputNome.removeClass("hidden"); +} + +/** + * Funzione per salvare le modifiche effettuate su una categoria di allegati. + * @param gestione + * @param pulsanteSalva + */ +function salvaCategoriaAllegati(gestione, pulsanteSalva) { + const categoria = $(pulsanteSalva).parent().parent(); + + const nome = categoria.find(".box-title"); + const inputNome = categoria.find(".category-name"); + + mostraCaricamentoAllegati(gestione); + + $.ajax({ + url: globals.rootdir + "/actions.php", + cache: false, + type: "POST", + data: { + op: "modifica-categoria-allegato", + id_module: gestione.data('id_module'), + id_plugin: gestione.data('id_plugin'), + id_record: gestione.data('id_record'), + category: nome.text(), + name: inputNome.val(), + }, + success: function (data) { + ricaricaAllegati(gestione); + }, + error: function (gestione) { + ricaricaAllegati(gestione); + } + }); +} + +/** + * Funzione per caricare un nuovo allegato. + * @param gestione + */ +function aggiungiAllegato(gestione) { + const id = "#" + gestione.attr('id'); + const form = $(id + " #upload-form"); + + form.ajaxSubmit({ + url: globals.rootdir + "/actions.php", + data: data, + type: "post", + uploadProgress: function (event, position, total, percentComplete) { + $(id + " #upload").prop("disabled", true).html(percentComplete + "%").removeClass("btn-success").addClass("btn-info"); + }, + success: function (data) { + ricaricaAllegati(gestione); + }, + error: function (data) { + alert(globals.translations.allegati.errore + ": " + data); + } + }); +} + +/** + * Funzione per mostrare il loader di caricamento per gli allegati. + * @param gestione + */ +function mostraCaricamentoAllegati(gestione) { + const id = "#" + gestione.attr('id'); + + localLoading($(id + " .panel-body"), true); +} + +/** + * Funzione dedicata al caricamento dinamico degli allegati. + * @param gestione + */ +function ricaricaAllegati(gestione) { + const id = "#" + gestione.attr('id'); + + let params = new URLSearchParams({ + op: "list_attachments", + id_module: gestione.data('id_module'), + id_plugin: gestione.data('id_plugin'), + id_record: gestione.data('id_record'), + }).toString(); + + $(id).load(globals.rootdir + "/ajax.php?" + params, function () { + localLoading($(id + " .panel-body"), false); + + const nuovoAllegato = $(id + " table tr").eq(-1).attr("id"); + if (nuovoAllegato !== undefined) { + $("#" + nuovoAllegato).effect("highlight", {}, 1500); + } + }); +} + +/** + * Funzione per l'apertura della pagina di gestione dei dati dell'allegato. + * @param button + */ +function modificaAllegato(button) { + const gestione = $(button).closest(".gestione-allegati"); + const allegato = $(button).closest("tr").data(); + + let params = new URLSearchParams({ + op: "visualizza-modifica-allegato", + id_module: gestione.data('id_module'), + id_plugin: gestione.data('id_plugin'), + id_record: gestione.data('id_record'), + id_allegato: allegato.id, + }).toString(); + + openModal(globals.translations.allegati.modifica, globals.rootdir + "/actions.php?" + params); +} + +/** + * Funzione per gestire il download di un allegato. + * @param button + */ +function saggiungiAllegato(button) { + const gestione = $(button).closest(".gestione-allegati"); + const allegato = $(button).closest("tr").data(); + + let params = new URLSearchParams({ + op: "download-allegato", + id_module: gestione.data('id_module'), + id_plugin: gestione.data('id_plugin'), + id_record: gestione.data('id_record'), + id: allegato.id, + filename: allegato.filename, + }).toString(); + + window.open(globals.rootdir + "/actions.php?" + params, "_blank") +} + +/** + * Funzione per l'apertura dell'anteprima di visualizzazione allegato. + * @param button + */ +function visualizzaAllegato(button) { + const allegato = $(button).closest("tr").data(); + + let params = new URLSearchParams({ + file_id: allegato.id, + }).toString(); + + openModal(allegato.nome + ' (' + allegato.filename + ')', globals.rootdir + "/view.php?" + params); +} + +/** + * Funzione per la gestione della rimozione di un allegato specifico. + * + * @param button + */ +function rimuoviAllegato(button) { + const gestione = $(button).closest(".gestione-allegati"); + const allegato = $(button).closest("tr").data(); + + swal({ + title: globals.translations.allegati.elimina, + type: "warning", + showCancelButton: true, + confirmButtonText: globals.translations.allegati.procedi, + }).then(function () { + mostraCaricamentoAllegati(gestione); + + // Parametri della richiesta AJAX + let params = new URLSearchParams({ + op: "rimuovi-allegato", + id_module: gestione.data('id_module'), + id_plugin: gestione.data('id_plugin'), + id_record: gestione.data('id_record'), + id_allegato: allegato.id, + filename: allegato.filename, + }).toString(); + + // Richiesta AJAX + $.ajax(globals.rootdir + "/actions.php?" + params) + .then(function () { + ricaricaAllegati(gestione); + }); + }).catch(swal.noop); +} + +function impostaCategorieAllegatiDisponibili(gestione, categorie) { + // Disabilitazione per rimozione input in aggiunta + return; + + const id = "#" + gestione.attr('id'); + const input = $("#modifica-allegato #categoria_allegato")[0]; + + autocomplete({ + minLength: 0, + input: input, + emptyMsg: globals.translations.noResults, + fetch: function (text, update) { + text = text.toLowerCase(); + const suggestions = categorie.filter(n => n.toLowerCase().startsWith(text)); + + // Trasformazione risultati in formato leggibile + const results = suggestions.map(function (result) { + return { + label: result, + value: result + } + }); + + update(results); + }, + onSelect: function (item) { + input.value = item.label; + }, + }); +} diff --git a/gulpfile.js b/gulpfile.js index a4518f700..f34e24a0d 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -82,9 +82,11 @@ const JS = gulp.parallel(() => { const vendor = [ 'jquery/dist/jquery.js', 'autosize/dist/autosize.js', + 'autocompleter/autocomplete.js', + 'html5sortable/dist/html5sortable.js', 'bootstrap-colorpicker/dist/js/bootstrap-colorpicker.js', 'moment/moment.js', - 'components-jqueryui/jquery-ui.js', + //'components-jqueryui/jquery-ui.js', 'datatables.net/js/jquery.dataTables.js', 'datatables.net-buttons/js/dataTables.buttons.js', 'datatables.net-buttons/js/buttons.colVis.js', diff --git a/include/modifica_allegato.php b/include/modifica_allegato.php index 80bbc43ec..a6a41db5d 100644 --- a/include/modifica_allegato.php +++ b/include/modifica_allegato.php @@ -56,12 +56,34 @@ $source = array_clean(array_column($categories, 'category')); echo ' '; diff --git a/include/top.php b/include/top.php index 05721121c..e2b8b2b01 100755 --- a/include/top.php +++ b/include/top.php @@ -108,19 +108,28 @@ if (Auth::check()) { 'details' => tr('Dettagli'), 'loading' => tr('Caricamento'), 'waiting' => tr('Impossibile procedere'), - 'waiting_msg' => tr('Prima di proseguire devi selezionare alcuni elementi!'), + 'waitingMessage' => tr('Prima di proseguire devi selezionare alcuni elementi!'), 'hooksExecuting' => tr('Hooks in esecuzione'), 'hookExecuting' => tr('Hook "_NAME_" in esecuzione'), 'hookMultiple' => tr('Hai _NUM_ notifiche'), 'hookSingle' => tr('Hai 1 notifica'), 'hookNone' => tr('Nessuna notifica'), 'singleCalendar' => tr("E' presente un solo periodo!"), + 'noResults' => tr("Nessun elemento trovato"), ]; foreach ($translations as $key => $value) { echo ' '.$key.': "'.addslashes($value).'",'; } echo ' + allegati: { + messaggio: "'.tr("Clicca o trascina qui per caricare uno o più file").'", + maxFilesize: "'.tr('Max upload: _SIZE_ MB').'", + errore: "'.tr('Errore').'", + modifica: "'.tr('Modifica allegato').'", + elimina: "'.tr('Vuoi eliminare questo file?').'", + procedi: "'.tr('Procedi').'", + }, ajax: { "missing": { "title": "'.tr('Errore').'", @@ -292,7 +301,7 @@ if (Auth::check()) { hotkeys("f1,f2,f3,f4", function(event, handler) { switch (handler.key) { - case "f1": + case "f1": event.preventDefault(); $("button[data-toggle]").first().trigger("click"); break; @@ -453,7 +462,8 @@ if (Auth::check()) {
    - diff --git a/mail.php b/mail.php index 9e4a67360..4b7125665 100755 --- a/mail.php +++ b/mail.php @@ -158,58 +158,58 @@ echo ' echo ' '; diff --git a/modules/preventivi/ajax/search.php b/modules/preventivi/ajax/search.php index 5b86e1bed..4701a463b 100755 --- a/modules/preventivi/ajax/search.php +++ b/modules/preventivi/ajax/search.php @@ -49,8 +49,8 @@ foreach ($rs as $r) { $result['link'] = base_path().'/editor.php?id_module='.$link_id.'&id_record='.$r['id']; $result['title'] = 'Preventivo '.$r['numero']; - if ($rs[$r]['data_accettazione'] == '0000-00-00') { - $result['title'] .= ' del '.Translator::dateToLocale($rs[$r]['data_accettazione']); + if ($r['data_accettazione'] == '0000-00-00') { + $result['title'] .= ' del '.Translator::dateToLocale($r['data_accettazione']); } $result['category'] = 'Preventivi'; diff --git a/package.json b/package.json index 5668b2e9d..d1cb56a98 100755 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "main": "gulpfile.js", "dependencies": { "admin-lte": "^2.4.0", + "autocompleter": "^6.1.1", "autonumeric": "^4.6.0", "autosize": "^3.0.21", "bootstrap": "^3.3.7", @@ -22,6 +23,7 @@ "fullcalendar": "^3.4.0", "geocomplete": "^1.7.0", "hotkeys-js": "^3.8.5", + "html5sortable": "^0.13.2", "inputmask": "^3.3.9", "jquery": "^3.5.1", "jquery-form": "^4.2.1", diff --git a/src/HTMLBuilder/Manager/FileManager.php b/src/HTMLBuilder/Manager/FileManager.php index 3619503e6..401b1e8a7 100755 --- a/src/HTMLBuilder/Manager/FileManager.php +++ b/src/HTMLBuilder/Manager/FileManager.php @@ -21,6 +21,7 @@ namespace HTMLBuilder\Manager; use Models\Setting; use Models\Upload; +use Util\FileSystem; /** * Gestione allegati. @@ -47,11 +48,14 @@ class FileManager implements ManagerInterface // ID del form $attachment_id = 'attachments_'.$options['id_module'].'_'.$options['id_plugin']; + $upload_max_filesize = ini_get('upload_max_filesize'); + $upload_max_filesize = substr($upload_max_filesize, 0, -1); + $dbo = database(); // Codice HTML $result = ' -
    '; +
    '; if (!empty($options['showpanel'])) { $result .= ' @@ -79,16 +83,20 @@ class FileManager implements ManagerInterface

    '.(!empty($category) ? $category : tr('Generale')).'

    - {[ "type": "text", "class": "hide category-name", "value": "'.$category.'" ]} + {[ "type": "text", "class": "hidden category-name", "value": "'.$category.'" ]}
    '; if (!empty($category) && !in_array($category, ['Fattura Elettronica'])) { $result .= ' - + + '; @@ -115,7 +123,7 @@ class FileManager implements ManagerInterface $file = Upload::find($r['id']); $result .= ' - + '; if ($file->user && $file->user->photo) { @@ -133,38 +141,38 @@ class FileManager implements ManagerInterface '.$r['name'].' - ('.$file->extension.')'.((!empty($file->size)) ? ' ('.\Util\FileSystem::formatBytes($file->size).')' : '').' '.(((setting('Logo stampe') == $r['filename']) || (setting('Filigrana stampe') == $r['filename'])) ? '' : '').''.' + ('.$file->extension.')'.((!empty($file->size)) ? ' ('. FileSystem::formatBytes($file->size).')' : '').' '.(((setting('Logo stampe') == $r['filename']) || (setting('Filigrana stampe') == $r['filename'])) ? '' : '').''.' - '.\Translator::timestampToLocale($r['created_at']).' + '.timestampFormat($r['created_at']).' - + '; // Anteprime supportate dal browser if ($file->hasPreview()) { $result .= ' - '; } else { $result .= ' - '; } if (!$options['readonly']) { $result .= ' - - + '; } $result .= ' @@ -214,147 +222,42 @@ class FileManager implements ManagerInterface $source = array_clean(array_column($categories, 'category')); - $upload_max_filesize = ini_get('upload_max_filesize'); - $upload_max_filesize = substr($upload_max_filesize, 0, -1); - $result .= ' '; return $result; From 82a21477783fa9a13ceb10b79df102b02dcd16b1 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Tue, 20 Jul 2021 20:48:02 +0200 Subject: [PATCH 2/6] Rimozione dipendenza JQuery UI per sorting --- assets/src/css/style.css | 10 +++++- assets/src/js/base/sidebar.js | 26 +++++++-------- assets/src/js/base/widgets.js | 39 ++++++++++++----------- gulpfile.js | 2 +- include/colonne.php | 29 ++++++++--------- modules/contratti/row-list.php | 34 +++++++++----------- modules/ddt/row-list.php | 34 +++++++++----------- modules/fatture/row-list.php | 34 +++++++++----------- modules/ordini/row-list.php | 34 +++++++++----------- modules/preventivi/row-list.php | 34 +++++++++----------- modules/stato_servizi/actions.php | 31 ++++-------------- modules/viste/fields.php | 37 ++++++++------------- plugins/checks.php | 24 ++++++-------- src/HTMLBuilder/Manager/WidgetManager.php | 2 +- src/Modules.php | 2 +- 15 files changed, 163 insertions(+), 209 deletions(-) diff --git a/assets/src/css/style.css b/assets/src/css/style.css index 0ba672be8..0f3c87898 100755 --- a/assets/src/css/style.css +++ b/assets/src/css/style.css @@ -1085,6 +1085,14 @@ div.tip { background-color: rgba(255, 99, 71, 0.6) !important; } -.login-box .img-responsive{ +.login-box .img-responsive { padding: 18px 0px 4px; } + +.no-selection { + -webkit-touch-callout: none; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} diff --git a/assets/src/js/base/sidebar.js b/assets/src/js/base/sidebar.js index 906b847aa..c0c292e88 100644 --- a/assets/src/js/base/sidebar.js +++ b/assets/src/js/base/sidebar.js @@ -40,21 +40,21 @@ $(document).ready(function () { } // Menu ordinabile - $(".sidebar-menu").sortable({ - cursor: 'move', + if (!globals.is_mobile) { + sortable(".sidebar-menu", { + axis: "y", + cursor: "move", + dropOnEmpty: true, + scroll: true, + })[0].addEventListener("sortupdate", function(e) { + let order = $(".sidebar-menu > .treeview[data-id]").toArray().map(a => $(a).data("id")) - stop: function (event, ui) { - let order = $(this).sortable('toArray').toString(); - - $.post(globals.rootdir + "/actions.php?id_module=" + globals.order_manager_id, { - op: 'sort_modules', - ids: order + $.post(globals.rootdir + "/actions.php", { + id_module: globals.order_manager_id, + op: "sort_modules", + order: order.join(","), }); - } - }); - - if (globals.is_mobile) { - $(".sidebar-menu").sortable("disable"); + }); } $(".sidebar-toggle").click(function () { diff --git a/assets/src/js/base/widgets.js b/assets/src/js/base/widgets.js index 4736df14a..3aae07b43 100644 --- a/assets/src/js/base/widgets.js +++ b/assets/src/js/base/widgets.js @@ -17,35 +17,36 @@ */ $(document).ready(function () { - $("#widget-top, #widget-right").sortable({ + const widgets = sortable("#widget-top, #widget-right", { + forcePlaceholderSize: true, items: 'li', cursor: 'move', dropOnEmpty: true, - connectWith: '.widget', + acceptFrom: '.widget', scroll: true, - helper: 'clone', - start: function (event, ui) { - // Salvo la lista da cui proviene il drag - src_list = ($(this).attr('id')).replace('widget-', ''); + }); - // Evidenzio le aree dei widget - $('.widget').addClass('bordered').sortable('refreshPositions'); - }, - stop: function (event, ui) { + for (const sorting of widgets) { + sorting.addEventListener("sortupdate", function (e) { // Rimuovo l'evidenziazione dell'area widget $('.widget').removeClass('bordered'); // Salvo la lista su cui ho eseguito il drop - dst_list = (ui.item.parent().attr('id')).replace('widget-', ''); + const location = $(e.detail.destination.container).attr('id').replace('widget-', ''); - var order = $(this).sortable('toArray').toString(); - $.post(globals.rootdir + "/actions.php?id_module=" + globals.order_manager_id, { - op: 'sort_widgets', - location: dst_list, - ids: order, + let order = $(".widget li[data-id]").toArray().map(a => $(a).data("id")) + $.post(globals.rootdir + "/actions.php", { + id_module: globals.order_manager_id, id_module_widget: globals.id_module, - id_record: globals.id_record, + op: 'sort_widgets', + location: location, + order: order.join(','), }); - } - }); + }); + + sorting.addEventListener("sortstart", function (e) { + // Evidenzio le aree dei widget + $('.widget').addClass('bordered'); + }); + } }); diff --git a/gulpfile.js b/gulpfile.js index f34e24a0d..e13758c78 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -86,7 +86,7 @@ const JS = gulp.parallel(() => { 'html5sortable/dist/html5sortable.js', 'bootstrap-colorpicker/dist/js/bootstrap-colorpicker.js', 'moment/moment.js', - //'components-jqueryui/jquery-ui.js', + 'components-jqueryui/jquery-ui.js', 'datatables.net/js/jquery.dataTables.js', 'datatables.net-buttons/js/dataTables.buttons.js', 'datatables.net-buttons/js/buttons.colVis.js', diff --git a/include/colonne.php b/include/colonne.php index 1ce8a8c94..6746474fb 100644 --- a/include/colonne.php +++ b/include/colonne.php @@ -30,7 +30,7 @@ $fields = $dbo->fetchArray('SELECT *, (SELECT GROUP_CONCAT(zz_groups.nome) FROM foreach ($fields as $field) { echo '
    -
    +
    '.$field['name'].'
    ( '.$field['gruppi_con_accesso'].')
    @@ -76,22 +76,19 @@ echo ' // Ordinamento dinamico delle colonne $(document).ready(function() { - $(".sortable").disableSelection(); - $(".sortable").each(function() { - $(this).sortable({ - cursor: "move", - dropOnEmpty: true, - scroll: true, - update: function(event, ui) { - let order = $(".panel[data-id]").toArray().map(a => $(a).data("id")) + sortable(".sortable", { + axis: "y", + cursor: "move", + dropOnEmpty: true, + scroll: true, + })[0].addEventListener("sortupdate", function(e) { + let order = $(".panel[data-id]").toArray().map(a => $(a).data("id")) + console.log(order); - $.post(globals.rootdir + "/actions.php", { - id: ui.item.data("id"), - id_module: "'.$id_module.'", - op: "ordina_colonne", - order: order.join(","), - }); - } + $.post(globals.rootdir + "/actions.php", { + id_module: globals.id_module, + op: "ordina_colonne", + order: order.join(","), }); }); }); diff --git a/modules/contratti/row-list.php b/modules/contratti/row-list.php index 5f553543b..6b9cac5d9 100755 --- a/modules/contratti/row-list.php +++ b/modules/contratti/row-list.php @@ -299,25 +299,21 @@ function rimuoviRiga(button) { } $(document).ready(function() { - $(".sortable").each(function() { - $(this).sortable({ - axis: "y", - handle: ".handle", - cursor: "move", - dropOnEmpty: true, - scroll: true, - update: function(event, ui) { - let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) + sortable(".sortable", { + axis: "y", + handle: ".handle", + cursor: "move", + dropOnEmpty: true, + scroll: true, + })[0].addEventListener("sortupdate", function(e) { + let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) - $.post(globals.rootdir + "/actions.php", { - id: ui.item.data("id"), - id_module: '.$id_module.', - id_record: '.$id_record.', - op: "update_position", - order: order.join(","), - }); - } - }); - }); + $.post(globals.rootdir + "/actions.php", { + id_module: globals.id_module, + id_record: globals.id_record, + op: "update_position", + order: order.join(","), + }); + }); }); '; diff --git a/modules/ddt/row-list.php b/modules/ddt/row-list.php index c82249e7c..4d09ca89f 100755 --- a/modules/ddt/row-list.php +++ b/modules/ddt/row-list.php @@ -373,25 +373,21 @@ function apriRiferimenti(button) { } $(document).ready(function() { - $(".sortable").each(function() { - $(this).sortable({ - axis: "y", - handle: ".handle", - cursor: "move", - dropOnEmpty: true, - scroll: true, - update: function(event, ui) { - let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) + sortable(".sortable", { + axis: "y", + handle: ".handle", + cursor: "move", + dropOnEmpty: true, + scroll: true, + })[0].addEventListener("sortupdate", function(e) { + let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) - $.post(globals.rootdir + "/actions.php", { - id: ui.item.data("id"), - id_module: '.$id_module.', - id_record: '.$id_record.', - op: "update_position", - order: order.join(","), - }); - } - }); - }); + $.post(globals.rootdir + "/actions.php", { + id_module: globals.id_module, + id_record: globals.id_record, + op: "update_position", + order: order.join(","), + }); + }); }); '; diff --git a/modules/fatture/row-list.php b/modules/fatture/row-list.php index 4ef74526b..8cc19a4dc 100755 --- a/modules/fatture/row-list.php +++ b/modules/fatture/row-list.php @@ -474,25 +474,21 @@ function apriInformazioniFE(button) { } $(document).ready(function() { - $(".sortable").each(function() { - $(this).sortable({ - axis: "y", - handle: ".handle", - cursor: "move", - dropOnEmpty: true, - scroll: true, - update: function(event, ui) { - let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) + sortable(".sortable", { + axis: "y", + handle: ".handle", + cursor: "move", + dropOnEmpty: true, + scroll: true, + })[0].addEventListener("sortupdate", function(e) { + let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) - $.post(globals.rootdir + "/actions.php", { - id: ui.item.data("id"), - id_module: '.$id_module.', - id_record: '.$id_record.', - op: "update_position", - order: order.join(","), - }); - } - }); - }); + $.post(globals.rootdir + "/actions.php", { + id_module: globals.id_module, + id_record: globals.id_record, + op: "update_position", + order: order.join(","), + }); + }); }); '; diff --git a/modules/ordini/row-list.php b/modules/ordini/row-list.php index 14ec21b05..ad4a8434d 100755 --- a/modules/ordini/row-list.php +++ b/modules/ordini/row-list.php @@ -402,25 +402,21 @@ function apriRiferimenti(button) { } $(document).ready(function() { - $(".sortable").each(function() { - $(this).sortable({ - axis: "y", - handle: ".handle", - cursor: "move", - dropOnEmpty: true, - scroll: true, - update: function(event, ui) { - let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) + sortable(".sortable", { + axis: "y", + handle: ".handle", + cursor: "move", + dropOnEmpty: true, + scroll: true, + })[0].addEventListener("sortupdate", function(e) { + let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) - $.post(globals.rootdir + "/actions.php", { - id: ui.item.data("id"), - id_module: '.$id_module.', - id_record: '.$id_record.', - op: "update_position", - order: order.join(","), - }); - } - }); - }); + $.post(globals.rootdir + "/actions.php", { + id_module: globals.id_module, + id_record: globals.id_record, + op: "update_position", + order: order.join(","), + }); + }); }); '; diff --git a/modules/preventivi/row-list.php b/modules/preventivi/row-list.php index 6a847bd71..6eea49daf 100755 --- a/modules/preventivi/row-list.php +++ b/modules/preventivi/row-list.php @@ -366,25 +366,21 @@ function rimuoviRiga(button) { } $(document).ready(function() { - $(".sortable").each(function() { - $(this).sortable({ - axis: "y", - handle: ".handle", - cursor: "move", - dropOnEmpty: true, - scroll: true, - update: function(event, ui) { - let order = $(".table .sortable tr[data-id]").toArray().map(a => $(a).data("id")) + sortable(".sortable", { + axis: "y", + handle: ".handle", + cursor: "move", + dropOnEmpty: true, + scroll: true, + })[0].addEventListener("sortupdate", function(e) { + let order = $(".table tr[data-id]").toArray().map(a => $(a).data("id")) - $.post(globals.rootdir + "/actions.php", { - id: ui.item.data("id"), - id_module: '.$id_module.', - id_record: '.$id_record.', - op: "update_position", - order: order.join(","), - }); - } - }); - }); + $.post(globals.rootdir + "/actions.php", { + id_module: globals.id_module, + id_record: globals.id_record, + op: "update_position", + order: order.join(","), + }); + }); }); '; diff --git a/modules/stato_servizi/actions.php b/modules/stato_servizi/actions.php index 8f207da76..b23573a4d 100755 --- a/modules/stato_servizi/actions.php +++ b/modules/stato_servizi/actions.php @@ -121,38 +121,21 @@ switch (filter('op')) { // Ordinamento moduli di primo livello case 'sort_modules': - $rs = $dbo->fetchArray('SELECT id FROM zz_modules WHERE enabled = 1 AND parent IS NULL ORDER BY `order` ASC'); + $order = explode(',', post('order', true)); - if ($_POST['ids'] != implode(',', array_column($rs, 'id'))) { - $ids = explode(',', $_POST['ids']); - - for ($i = 0; $i < count($ids); ++$i) { - $dbo->query('UPDATE zz_modules SET `order`='.prepare($i).' WHERE id='.prepare($ids[$i])); - } - - flash()->info(tr('Posizione delle voci di menù aggiornata!')); + foreach ($order as $i => $id) { + $dbo->query('UPDATE zz_modules SET `order`='.prepare($i).' WHERE id='.prepare($id)); } break; case 'sort_widgets': - $location = post('location'); - $id_module_widget = post('id_module_widget'); + $order = explode(',', post('order', true)); - $location = empty($id_record) ? 'controller_'.$location : 'editor_'.$location; - - $rs = $dbo->fetchArray("SELECT CONCAT('widget_', id) AS id FROM zz_widgets WHERE enabled = 1 AND location = ".prepare($location).' AND id_module = '.prepare($id_module_widget).' ORDER BY `order` ASC'); - - if ($_POST['ids'] != implode(',', array_column($rs, 'id'))) { - $ids = explode(',', $_POST['ids']); - - for ($i = 0; $i < count($ids); ++$i) { - $id = explode('_', $ids[$i]); - $dbo->query('UPDATE zz_widgets SET `order`='.prepare($i).' WHERE id='.prepare($id[1])); - } - - flash()->info(tr('Posizioni widgets aggiornate!')); + foreach ($order as $i => $id) { + $dbo->query('UPDATE zz_widgets SET `order`='.prepare($i).' WHERE id='.prepare($id)); } + break; case 'sizes': diff --git a/modules/viste/fields.php b/modules/viste/fields.php index dc674c236..cb03faaca 100755 --- a/modules/viste/fields.php +++ b/modules/viste/fields.php @@ -144,7 +144,7 @@ echo ' foreach ($fields as $field) { echo ' -

    +

    '; @@ -243,30 +243,19 @@ echo ' $(document).ready(function() { $("#save-buttons").hide(); - $(".sortable").disableSelection(); - $(".sortable").each(function() { - $(this).sortable({ - axis: "y", - cursor: "move", - dropOnEmpty: true, - scroll: true, - update: function(event, ui) { + sortable(".sortable", { + axis: "y", + cursor: "move", + dropOnEmpty: true, + scroll: true, + })[0].addEventListener("sortupdate", function(e) { + let order = $(".sortable p[data-id]").toArray().map(a => $(a).data("id")) - var order = ""; - $("div.panel-body.sortable p[data-id]").each( function() { - order += ","+$(this).data("id"); - }); - - order = order.replace(/^,/, ""); - - $.post(globals.rootdir + "/actions.php", { - id: ui.item.data("id"), - id_module: '.$id_module.', - id_record: '.$id_record.', - op: "update_position", - order: order, - }); - } + $.post(globals.rootdir + "/actions.php", { + id_module: globals.id_module, + id_record: globals.id_record, + op: "update_position", + order: order.join(","), }); }); }); diff --git a/plugins/checks.php b/plugins/checks.php index 2fe1bee40..9f6635891 100755 --- a/plugins/checks.php +++ b/plugins/checks.php @@ -84,29 +84,25 @@ $(document).ready(function() { id_record: "'.$id_record.'", }, "'.$checks_id.'"); - $(".checklist").sortable({ + sortable(".checklist", { placeholder: "sort-highlight", handle: ".handle", forcePlaceholderSize: true, zIndex: 999999, - update: function(event, ui) { - var order = []; - $(".checklist > li").each( function(){ - order.push($(this).data("id")); - }); + })[0].addEventListener("sortupdate", function(e) { + let order = $(".checklist > li[data-id]").toArray().map(a => $(a).data("id")) - $.post(globals.rootdir + "/actions.php", { - id_module: "'.$id_module.'", - id_plugin: "'.$id_plugin.'", - id_record: "'.$id_record.'", + $.post(globals.rootdir + "/actions.php", { + id_module: globals.id_module, + id_plugin: "'.$id_plugin.'", + id_record: globals.id_record, op: "ordina-checks", - order: order.join(","), - }); - } + order: order.join(","), + }); }); $(".checklist").todoList({ - onCheck : function () { + onCheck: function () { var id = $(this).parent().data("id"); checklists["'.$checks_id.'"].toggleCheck(id); diff --git a/src/HTMLBuilder/Manager/WidgetManager.php b/src/HTMLBuilder/Manager/WidgetManager.php index 34f9532a2..ad9597861 100755 --- a/src/HTMLBuilder/Manager/WidgetManager.php +++ b/src/HTMLBuilder/Manager/WidgetManager.php @@ -258,7 +258,7 @@ class WidgetManager implements ManagerInterface // Aggiungo ad uno ad uno tutti i widget foreach ($widgets as $widget) { $result .= ' -

  • '; +
  • '; $info = array_merge($options, [ 'id' => $widget['id'], diff --git a/src/Modules.php b/src/Modules.php index 0452aca20..f411b85c9 100755 --- a/src/Modules.php +++ b/src/Modules.php @@ -357,7 +357,7 @@ class Modules if ($active) { $result .= ' active actual'; } - $result .= '" id="'.$element['id'].'"> + $result .= '" id="'.$element['id'].'" data-id="'.$element['id'].'"> '.$title.''; From 17f07eec0d95754ddb7745877a51d2400f863c4a Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Wed, 21 Jul 2021 11:43:48 +0200 Subject: [PATCH 3/6] Miglioramenti minori --- assets/src/js/functions/functions.js | 10 ++++++++-- modules/anagrafiche/src/Anagrafica.php | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/assets/src/js/functions/functions.js b/assets/src/js/functions/functions.js index b0fff95b5..e77147816 100755 --- a/assets/src/js/functions/functions.js +++ b/assets/src/js/functions/functions.js @@ -52,7 +52,11 @@ function openModal(title, href) { } }); - var content = '