2017-08-04 16:28:16 +02:00
|
|
|
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 () {
|
2017-09-01 18:13:25 +02:00
|
|
|
return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) ||
|
|
|
|
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0, 4)));
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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');
|
|
|
|
|
2017-09-19 16:50:01 +02:00
|
|
|
// 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));
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Orologio
|
|
|
|
clock();
|
|
|
|
|
|
|
|
// Richiamo alla generazione di Datatables
|
|
|
|
start_datatables();
|
|
|
|
|
|
|
|
// Calendario principale
|
|
|
|
ranges = {};
|
|
|
|
ranges[globals.translations.today] = [moment(), moment()];
|
2017-09-14 16:20:11 +02:00
|
|
|
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')];
|
2017-08-04 16:28:16 +02:00
|
|
|
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
|
2017-09-19 16:50:01 +02:00
|
|
|
$.get(globals.rootdir + '/core.php?period_start=' + start.format('YYYY-MM-DD') + '&period_end=' + end.format('YYYY-MM-DD'), function (data) {
|
2017-09-15 17:00:33 +02:00
|
|
|
location.reload();
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-09-12 16:17:11 +02:00
|
|
|
// Messaggi automatici di eliminazione
|
2017-08-04 16:28:16 +02:00
|
|
|
$(document).on('click', '.ask', function () {
|
|
|
|
message(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Pulsanti di Datatables
|
|
|
|
$(".btn-csv").click(function (e) {
|
2018-07-02 16:56:00 +02:00
|
|
|
var table = $(document).find("#" + $(this).closest("[data-target]").data("target")).DataTable();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
table.buttons(0).trigger();
|
|
|
|
});
|
|
|
|
|
2018-07-02 16:56:00 +02:00
|
|
|
$(".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();
|
|
|
|
});
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
$(".btn-copy").click(function (e) {
|
2018-07-02 16:56:00 +02:00
|
|
|
var table = $(document).find("#" + $(this).closest("[data-target]").data("target")).DataTable();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
table.buttons(1).trigger();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".btn-print").click(function (e) {
|
2018-07-02 16:56:00 +02:00
|
|
|
var table = $(document).find("#" + $(this).closest("[data-target]").data("target")).DataTable();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
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"));
|
|
|
|
|
|
|
|
if (table.data('selected')) {
|
2017-09-13 17:56:49 +02:00
|
|
|
$(this).attr("data-id_records", table.data('selected'));
|
|
|
|
$(this).data("id_records", table.data('selected'));
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
message(this);
|
2017-09-13 17:56:49 +02:00
|
|
|
|
|
|
|
$(this).attr("data-id_records", "");
|
|
|
|
$(this).data("id_records", "");
|
2017-08-04 16:28:16 +02:00
|
|
|
} 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();
|
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
$.post(globals.rootdir + "/actions.php?id_module=" + globals.aggiornamenti_id, {
|
2017-08-04 16:28:16 +02:00
|
|
|
op: 'sortmodules',
|
|
|
|
ids: order
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-04 10:24:44 +02:00
|
|
|
if (isMobile.any()) {
|
2017-09-01 18:13:25 +02:00
|
|
|
$(".sidebar-menu").sortable("disable");
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Tabs
|
2017-10-08 18:28:26 +02:00
|
|
|
$('.nav-tabs').tabs();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Entra nel tab indicato al caricamento della pagina
|
|
|
|
var hash = window.location.hash ? window.location.hash : getUrlVars().hash;
|
|
|
|
if (hash && hash != '#tab_0') {
|
2017-10-08 18:28:26 +02:00
|
|
|
$('ul.nav-tabs a[href="' + hash + '"]').tab('show');
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-01 18:13:25 +02:00
|
|
|
// Nel caso la navigazione sia da mobile, disabilito il ritorno al punto precedente
|
2017-09-04 10:24:44 +02:00
|
|
|
if (!isMobile.any()) {
|
2017-09-01 18:13:25 +02:00
|
|
|
// Salvo lo scroll per riportare qui l'utente al reload
|
|
|
|
$(window).on('scroll', function () {
|
2018-01-12 17:56:06 +01:00
|
|
|
if (sessionStorage != undefined) {
|
|
|
|
sessionStorage.setItem('scrollTop_' + globals.id_module + '_' + globals.id_record, $(document).scrollTop());
|
2017-09-01 18:13:25 +02:00
|
|
|
}
|
|
|
|
});
|
2017-08-31 16:23:26 +02:00
|
|
|
|
2017-09-01 18:13:25 +02:00
|
|
|
// Riporto l'utente allo scroll precedente
|
2018-01-12 17:56:06 +01:00
|
|
|
if (sessionStorage['scrollTop_' + globals.id_module + '_' + globals.id_record] != undefined) {
|
2017-09-01 18:13:25 +02:00
|
|
|
setTimeout(function () {
|
2018-01-12 17:56:06 +01:00
|
|
|
scrollToAndFocus(sessionStorage['scrollTop_' + globals.id_module + '_' + globals.id_record]);
|
2017-09-01 18:13:25 +02:00
|
|
|
}, 1);
|
|
|
|
}
|
2017-08-31 16:23:26 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
$('.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();
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2017-08-30 14:43:38 +02:00
|
|
|
$(this).css({
|
|
|
|
'position': 'fixed',
|
|
|
|
'z-index': 3,
|
|
|
|
'right': '10px',
|
|
|
|
'top': -100,
|
|
|
|
}).delay(1000).animate({
|
2017-08-04 16:28:16 +02:00
|
|
|
'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
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.widget').mouseover(function (e) {
|
|
|
|
e.preventDefault();
|
2018-02-22 12:35:22 +01:00
|
|
|
start_widgets($("#widget-top, #widget-right"));
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#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("<li class='ui-autocomplete-category'>" + item.category + "</li>");
|
|
|
|
currentCategory = item.category;
|
|
|
|
}
|
|
|
|
|
|
|
|
that._renderItemData(ul, item);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_renderItem: function (ul, item) {
|
|
|
|
return $("<li>")
|
|
|
|
.append("<a href='" + item.link + "' title='Clicca per aprire'><b>" + item.value + "</b><br/>" + item.label + "</a>")
|
|
|
|
.appendTo(ul);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Configurazione supersearch
|
|
|
|
var $super = $('#supersearch').supersearch({
|
|
|
|
minLength: 3,
|
|
|
|
select: function (event, ui) {
|
|
|
|
location.href = ui.item.link;
|
|
|
|
},
|
|
|
|
source: function (request, response) {
|
|
|
|
$.ajax({
|
2018-02-03 16:29:53 +01:00
|
|
|
url: globals.rootdir + '/ajax_search.php',
|
2017-08-04 16:28:16 +02:00
|
|
|
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('<br/>,', '<br/>');
|
|
|
|
|
|
|
|
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();
|
2018-09-19 10:44:32 +02:00
|
|
|
$.post(globals.rootdir + "/actions.php?id_module=" + globals.aggiornamenti_id, {
|
2017-08-04 16:28:16 +02:00
|
|
|
op: 'updatewidget',
|
|
|
|
location: dst_list,
|
|
|
|
id_module: globals.id_module,
|
2018-03-24 00:19:15 +01:00
|
|
|
id_record: globals.id_record,
|
2017-08-04 16:28:16 +02:00
|
|
|
class: new_class,
|
|
|
|
id: ui.item.attr('id')
|
|
|
|
});
|
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
$.post(globals.rootdir + "/actions.php?id_module=" + globals.aggiornamenti_id, {
|
2017-08-04 16:28:16 +02:00
|
|
|
op: 'sortwidget',
|
|
|
|
location: dst_list,
|
|
|
|
ids: order,
|
|
|
|
id_module: globals.id_module,
|
2018-03-24 00:19:15 +01:00
|
|
|
id_record: globals.id_record,
|
2017-08-04 16:28:16 +02:00
|
|
|
class: new_class
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Modal
|
|
|
|
function launch_modal(title, href, init_modal, id) {
|
2018-08-31 11:39:38 +02:00
|
|
|
// Fix - Select2 does not function properly when I use it inside a Bootstrap modal.
|
2018-07-23 11:09:50 +02:00
|
|
|
$.fn.modal.Constructor.prototype.enforceFocus = function () {};
|
2017-12-16 15:49:29 +01:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
if (id == null) {
|
|
|
|
id = '#bs-popup';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (init_modal == null) {
|
|
|
|
init_modal = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(id).on('hidden.bs.modal', function () {
|
2018-07-23 11:09:50 +02:00
|
|
|
if ($('.modal-backdrop').length < 1) {
|
2017-12-15 09:40:21 +01:00
|
|
|
$(this).html('');
|
|
|
|
$(this).data('modal', null);
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Lettura contenuto div
|
|
|
|
if (href.substr(0, 1) == '#') {
|
|
|
|
data = $(href).html();
|
|
|
|
|
|
|
|
$(id).html(
|
|
|
|
'<div class="modal-dialog modal-lg">' +
|
|
|
|
' <div class="modal-content">' +
|
|
|
|
' <div class="modal-header">' +
|
|
|
|
' <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">' + globals.translations.close + '</span></button>' +
|
|
|
|
' <h4 class="modal-title">' + title + '</h4>' +
|
|
|
|
' </div>' +
|
|
|
|
' <div class="modal-body">' + data + '</div>'
|
|
|
|
);
|
|
|
|
if (init_modal == 1) {
|
|
|
|
$(id).modal('show');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$.get(href, function (data, response) {
|
|
|
|
if (response == 'success') {
|
|
|
|
$(id).html(
|
|
|
|
'<div class="modal-dialog modal-lg">' +
|
|
|
|
' <div class="modal-content">' +
|
|
|
|
' <div class="modal-header">' +
|
|
|
|
' <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">' + globals.translations.close + '</span></button>' +
|
|
|
|
' <h4 class="modal-title">' + title + '</h4>' +
|
|
|
|
' </div>' +
|
|
|
|
' <div class="modal-body">' + data + '</div>'
|
|
|
|
);
|
|
|
|
if (init_modal == 1) {
|
|
|
|
$(id).modal('show');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Datatable
|
|
|
|
function start_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,
|
2017-08-28 12:16:14 +02:00
|
|
|
order: [],
|
2017-08-04 16:28:16 +02:00
|
|
|
lengthChange: false,
|
2017-09-11 18:24:15 +02:00
|
|
|
scrollY: "70vh",
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.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];
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-09-01 12:55:48 +02:00
|
|
|
// Fix per l'URL encoding
|
|
|
|
search.forEach(function (value, index, array) {
|
|
|
|
search[array[index]] = decodeURIComponent(array[value]);
|
|
|
|
})
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
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;
|
2018-06-29 10:20:13 +02:00
|
|
|
var tempo;
|
2018-07-23 11:09:50 +02:00
|
|
|
var tempo_attesa_ricerche = (globals.tempo_attesa_ricerche * 1000);
|
2018-06-29 15:48:57 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
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,
|
2017-09-01 12:55:48 +02:00
|
|
|
stateSave: true,
|
2017-09-01 18:13:25 +02:00
|
|
|
stateSaveCallback: function (settings, data) {
|
2018-01-12 17:56:06 +01:00
|
|
|
sessionStorage.setItem('DataTables_' + id_module + '-' + id_plugin + '-' + id_parent, JSON.stringify(data));
|
2017-09-01 18:13:25 +02:00
|
|
|
},
|
|
|
|
stateLoadCallback: function (settings) {
|
2018-01-12 17:56:06 +01:00
|
|
|
return JSON.parse(sessionStorage.getItem('DataTables_' + id_module + '-' + id_plugin + '-' + id_parent));
|
2017-09-01 18:13:25 +02:00
|
|
|
},
|
2017-08-04 16:28:16 +02:00
|
|
|
columnDefs: [{
|
|
|
|
searchable: false,
|
|
|
|
orderable: false,
|
|
|
|
width: '1%',
|
|
|
|
className: 'select-checkbox',
|
|
|
|
targets: 0
|
|
|
|
}],
|
|
|
|
select: {
|
|
|
|
style: 'multi',
|
|
|
|
selector: 'td:first-child'
|
|
|
|
},
|
2018-07-23 11:09:50 +02:00
|
|
|
buttons: [{
|
2017-08-04 16:28:16 +02:00
|
|
|
extend: 'csv',
|
|
|
|
fieldSeparator: ";",
|
|
|
|
exportOptions: {
|
|
|
|
modifier: {
|
|
|
|
selected: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
extend: 'copy',
|
|
|
|
exportOptions: {
|
|
|
|
modifier: {
|
|
|
|
selected: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
extend: 'print',
|
2018-07-23 11:09:50 +02:00
|
|
|
autoPrint: true,
|
|
|
|
customize: function (win) {
|
|
|
|
$(win.document.body)
|
|
|
|
.css('font-size', '10pt')
|
|
|
|
.append(
|
2018-09-27 10:15:04 +02:00
|
|
|
'<table class="main-records table table-condensed table-bordered dataTable"><tfoot><tr><td></td><td class="pull-right">' + $('#summable').text() + '</td><td></td></tr></tfoot></table>'
|
2018-07-23 11:09:50 +02:00
|
|
|
);
|
|
|
|
$(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');
|
|
|
|
},
|
2017-08-04 16:28:16 +02:00
|
|
|
exportOptions: {
|
|
|
|
modifier: {
|
|
|
|
selected: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-07-02 16:56:00 +02:00
|
|
|
{
|
|
|
|
extend: 'excel',
|
|
|
|
exportOptions: {
|
|
|
|
modifier: {
|
|
|
|
selected: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
extend: 'pdf',
|
|
|
|
exportOptions: {
|
|
|
|
modifier: {
|
|
|
|
selected: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-08-04 16:28:16 +02:00
|
|
|
],
|
|
|
|
scroller: {
|
|
|
|
loadingIndicator: true
|
|
|
|
},
|
|
|
|
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 () {
|
|
|
|
var api = this.api();
|
|
|
|
api.columns('.search').every(function () {
|
|
|
|
var column = this;
|
|
|
|
$('<br><input type="text" style="width:100%" class="form-control" placeholder="' + globals.translations.filter + '..."><i class="deleteicon fa fa-times fa-2x hide"></i>')
|
|
|
|
.appendTo(column.header())
|
|
|
|
.on('keyup', function (e) {
|
2018-06-29 15:48:57 +02:00
|
|
|
|
2018-06-29 10:20:13 +02:00
|
|
|
clearInterval(tempo);
|
2018-06-29 15:48:57 +02:00
|
|
|
|
2018-09-27 10:15:04 +02:00
|
|
|
// Fix del pulsante di pulizia ricerca e del messaggio sulla ricerca lenta
|
2017-08-04 16:28:16 +02:00
|
|
|
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('<span class="text-danger" id="slow"><i class="fa fa-refresh fa-spin"></i> ' + globals.translations.long + '</span>');
|
|
|
|
}
|
|
|
|
$(this).addClass('input-searching');
|
|
|
|
$(this).next('.deleteicon').removeClass('hide');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 10:15:04 +02:00
|
|
|
function start_search(module_id, field, search_value) {
|
|
|
|
searchTable(module_id, field, search_value);
|
2018-06-29 10:20:13 +02:00
|
|
|
column.search(search_value).draw();
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-09-27 10:15:04 +02:00
|
|
|
// 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();
|
2018-07-23 11:09:50 +02:00
|
|
|
if (e.keyCode == 13 || $(this).val() == '') {
|
2018-09-27 10:15:04 +02:00
|
|
|
start_search(module_id, field, value);
|
2018-07-23 11:09:50 +02:00
|
|
|
} else {
|
2018-09-27 10:15:04 +02:00
|
|
|
tempo = window.setTimeout(start_search, tempo_attesa_ricerche, module_id, field, value);
|
2018-06-29 10:20:13 +02:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
});
|
2018-06-29 15:48:57 +02:00
|
|
|
|
2018-06-29 10:20:13 +02:00
|
|
|
// Disabilito l'ordinamento alla pressione del tasto invio sull'<input>
|
|
|
|
$("thead input, .search").on('keypress', function (e) {
|
|
|
|
stopTableSorting(e);
|
|
|
|
});
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Disabilito l'ordinamento al click sull'<input>
|
|
|
|
$("thead input, .deleteicon").click(function (e) {
|
|
|
|
stopTableSorting(e);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.deleteicon').on("click", function (e) {
|
|
|
|
reset($(this).parent().attr("id").replace("th_", ""));
|
|
|
|
api.page.len(200).draw();
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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) {
|
2017-09-13 18:47:42 +02:00
|
|
|
if ($(data[0]).data('id') && $.inArray($(data[0]).data('id'), $this.data('selected').split(';')) !== -1) {
|
2017-08-04 16:28:16 +02:00
|
|
|
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) {
|
2018-07-02 16:56:00 +02:00
|
|
|
container.find('.table-btn').removeClass('disabled').attr('disabled', false);
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
2018-07-02 16:56:00 +02:00
|
|
|
container.find('.table-btn').addClass('disabled').attr('disabled', true);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2018-04-20 15:50:57 +02:00
|
|
|
var i = -1;
|
2017-08-04 16:28:16 +02:00
|
|
|
this.api().columns().every(function () {
|
|
|
|
if (sum.summable[i] != undefined) {
|
|
|
|
$(this.footer()).addClass("text-right");
|
2018-07-23 11:09:50 +02:00
|
|
|
$(this.footer()).attr("id", "summable");
|
2017-08-04 16:28:16 +02:00
|
|
|
$(this.footer()).html(sum.summable[i]);
|
|
|
|
} else $(this.footer()).html(" ");
|
|
|
|
i++;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
table.on('select deselect', function (e, dt, type, indexes) {
|
|
|
|
if (type === 'row') {
|
2017-09-13 18:47:42 +02:00
|
|
|
var selected = $this.data('selected').split(';');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-06-29 15:48:57 +02:00
|
|
|
selected = selected.filter(function (value, index, self) {
|
|
|
|
return value != '' && self.indexOf(value) === index;
|
|
|
|
})
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
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) {
|
2017-09-07 18:58:41 +02:00
|
|
|
delete selected[index];
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-29 15:48:57 +02:00
|
|
|
selected = selected.filter(function (value, index, self) {
|
|
|
|
return value != '' && self.indexOf(value) === index;
|
|
|
|
})
|
2017-09-07 18:58:41 +02:00
|
|
|
|
2017-09-13 18:47:42 +02:00
|
|
|
$this.data('selected', selected.join(';'));
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
var container = $(document).find('[data-target=' + $this.attr('id') + ']');
|
|
|
|
|
2017-09-07 18:58:41 +02:00
|
|
|
if (selected.length > 0) {
|
2017-08-04 16:28:16 +02:00
|
|
|
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) {
|
2018-07-02 16:56:00 +02:00
|
|
|
container.find('.table-btn').removeClass('disabled').attr('disabled', false);
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
2018-07-02 16:56:00 +02:00
|
|
|
container.find('.table-btn').addClass('disabled').attr('disabled', true);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
table.on('processing.dt', function (e, settings, processing) {
|
|
|
|
if (processing) {
|
|
|
|
$('#mini-loader').show();
|
|
|
|
} else {
|
|
|
|
$('#mini-loader').hide();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopTableSorting(e) {
|
|
|
|
if (!e) var e = window.event
|
|
|
|
e.cancelBubble = true;
|
|
|
|
if (e.stopPropagation) e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset(type) {
|
|
|
|
if (type == null) $('[id^=th_] input').val('').trigger('keyup');
|
|
|
|
else $('[id^=th_' + type + '] input').val('').trigger('keyup');
|
|
|
|
}
|
|
|
|
|
|
|
|
function openLink(event, link) {
|
|
|
|
if (event.ctrlKey) {
|
|
|
|
window.open(link);
|
|
|
|
} else {
|
|
|
|
location.href = link;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select
|
|
|
|
function start_superselect() {
|
|
|
|
// Statico
|
|
|
|
$('.superselect').each(function () {
|
|
|
|
$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') ? false : true,
|
|
|
|
templateResult: function (data, container) {
|
|
|
|
var bg; // templateSelection
|
|
|
|
|
|
|
|
if (data._bgcolor_) {
|
|
|
|
bg = data._bgcolor_;
|
|
|
|
} else if ($(data.element).attr("_bgcolor_")) {
|
|
|
|
bg = $(data.element).attr("_bgcolor_");
|
|
|
|
} else if ($(data.element).data("_bgcolor_")) {
|
|
|
|
bg = $(data.element).data("_bgcolor_");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bg) {
|
|
|
|
$(container).css("background-color", bg);
|
|
|
|
$(container).css("color", setContrast(bg));
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.text;
|
|
|
|
},
|
|
|
|
escapeMarkup: function (text) {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Dinamico (AJAX, per tabelle con molti record)
|
|
|
|
$('.superselectajax').each(function () {
|
|
|
|
$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: function (data, container) {
|
|
|
|
var bg; // templateSelection
|
|
|
|
|
|
|
|
if (data._bgcolor_) {
|
|
|
|
bg = data._bgcolor_;
|
|
|
|
} else if ($(data.element).attr("_bgcolor_")) {
|
|
|
|
bg = $(data.element).attr("_bgcolor_");
|
|
|
|
} else if ($(data.element).data("_bgcolor_")) {
|
|
|
|
bg = $(data.element).data("_bgcolor_");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bg && !$("head").find('#' + data._resultId + '_style').length) {
|
|
|
|
$(container).css("background-color", bg);
|
|
|
|
$(container).css("color", setContrast(bg));
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.text;
|
|
|
|
},
|
|
|
|
ajax: {
|
|
|
|
url: globals.rootdir + "/ajax_select.php?op=" + $this.data('source'),
|
|
|
|
dataType: 'json',
|
|
|
|
delay: 250,
|
|
|
|
data: function (params) {
|
|
|
|
return {
|
|
|
|
q: params.term // search term
|
|
|
|
}
|
|
|
|
},
|
|
|
|
processResults: function (data) {
|
|
|
|
return {
|
|
|
|
results: data
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cache: false
|
|
|
|
},
|
|
|
|
width: '100%'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-05 17:31:58 +02:00
|
|
|
/**
|
|
|
|
* Reimposta i contenuti di un <select> creato con select2.
|
|
|
|
*/
|
|
|
|
jQuery.fn.selectClear = function () {
|
|
|
|
this.val([]).trigger("change");
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
/**
|
|
|
|
* Resetta i contenuti di un <select> creato con select2.
|
|
|
|
*/
|
|
|
|
jQuery.fn.selectReset = function () {
|
2017-09-05 17:31:58 +02:00
|
|
|
this.selectClear();
|
2017-08-04 16:28:16 +02:00
|
|
|
this.empty();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-12-16 15:49:29 +01:00
|
|
|
* Aggiorna un <select> creato con select2 impostando un valore di default.
|
|
|
|
* Da utilizzare per l'impostazione dei select basati su richieste AJAX.
|
2017-08-04 16:28:16 +02:00
|
|
|
*/
|
|
|
|
jQuery.fn.selectSetNew = function (value, label) {
|
|
|
|
this.selectReset();
|
|
|
|
|
|
|
|
this.selectAdd([{
|
|
|
|
'value': value,
|
|
|
|
'text': label,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
this.selectSet(value);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-12-16 15:49:29 +01:00
|
|
|
* Aggiorna un <select> creato con select2 impostando un valore di default.
|
|
|
|
* Da utilizzare per l'impostazione dei select statici.
|
2017-08-04 16:28:16 +02:00
|
|
|
*/
|
|
|
|
jQuery.fn.selectSet = function (value) {
|
|
|
|
this.val(value).trigger("change");
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Aggiorna un <select> creato con select2 impostando un valore di default
|
|
|
|
*/
|
|
|
|
jQuery.fn.selectAdd = function (values) {
|
|
|
|
$this = this;
|
|
|
|
|
|
|
|
values.forEach(function (item, index, array) {
|
|
|
|
var option = $('<option/>', item);
|
|
|
|
|
|
|
|
$this.append(option);
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restituisce l'oggetto contenente gli attributi di una <option> generata da select2.
|
|
|
|
*/
|
|
|
|
jQuery.fn.selectData = function () {
|
|
|
|
var obj = $(this[0]);
|
|
|
|
|
|
|
|
$select_obj = obj.select2('data');
|
|
|
|
|
|
|
|
if ($select_obj[0] == undefined) {
|
|
|
|
return undefined;
|
|
|
|
} else {
|
|
|
|
if ($select_obj[0].selected == false) {
|
|
|
|
return $select_obj[0];
|
|
|
|
} else {
|
|
|
|
return $select_obj[0].element.dataset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Inputmask
|
2018-01-25 17:08:10 +01:00
|
|
|
function start_inputmask(element) {
|
2018-07-23 11:09:50 +02:00
|
|
|
if (element == undefined) {
|
2018-01-25 17:08:10 +01:00
|
|
|
element = '';
|
|
|
|
} else {
|
|
|
|
element = element + ' ';
|
|
|
|
}
|
|
|
|
|
2017-09-01 18:13:25 +02:00
|
|
|
var date = moment.localeData().longDateFormat('L').toLowerCase();
|
2018-01-25 17:08:10 +01:00
|
|
|
|
2018-07-23 11:09:50 +02:00
|
|
|
$(element + ".date-mask").inputmask(date, {
|
2017-09-01 18:13:25 +02:00
|
|
|
"placeholder": date
|
|
|
|
});
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-07-23 11:09:50 +02:00
|
|
|
$(element + '.email-mask').inputmask('Regex', {
|
2017-08-04 16:28:16 +02:00
|
|
|
regex: "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$",
|
|
|
|
});
|
2018-02-22 12:35:22 +01:00
|
|
|
|
2018-07-23 11:09:50 +02:00
|
|
|
$(element + '.alphanumeric-mask').inputmask('Regex', {
|
2018-06-14 15:47:59 +02:00
|
|
|
regex: "[A-Za-z0-9#_|\/\\-.]*",
|
2018-02-16 13:16:17 +01:00
|
|
|
});
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-04 10:24:44 +02:00
|
|
|
if (isMobile.any()) {
|
2018-07-23 11:09:50 +02:00
|
|
|
$(element + '.inputmask-decimal, ' + element + '.date-mask, ' + element + '.timestamp-mask').each(function () {
|
2017-09-01 18:13:25 +02:00
|
|
|
$(this).attr('type', 'tel');
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
} else {
|
2018-07-23 11:09:50 +02:00
|
|
|
$(element + '.inputmask-decimal').each(function () {
|
2017-08-04 16:28:16 +02:00
|
|
|
var $this = $(this);
|
2017-09-05 18:20:02 +02:00
|
|
|
|
|
|
|
var min = $this.attr('min-value');
|
|
|
|
if (min == 'undefined') {
|
|
|
|
min = false;
|
|
|
|
}
|
2018-06-29 15:48:57 +02:00
|
|
|
|
2018-07-23 11:09:50 +02:00
|
|
|
var max = $this.attr('max-value');
|
2018-03-02 17:19:15 +01:00
|
|
|
if (max == 'undefined') {
|
|
|
|
max = false;
|
|
|
|
}
|
2017-09-05 18:20:02 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
$this.inputmask("decimal", {
|
2017-09-05 18:20:02 +02:00
|
|
|
min: min ? min : undefined,
|
|
|
|
allowMinus: !min || min < 0 ? true : false,
|
2018-07-23 11:09:50 +02:00
|
|
|
max: max ? max : undefined,
|
|
|
|
allowPlus: !max || max < 0 ? true : false,
|
2017-08-04 16:28:16 +02:00
|
|
|
digits: $this.attr('decimals') ? $this.attr('decimals') : globals.cifre_decimali,
|
2017-08-12 11:41:16 +02:00
|
|
|
digitsOptional: true, // Necessario per un problema di inputmask con i numeri negativi durante l'init
|
2017-08-04 16:28:16 +02:00
|
|
|
enforceDigitsOnBlur: true,
|
|
|
|
rightAlign: true,
|
|
|
|
autoGroup: true,
|
|
|
|
radixPoint: globals.decimals,
|
|
|
|
groupSeparator: globals.thousands,
|
2017-08-11 12:11:57 +02:00
|
|
|
onUnMask: function (maskedValue, unmaskedValue) {
|
|
|
|
return maskedValue.toEnglish();
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$this.on('keyup', function () {
|
2017-09-05 18:20:02 +02:00
|
|
|
if (min && $(this).val().toEnglish() < min) {
|
|
|
|
$(this).val(min);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-31 16:23:26 +02:00
|
|
|
/**
|
|
|
|
* Funzione per far scrollare la pagina fino a un id + focus e offset
|
|
|
|
* @param integer offset
|
|
|
|
* @param string id
|
|
|
|
*/
|
|
|
|
function scrollToAndFocus(offset, id) {
|
|
|
|
if (id) {
|
|
|
|
offset += $('#' + id).offset().top;
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
$('html,body').animate({
|
2017-08-31 16:23:26 +02:00
|
|
|
scrollTop: offset
|
|
|
|
}, 'slow');
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ritorna un array associativo con i parametri passati via GET
|
|
|
|
*/
|
|
|
|
function getUrlVars(url) {
|
|
|
|
var vars = [],
|
|
|
|
hash;
|
|
|
|
if (url == null)
|
|
|
|
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
|
|
|
else
|
|
|
|
var hashes = url.slice(url.indexOf('?') + 1).split('&');
|
|
|
|
for (var i = 0; i < hashes.length; i++) {
|
|
|
|
hash = hashes[i].split('=');
|
|
|
|
vars.push(hash[0]);
|
|
|
|
vars[hash[0]] = hash[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data e ora (orologio)
|
|
|
|
function clock() {
|
|
|
|
$('#datetime').html(moment().format(globals.timestampFormat));
|
|
|
|
setTimeout('clock()', 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Funzione per impostare un valore ad un array in $_SESSION
|
|
|
|
*/
|
|
|
|
function session_set_array(session_array, value, inversed) {
|
|
|
|
if (inversed == undefined) {
|
|
|
|
inversed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $.get(globals.rootdir + "/ajax.php?op=session_set_array&session=" + session_array + "&value=" + value + "&inversed=" + inversed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Funzione per impostare un valore ad una sessione
|
|
|
|
*/
|
2018-03-20 00:57:36 +01:00
|
|
|
function session_set(session_array, value, clear, reload) {
|
2017-08-04 16:28:16 +02:00
|
|
|
if (clear == undefined) {
|
|
|
|
clear = 1;
|
|
|
|
}
|
|
|
|
|
2018-03-20 00:57:36 +01:00
|
|
|
if (reload == undefined) {
|
|
|
|
reload = 0;
|
|
|
|
}
|
|
|
|
|
2018-07-23 11:09:50 +02:00
|
|
|
return $.get(globals.rootdir + "/ajax.php?op=session_set&session=" + session_array + "&value=" + value + "&clear=" + clear, function (data, status) {
|
2018-06-29 15:48:57 +02:00
|
|
|
|
2018-07-23 11:09:50 +02:00
|
|
|
if (reload == 1)
|
2018-06-29 15:48:57 +02:00
|
|
|
location.reload();
|
|
|
|
|
2018-03-20 00:57:36 +01:00
|
|
|
});
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function session_keep_alive() {
|
|
|
|
$.get(globals.rootdir + '/core.php');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Funzione per gestire i contatori testuali nel formato x/total.
|
|
|
|
* Viene dato un id del campo da verificare come input, viene letto il testo nella forma [0-9]/[0-9] e viene fatto
|
|
|
|
* il replate del primo numero in base a quanti elementi sono stati trovati (valore passato per parametro)
|
|
|
|
*/
|
|
|
|
function update_counter(id, new_value) {
|
|
|
|
new_text = $('#' + id).html();
|
|
|
|
|
|
|
|
// Estraggo parte numerica (formato x/total)
|
|
|
|
pattern = /([^0-9]+)([0-9]+)\/([0-9]+)([^0-9]+)/;
|
|
|
|
new_text = new_text.replace(pattern, "$1" + new_value + "/$3$4");
|
|
|
|
|
|
|
|
// Estraggo totale (parte numerica dopo lo slash /)
|
|
|
|
matches = pattern.exec(new_text);
|
|
|
|
total = matches[3];
|
|
|
|
|
|
|
|
$('#' + id).html(new_text);
|
|
|
|
|
|
|
|
if (new_value == total) {
|
|
|
|
$('#' + id).removeClass('btn-warning').removeClass('btn-danger').addClass('btn-success');
|
|
|
|
} else if (new_value == 0) {
|
|
|
|
$('#' + id).removeClass('btn-warning').removeClass('btn-success').addClass('btn-danger');
|
|
|
|
} else {
|
|
|
|
$('#' + id).removeClass('btn-success').removeClass('btn-danger').addClass('btn-warning');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Number.prototype.formatMoney = function (c, d, t) {
|
|
|
|
var n = this,
|
|
|
|
c = isNaN(c = Math.abs(c)) ? 2 : c,
|
|
|
|
d = d == undefined ? "." : d,
|
|
|
|
t = t == undefined ? "," : t,
|
|
|
|
s = n < 0 ? "-" : "",
|
|
|
|
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
|
|
|
|
j = (j = i.length) > 3 ? j % 3 : 0;
|
|
|
|
|
|
|
|
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
|
|
|
|
}
|
|
|
|
|
2017-08-11 12:11:57 +02:00
|
|
|
String.prototype.toEnglish = function () {
|
2017-09-19 16:50:01 +02:00
|
|
|
return numeral(this.toString()).value();
|
2017-08-11 12:11:57 +02:00
|
|
|
};
|
|
|
|
|
2017-09-19 16:50:01 +02:00
|
|
|
Number.prototype.toLocale = function () {
|
|
|
|
return numeral(this).format();
|
2017-08-04 16:28:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function setContrast(backgroundcolor) {
|
|
|
|
var rgb = [];
|
|
|
|
var bg = String(backgroundcolor);
|
|
|
|
|
|
|
|
// ex. backgroundcolor = #ffc400
|
|
|
|
rgb[0] = bg.substr(1, 2);
|
|
|
|
rgb[1] = bg.substr(2, 2);
|
|
|
|
rgb[2] = bg.substr(5, 2);
|
|
|
|
|
|
|
|
var R1 = parseInt(rgb[0], 16);
|
|
|
|
var G1 = parseInt(rgb[1], 16);
|
|
|
|
var B1 = parseInt(rgb[2], 16);
|
|
|
|
|
|
|
|
var R2 = 255;
|
|
|
|
var G2 = 255;
|
|
|
|
var B2 = 255;
|
|
|
|
|
|
|
|
var L1 = 0.2126 * Math.pow(R1 / 255, 2.2) + 0.7152 * Math.pow(G1 / 255, 2.2) + 0.0722 * Math.pow(B1 / 255, 2.2);
|
|
|
|
var L2 = 0.2126 * Math.pow(R2 / 255, 2.2) + 0.7152 * Math.pow(G2 / 255, 2.2) + 0.0722 * Math.pow(B2 / 255, 2.2);
|
|
|
|
|
|
|
|
if (L1 > L2) {
|
|
|
|
var lum = (L1 + 0.05) / (L2 + 0.05);
|
|
|
|
} else {
|
|
|
|
var lum = (L2 + 0.05) / (L1 + 0.05);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lum >= 9) {
|
|
|
|
return "#ffffff";
|
|
|
|
} else {
|
|
|
|
return "#000000";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function message(element) {
|
2017-09-07 18:58:41 +02:00
|
|
|
data = $.extend({}, $(element).data());
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
var title = globals.translations.deleteTitle;
|
|
|
|
if (data["title"] != undefined) title = data["title"];
|
|
|
|
|
|
|
|
var msg = globals.translations.deleteMessage;
|
2018-09-27 17:27:39 +02:00
|
|
|
if (data["msg"] != undefined) msg = data["msg"];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
var button = globals.translations.delete;
|
|
|
|
if (data["button"] != undefined) button = data["button"];
|
|
|
|
|
|
|
|
var btn_class = "btn btn-lg btn-danger";
|
|
|
|
if (data["class"] != undefined) btn_class = data["class"];
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: title,
|
2018-09-27 17:27:39 +02:00
|
|
|
html: '<div id="swal-form" data-parsley-validate>' + msg + '</div>',
|
2017-08-04 16:28:16 +02:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonText: button,
|
|
|
|
confirmButtonClass: btn_class,
|
2018-09-27 17:27:39 +02:00
|
|
|
onOpen: function () {
|
|
|
|
start_superselect();
|
|
|
|
start_inputmask();
|
|
|
|
},
|
2018-07-23 11:09:50 +02:00
|
|
|
preConfirm: function () {
|
2018-09-27 17:27:39 +02:00
|
|
|
$form = $('#swal-form');
|
|
|
|
$form.find(':input').each(function () {
|
2018-07-23 11:09:50 +02:00
|
|
|
data[$(this).attr('name')] = $(this).val();
|
|
|
|
});
|
|
|
|
|
2018-09-27 17:27:39 +02:00
|
|
|
if ($form.parsley().validate()) {
|
|
|
|
return new Promise(function (resolve) {
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('.swal2-buttonswrapper button').each(function () {
|
|
|
|
$(this).prop('disabled', false);
|
|
|
|
});
|
|
|
|
}
|
2018-07-23 11:09:50 +02:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}).then(
|
2018-09-27 17:27:39 +02:00
|
|
|
function () {
|
2017-08-04 16:28:16 +02:00
|
|
|
if (data["op"] == undefined) data["op"] = "delete";
|
|
|
|
|
|
|
|
var href = window.location.href.split("#")[0]
|
|
|
|
if (data["href"] != undefined) {
|
|
|
|
href = data["href"];
|
|
|
|
delete data.href;
|
|
|
|
}
|
|
|
|
|
|
|
|
var hash = window.location.href.split("#")[1];
|
|
|
|
if (hash) {
|
|
|
|
data["hash"] = hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
method = "post";
|
|
|
|
if (data["method"] != undefined) {
|
|
|
|
if (data["method"] == "post" || data["method"] == "get") {
|
|
|
|
method = data["method"];
|
|
|
|
}
|
|
|
|
delete data.method;
|
|
|
|
}
|
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
blank = data.blank != undefined && data.blank;
|
|
|
|
delete data.blank;
|
|
|
|
|
2018-08-31 18:06:44 +02:00
|
|
|
if (data.callback) {
|
|
|
|
$.ajax({
|
|
|
|
type: method,
|
|
|
|
crossDomain: true,
|
|
|
|
url: href,
|
|
|
|
data: data,
|
|
|
|
success: function (response) {
|
|
|
|
var callback = window[data.callback];
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
callback(response);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function (xhr, ajaxOptions, error) {
|
|
|
|
swal({
|
|
|
|
title: globals.translations.errorTitle,
|
|
|
|
html: globals.translations.errorMessage,
|
|
|
|
type: "error",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
redirect(href, data, method, blank);
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
},
|
|
|
|
function (dismiss) {}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-09-13 16:21:16 +02:00
|
|
|
function redirect(href, data, method, blank) {
|
|
|
|
method = method ? method : "get";
|
|
|
|
blank = blank ? blank : false;
|
|
|
|
|
2017-09-13 17:56:49 +02:00
|
|
|
if (method == "post") {
|
|
|
|
var text = '<form action="' + href + window.location.hash + '" method="post"' + (blank ? ' target="_blank"' : '') + '>';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-13 17:56:49 +02:00
|
|
|
for (var name in data) {
|
2017-09-13 16:21:16 +02:00
|
|
|
text += '<input type="hidden" name="' + name + '" value="' + data[name] + '"/>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
text += '</form>';
|
|
|
|
|
|
|
|
var form = $(text);
|
|
|
|
$('body').append(form);
|
|
|
|
|
|
|
|
form.submit();
|
|
|
|
} else {
|
2017-09-13 17:56:49 +02:00
|
|
|
var values = [];
|
|
|
|
|
|
|
|
for (var name in data) {
|
|
|
|
values.push(name + '=' + data[name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var link = href + (href.indexOf('?') !== -1 ? '&' : '?') + values.join('&') + window.location.hash;
|
2017-09-13 17:08:27 +02:00
|
|
|
|
2017-09-18 17:24:25 +02:00
|
|
|
if (!blank) {
|
2017-09-13 17:08:27 +02:00
|
|
|
location.href = link;
|
2017-09-13 17:56:49 +02:00
|
|
|
} else {
|
|
|
|
window.open(link);
|
2017-09-13 17:08:27 +02:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-16 17:49:09 +02:00
|
|
|
|
|
|
|
function setCookie(cname, cvalue, exdays) {
|
|
|
|
var d = new Date();
|
2018-07-23 11:09:50 +02:00
|
|
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
|
|
|
var expires = "expires=" + d.toUTCString();
|
2018-04-16 17:49:09 +02:00
|
|
|
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCookie(cname) {
|
|
|
|
var name = cname + "=";
|
|
|
|
var decodedCookie = decodeURIComponent(document.cookie);
|
|
|
|
var ca = decodedCookie.split(';');
|
2018-07-23 11:09:50 +02:00
|
|
|
for (var i = 0; i < ca.length; i++) {
|
2018-04-16 17:49:09 +02:00
|
|
|
var c = ca[i];
|
|
|
|
while (c.charAt(0) == ' ') {
|
|
|
|
c = c.substring(1);
|
|
|
|
}
|
|
|
|
if (c.indexOf(name) == 0) {
|
|
|
|
return c.substring(name.length, c.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2018-06-18 15:56:00 +02:00
|
|
|
|
|
|
|
/**
|
2018-07-23 11:09:50 +02:00
|
|
|
* Funzione per controllare se un file esiste
|
|
|
|
*/
|
|
|
|
function UrlExists(url) {
|
2018-06-18 15:56:00 +02:00
|
|
|
var http = new XMLHttpRequest();
|
|
|
|
http.open('HEAD', url, false);
|
|
|
|
http.send();
|
2018-07-23 11:09:50 +02:00
|
|
|
return http.status != 404;
|
2018-06-29 15:48:57 +02:00
|
|
|
}
|
2018-09-19 09:51:36 +02:00
|
|
|
|
|
|
|
function buttonLoading(button) {
|
|
|
|
var $this = $(button);
|
|
|
|
|
|
|
|
var result = [
|
|
|
|
$this.html(),
|
|
|
|
$this.attr("class")
|
|
|
|
];
|
|
|
|
|
|
|
|
$this.html('<i class="fa fa-spinner fa-pulse fa-fw"></i> Attendere...');
|
|
|
|
$this.addClass("btn-warning");
|
|
|
|
$this.prop("disabled", true);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buttonRestore(button, loadingResult) {
|
|
|
|
var $this = $(button);
|
|
|
|
|
|
|
|
$this.html(loadingResult[0]);
|
|
|
|
|
|
|
|
$this.attr("class", "");
|
|
|
|
$this.addClass(loadingResult[1]);
|
|
|
|
$this.prop("disabled", false);
|
|
|
|
}
|
2018-09-27 10:15:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|