var isMobile = { Android: function () { return navigator.userAgent.match(/Android/i); }, BlackBerry: function () { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function () { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function () { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function () { return navigator.userAgent.match(/IEMobile/i); }, any: function () { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } }; // 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(); }); $(document).ready(function () { // 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'); // Orologio clock(); // Pulsante per il ritorno a inizio pagina backToTop(); // Richiamo alla generazione di Datatables start_datatables(); // Calendario principale ranges = {}; ranges[globals.translations.today] = [moment(), moment()]; ranges[globals.translations.yesterday] = [moment().subtract(1, 'days'), moment().subtract(1, 'days')]; ranges[globals.translations.last7Days] = [moment().subtract(6, 'days'), moment()]; ranges[globals.translations.last30Days] = [moment().subtract(29, 'days'), moment()]; 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')]; // Calendario principale $('#daterange').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, endDate: globals.end_date, applyClass: 'btn btn-success btn-sm', cancelClass: 'btn btn-danger btn-sm', linkedCalendars: false }, 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 () { location.href = location.href; }); } ); $(document).on('click', '.ask', function () { message(this); }); // Pulsanti di Datatables $(".btn-csv").click(function (e) { var table = $(document).find("#" + $(this).parent().parent().parent().data("target")).DataTable(); table.buttons(0).trigger(); }); $(".btn-copy").click(function (e) { var table = $(document).find("#" + $(this).parent().parent().parent().data("target")).DataTable(); table.buttons(1).trigger(); }); $(".btn-print").click(function (e) { var table = $(document).find("#" + $(this).parent().parent().parent().data("target")).DataTable(); table.buttons(2).trigger(); }); $(".btn-select-all").click(function () { var table = $(document).find("#" + $(this).parent().parent().parent().data("target")).DataTable(); $("#main_loading").show(); table.clear().draw(); table.page.len(-1).draw(); }); $(".btn-select-none").click(function () { var table = $(document).find("#" + $(this).parent().parent().parent().data("target")).DataTable(); table.rows().deselect(); table.page.len(200); }); $(".bulk-action").click(function () { var table = $(document).find("#" + $(this).parent().parent().parent().parent().data("target")); $(this).attr("data-id_records", table.data('selected')); if (table.data('selected')) { message(this); } else { swal(globals.translations.waiting, globals.translations.waiting_msg, "error"); } }); // Sidebar $('.sidebar-menu > li.treeview i.fa-angle-left').click(function (e) { e.preventDefault(); $(this).find('ul').stop().slideDown(); }); $('.sidebar-menu > li.treeview i.fa-angle-down').click(function (e) { e.preventDefault(); $(this).find('ul').stop().slideUp(); }); $menulist = $('.treeview-menu > li.active'); for (i = 0; i < $menulist.length; i++) { $list = $($menulist[i]); $list.parent().show().parent().addClass('active'); $list.parent().parent().find('i.fa-angle-left').removeClass('fa-angle-left').addClass('fa-angle-down'); } // Menu ordinabile $(".sidebar-menu").sortable({ cursor: 'move', stop: function (event, ui) { var order = $(this).sortable('toArray').toString(); $.post(globals.rootdir + "/modules/aggiornamenti/actions.php?id_module=" + globals.aggiornamenti_id, { op: 'sortmodules', ids: order }); } }); // Tabs $('#tabs').tabs(); // Entra nel tab indicato al caricamento della pagina var hash = window.location.hash ? window.location.hash : getUrlVars().hash; if (hash && hash != '#tab_0') { $('ul.nav a[href="' + hash + '"]').tab('show'); $($.fn.dataTable.tables(true)).DataTable().columns.adjust(); $($.fn.dataTable.tables(true)).DataTable().scroller.measure(); } $('.nav-tabs a').click(function (e) { $(this).tab('show'); var scrollmem = $('body').scrollTop() || $('html').scrollTop(); window.location.hash = this.hash; $('html,body').scrollTop(scrollmem); }); // Fix per la visualizzazione di Datatables all'interno dei tab Bootstrap $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { $($.fn.dataTable.tables(true)).DataTable().columns.adjust(); $($.fn.dataTable.tables(true)).DataTable().scroller.measure(); }); // Aggiunta nell'URL del nome tab su cui tornare dopo il submit $(document).on('submit', 'form', function () { $(this).find('input:disabled, select:disabled').prop('disabled', false); var hash = window.location.hash; if (hash) { var input = $('', { type: 'hidden', name: 'hash', value: hash, }); $(this).append(input); } }); // 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, 'top': -100, 'right': 10, 'opacity': 1 }).delay(1000).animate({ 'top': tops, 'opacity': 1 }).delay(3000).animate({ 'top': -100, 'opacity': 0 }); }); } // Nascondo la notifica se passo sopra col mouse $('.alert-success.push').on('mouseover', function () { $(this).stop().animate({ 'top': -100, 'opacity': 0 }); }); $('.widget').mouseover(function (e) { e.preventDefault(); start_widgets($("#widget-controller_top, #widget-controller_right")); }); $('#supersearch').keyup(function () { $(document).ajaxStop(); if ($(this).val() == '') { $(this).removeClass('wait'); } else { $(this).addClass('wait'); } }); $.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 = ""; 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_autocomplete.php?op=supersearch&module=*', dataType: "json", data: { term: request.term }, 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('
    ,', '
    '); return { label: labels, category: item.category, link: item.link, value: item.title } })); } } }); } }); }); // Widgets ordinabili function start_widgets($widgets) { cls = new Array(); for (i = 0; i < $widgets.length; i++) { $widget = $($widgets[i]); list_name = ($widget.attr('id')).replace('widget-', ''); // Salvo le classi del primo elemento di ogni lista cls[list_name] = $widget.find('li:first').attr('class'); $widget.sortable({ items: 'li', cursor: 'move', dropOnEmpty: true, connectWith: '.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) { // 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-', ''); var new_class = ""; var order = $(this).sortable('toArray').toString(); $.post(globals.rootdir + "/modules/aggiornamenti/actions.php?id_module=" + globals.aggiornamenti_id, { op: 'updatewidget', location: dst_list, id_module: globals.id_module, class: new_class, id: ui.item.attr('id') }); $.post(globals.rootdir + "/modules/aggiornamenti/actions.php?id_module=" + globals.aggiornamenti_id, { op: 'sortwidget', location: dst_list, ids: order, id_module: globals.id_module, class: new_class }); } }); } } // Modal function launch_modal(title, href, init_modal, id) { if (id == null) { id = '#bs-popup'; } if (init_modal == null) { init_modal = 1; } $('html').addClass('modal-open'); $(id).on('hidden.bs.modal', function () { $('html').removeClass('modal-open'); $(this).html(''); $(this).data('modal', null); }); // Lettura contenuto div if (href.substr(0, 1) == '#') { data = $(href).html(); $(id).html( '