Initial Commit

This commit is contained in:
GiacomoHome
2021-09-17 12:41:45 +02:00
commit 9001e4656e
570 changed files with 31013 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
Number.prototype.toFixedDown = function (digits) {
var re = new RegExp("(\\d+\\.\\d{" + digits + "})(\\d)");
var m = this.toString().match(re);
return m ? parseFloat(m[1]) : this.valueOf();
};
Number.prototype.truncate = function (digits) {
var num = this.valueOf().toFixedDown(digits);
num = num.toString();
var intero = String(num.split('.')[0]);
var fraction = String(num.split('.')[1]);
var padding = '';
if (isNaN(intero)) return '';
if (fraction == 'undefined') {
fraction = '';
padding = new Array(Math.max(digits - fraction.length, 0) + 1).join('0');
if (digits > 0) {
num += '.' + padding;
}
} else {
padding = new Array(Math.max(digits - fraction.length, 0) + 1).join('0');
num += padding;
}
return num;
};
//funzione per l'arrotondamento delle cifre decimali in eccesso dal 5
Number.prototype.toFixedExcess = function(precision){
precision = (parseInt(precision) == 0) ? 0:(parseInt(precision) || 2);
var num = this.valueOf();
var pow = Math.pow(10,precision);
return (Math.round( num * pow ) / pow).toFixed(precision);
};
//Funzione per arrotondare correttamente i numeri in modo da correggere l'errore delle somme e differenze
function myParseFloat(number){
//console.log("MyParseFloat-Old: "+number);
var newnumber = new Number(number+'').toFixed(12);
//console.log("MyParseFloat-New: "+newnumber);
return parseFloat(newnumber);
}
//Funzione che implementa il pad left di una stringa
Number.prototype.padLeft = function (n,str) {
return (this < 0 ? '-' : '') +
Array(n-String(Math.abs(this)).length+1)
.join(str||'0') +
(Math.abs(this));
};
const checkIfAddressIsInArea = (location, area) => {
if (google.maps.geometry.poly.containsLocation(location, area)){
return true;
} else {
return false;
}
}
const checkIfAddressIsInAreaLatLon = (lat, lon) => {
const location = new google.maps.LatLng(lat, lon);
if (google.maps.geometry.poly.containsLocation(location, area)){
return true;
} else {
return false;
}
}
+1000
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,82 @@
'use strict';
function DashboardController($scope, Ordini, moment, toaster, AuthService, DateRangePickerService, $timeout, $window) {
$scope.dateRangeOptions = {
...defaultDateRangePickerOptions,
ranges: DateRangePickerService.getTrimestreCustomRangeOptions(),
autoApply: true
};
const stampaRapportoAdminUri = `${BASE_URL_SITE}/admin/index/stampareportattivita`;
$scope.loading = true;
$scope.DataConsegna = {startDate: moment().subtract(29, 'days'), endDate: moment()};
$scope.Periodo = '';
$scope.series = ['Ordini ' + $scope.Periodo, ''];
$scope.colors = ['#44ABF1', '#DDDDDD'];
$scope.labels = [];
$scope.data = [];
$scope.TotOrdiniPeriodo = 0;
$scope.graphOptions = {
legend: {display: false},
scales: {
yAxes: [
{
id: 'y-axis-1',
type: 'linear',
display: true,
position: 'left'
}
]
}
};
$scope.$watch('DataConsegna', (oldVal, newVal) => {
$scope.Periodo = 'Dal ' + newVal.startDate.format('DD/MM/YYYY') + ' al ' + newVal.endDate.format('DD/MM/YYYY');
$scope.refreshGraph();
});
$scope.refreshGraph = () => {
$scope.loading = true;
const per = $scope.DataConsegna.startDate.format('YYYY-MM-DD') + '|' + $scope.DataConsegna.endDate.format('YYYY-MM-DD');
Ordini.getGraphData(per).then((res) => {
$scope.labels = res.DatiGrafico.labels;
$scope.data = [res.DatiGrafico.data, []];
$scope.TotOrdiniPeriodo = res.TotOrdini;
}).catch((err) => {
toaster.error("Attenzione", "Errore durante il recupero dei dati del grafico");
}).finally(() => {
$timeout(() => {
$scope.loading = false
}, 300);
});
};
$scope.stampaRapporto = () => {
if (!$scope.DataConsegna) {
alert("Devi selezionare un periodo per la stampa rapporto");
return;
}
let periodo = $scope.DataConsegna.startDate.format('YYYY-MM-DD') + '|' + $scope.DataConsegna.endDate.format('YYYY-MM-DD');
/*if(!confirm(`Aprire la stampa report per il periodo scelto (${periodo}) ?`)){
return;
}*/
let url = `${stampaRapportoAdminUri}/p/${periodo}`;
$window.open(url, '_blank');
};
//$scope.refreshGraph();
}
app.controller('DashboardController', DashboardController);
+271
View File
@@ -0,0 +1,271 @@
angular.module('app')
.factory('SottoAree', function ($resource) {
const resource = $resource(basePath + 'sottoaree/:id', {id: '@id'}, {
update: {method: 'PUT'},
insert: {method: 'POST'},
getList: {
method: 'GET',
url: basePath + 'sottoaree',
transformResponse: function (result,headers) {
let res = {};
res.data = angular.fromJson(result);
res.headers = headers();
return res;
}
},
getByCodice: {
method: 'GET',
url: basePath + 'sottoaree/m/get-by-codice'
}
});
return {
get: function (success, error) {
return resource.query(success, error);
},
find: function (id) {
return resource.get({id: id}).$promise;
},
insert: function (data) {
return resource.insert(data).$promise;
},
update: function (data) {
return resource.update(data).$promise;
},
delete: function (id) {
return resource.delete({id: id}).$promise;
},
getList: function (data) {
return resource.getList(data).$promise;
},
getByCodice: function (codice) {
return resource.getByCodice({Codice: codice}).$promise;
}
};
})
.factory('Users', function ($resource) {
const resource = $resource(basePath + 'users/:id', {id: '@id'}, {
update: {method: 'PUT'},
insert: {method: 'POST'},
getUserData: {
method: 'GET',
url: basePath + 'users/m/get-user-info',
transformResponse: function (result,headers) {
let res = {};
res.data = angular.fromJson(result);
res.headers = headers();
return res;
}
},
getList: {
method: 'GET',
url: basePath + 'users',
transformResponse: function (result,headers) {
let res = {};
res.data = angular.fromJson(result);
res.headers = headers();
return res;
}
},
proponiCodiceUtente: {
method: 'GET',
url: basePath + 'users/m/get-codice'
},
caricaRidersMt: {
method: 'GET',
url: basePath + 'users/m/get-riders-mt',
transformResponse: function (result,headers) {
let res = {};
res.data = angular.fromJson(result);
res.headers = headers();
return res;
}
},
});
return {
get: function (success, error) {
return resource.query(success, error);
},
find: function (id) {
return resource.get({id: id}).$promise;
},
getByToken: function (token) {
return resource.getList({token: token}).$promise;
},
getUserData: function () {
return resource.getUserData().$promise;
},
insert: function (data) {
return resource.insert(data).$promise;
},
update: function (data) {
return resource.update(data).$promise;
},
delete: function (id) {
return resource.delete({id: id}).$promise;
},
getList: function (data) {
return resource.getList(data).$promise;
},
proponiCodiceUtente: function (role) {
return resource.proponiCodiceUtente({role: role}).$promise;
},
caricaRidersMt: function () {
return resource.caricaRidersMt().$promise;
}
};
})
.factory('FasceOrarie', function ($resource) {
const resource = $resource(basePath + 'fasceorarie/:id', {id: '@id'}, {
update: {method: 'PUT'},
insert: {method: 'POST'},
getList: {
method: 'GET',
url: basePath + 'fasceorarie',
transformResponse: function (result,headers) {
let res = {};
res.data = angular.fromJson(result);
res.headers = headers();
return res;
}
}
});
return {
get: function (success, error) {
return resource.query(success, error);
},
find: function (id) {
return resource.get({id: id}).$promise;
},
insert: function (data) {
return resource.insert(data).$promise;
},
update: function (data) {
return resource.update(data).$promise;
},
delete: function (id) {
return resource.delete({id: id}).$promise;
},
getList: function (data) {
return resource.getList(data).$promise;
}
};
})
.factory('TipologieAttivita', function ($resource) {
const resource = $resource(basePath + 'tipologieattivita/:id', {id: '@id'}, {
update: {method: 'PUT'},
insert: {method: 'POST'},
getList: {
method: 'GET',
url: basePath + 'tipologieattivita',
transformResponse: function (result,headers) {
let res = {};
res.data = angular.fromJson(result);
res.headers = headers();
return res;
}
}
});
return {
get: function (success, error) {
return resource.query(success, error);
},
find: function (id) {
return resource.get({id: id}).$promise;
},
insert: function (data) {
return resource.insert(data).$promise;
},
update: function (data) {
return resource.update(data).$promise;
},
delete: function (id) {
return resource.delete({id: id}).$promise;
},
getList: function (data) {
return resource.getList(data).$promise;
}
};
})
.factory('Ordini', function ($resource) {
const resource = $resource(basePath + 'ordini/:id', {id: '@id'}, {
update: {method: 'PUT'},
insert: {method: 'POST'},
getList: {
method: 'GET',
url: basePath + 'ordini',
transformResponse: function (result,headers) {
let res = {};
res.data = angular.fromJson(result);
res.headers = headers();
return res;
}
},
getOrdiniDaGestire: {
method: 'GET',
url: basePath + 'ordiniadmin',
transformResponse: function (result,headers) {
let res = {};
res.data = angular.fromJson(result);
res.headers = headers();
return res;
}
},
checkStatoOrdiniSync: {
method: 'GET',
url: basePath + 'ordiniadmin/m/check-ordini-sync',
},
setStatoOrdiniSync: {
method: 'GET',
url: basePath + 'ordiniadmin/m/set-ordini-sync',
},
resetMtDashboard: {
method: 'GET',
url: basePath + 'ordiniadmin/m/reset-mt-dashboard',
},
getGraphData: {
method: 'GET',
url: basePath + 'ordiniadmin/m/get-graph-data',
}
});
return {
get: function (success, error) {
return resource.query(success, error);
},
find: function (id) {
return resource.get({id: id}).$promise;
},
insert: function (data) {
return resource.insert(data).$promise;
},
update: function (data) {
return resource.update(data).$promise;
},
delete: function (id) {
return resource.delete({id: id}).$promise;
},
getList: function (data) {
return resource.getList(data).$promise;
},
getOrdiniDaGestire: function (data) {
return resource.getOrdiniDaGestire(data).$promise;
},
checkStatoOrdiniSync: function () {
return resource.checkStatoOrdiniSync().$promise;
},
setStatoOrdiniSync: function (stato) {
return resource.setStatoOrdiniSync({s: stato}).$promise;
},
resetMtDashboard: function () {
return resource.resetMtDashboard().$promise;
},
getGraphData: function (periodo) {
return resource.getGraphData({p: periodo}).$promise;
}
};
});
+565
View File
@@ -0,0 +1,565 @@
'use strict';
/******************** PARAMETRI ******************************/
const BASE_URL_SITE = $('link[rel="canonical"]').attr('href');
var modal_id = '#modal';
var form_id = '#' + $(modal_id).attr('data-form');
var form = $(form_id);
var filter_modal_id = '#filterModal';
var filter_form_id = '#' + $(filter_modal_id).attr('data-form');
var filter_form = $(filter_form_id);
var modalLoader = $('#modal-loader');
/*********************************************************************************/
/**** FUNZIONI GLOBALI PERSONALIZZATE ***/
const defaultDatePickerOptions = {
language: 'it',
format: "dd/mm/yyyy",
autoclose: true
};
const defaultDateRangePickerOptions = {
autoApply: false,
autoUpdateInput: false,
linkedCalendars: false,
showCustomRangeLabel: false,
locale: {
"format": "DD/MM/YYYY",
"separator": " | ",
"applyLabel": "Ok",
"cancelLabel": "Reset",
"fromLabel": "Da",
"toLabel": "A",
"customRangeLabel": "Custom",
"weekLabel": "W",
"daysOfWeek": [
"Dom",
"Lun",
"Mar",
"Mer",
"Gio",
"Ven",
"Sab"
],
"monthNames": [
"Gennaio",
"Febbraio",
"Marzo",
"Aprile",
"Maggio",
"Giugno",
"Luglio",
"Agosto",
"Settembre",
"Ottobre",
"Novembre",
"Dicembre"
],
"firstDay": 1
},
alwaysShowCalendars: true,
ranges: {
'Oggi': [moment(), moment()],
'Ieri': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Ultimi 7 gg': [moment().subtract(6, 'days'), moment()],
'Ultimi 30 gg': [moment().subtract(29, 'days'), moment()],
'Questo Mese': [moment().startOf('month'), moment().endOf('month')],
'Mese Scorso': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
};
let $table;
String.prototype.capitalize = function () {
return this.charAt(0).toUpperCase() + this.slice(1)
}
$('a[href="#"]').click(function (event) {
event.preventDefault();
});
$('a[data-widget="pushmenu"]').click(function () {
let collapsed = ($('body').hasClass('sidebar-collapse')) ? 0 : 1;
$.cookie('ui_sidebar_collapsed', collapsed, {path: '/'});
if (collapsed) {
$table.trigger('reflow');
}
});
/****************************************
************* SEZIONE FORM *************
***************************************/
function populateForm(data, frm) {
$.each(data, function (key, value) {
var $ctrl = $('[name=' + key + ']', frm);
if ($ctrl.is('select')) {
$("option", $ctrl).each(function () {
if (this.value == value) {
this.selected = true;
}
});
} else {
switch ($ctrl.attr("type")) {
case "text":
case "hidden":
case "number":
$ctrl.val(value);
break;
case "textarea":
$ctrl.val(value);
break;
case "radio":
case "checkbox":
$ctrl.each(function () {
if ($(this).attr('id') == key && value == '1') {
$(this).iCheck('check');
}
});
break;
default:
$ctrl.val(value);
break;
}
}
});
$('input.datepicker').datepicker('update');
}
function resetForm(tipo, form_id) {
$(form_id + ' #ErrorDescription').html('').addClass('d-none');
$(form_id + ' div.form-group').removeClass('has-error');
$(form_id + ' div.multi-line-field-label-error').removeClass('has-error');
$(form_id + ' div.label-danger').addClass('d-none').html('');
if (tipo != 'errors') {
$(form_id).clearForm();
}
}
function getErrorHtml(formErrors, noBr) {
if ((typeof (formErrors) === 'undefined') || (formErrors.length < 1)) return;
noBr = (typeof (noBr) === 'undefined') ? false : noBr;
var out = '';
let brtxt = (noBr) ? '' : '<br>';
for (let errorKey in formErrors) {
out += (formErrors[errorKey] + brtxt);
}
return out;
}
function showErrors(form_id, resp) {
resetForm('errors', form_id);
//$(form_id + ' #ErrorDescription').html(resp.message).removeClass('d-none');
toastr.error(resp.message);
for (let key in resp.errors) {
let errBlock = $(form_id + ' div#' + key);
let labelBlock = $(form_id + ' div#' + key + ' .label-danger');
errBlock.addClass('has-error');
if (labelBlock.length === 0) {
labelBlock = errBlock.parent().children(' .label-danger');
labelBlock.html(labelBlock.html() + ' | ' + getErrorHtml(resp.errors[key], true));
labelBlock.removeClass('d-none');
} else {
labelBlock.html(getErrorHtml(resp.errors[key])).removeClass('d-none');
}
}
}
function initDatePicker() {
$('.datepicker').datepicker(defaultDatePickerOptions);
}
function initDateRangePicker(customRange) {
let dateRangePickerOptions = defaultDateRangePickerOptions;
if (customRange) {
dateRangePickerOptions.ranges = customRange;
}
$('input[daterangepicker]').daterangepicker(dateRangePickerOptions);
$('input[daterangepicker]').on('apply.daterangepicker', function (ev, picker) {
$(this).val(picker.startDate.format('DD/MM/YYYY') + ' | ' + picker.endDate.format('DD/MM/YYYY'));
});
$('input[daterangepicker]').on('cancel.daterangepicker', function (ev, picker) {
$(this).val('');
});
}
function initSwitchButton() {
//Abilita gli swithc button
$("input[data-bootstrap-switch]").each(function () {
$(this).bootstrapSwitch('state', $(this).prop('checked'));
});
}
function initICheck() {
var tableBody = $('#tablebody');
$('#select_all').click(function (link) {
link.preventDefault();
tableBody.find(':checkbox').iCheck('check');
});
$('#deselect_all').click(function (link) {
link.preventDefault();
tableBody.find(':checkbox').iCheck('uncheck');
});
$('#invert_all').click(function (link) {
link.preventDefault();
tableBody.find(':checkbox').iCheck('toggle');
});
}
function initTooltip() {
$('[data-toggle="tooltip"]').tooltip();
}
function initPopover() {
$('[data-toggle="popover"]').popover();
}
function initSummernote() {
$('.summernote').summernote({
dialogsInBody: true
});
}
function initSelect2(){
$('select[select2]').select2();
}
/*function initFontIconPicker(options){
$('[font-icon-picker]').fontIconPicker(options);
}*/
function refreshFormComponents() {
$("input[type='checkbox'], input[type='radio']").not(".no-icheck").iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue'
});
initTooltip();
initPopover();
}
function initFormComponents() {
refreshFormComponents();
initICheck();
initSwitchButton();
initDatePicker();
initDateRangePicker();
}
$(document).ready(() => {
setOrderThValue();
fixHeghtOfTableList();
}).delegate('a[href="#"]', 'click', function (link) {
link.preventDefault();
})
.delegate('#filterData', 'click', function (link) {
link.preventDefault();
$(filter_modal_id).modal('show');
})
.delegate('#filtra', 'click', function (link) {
link.preventDefault();
filter_form.submit();
})
.delegate('#resetFiltri', 'click', function (link) {
link.preventDefault();
filter_form.clearForm();
filter_form.find('select').val('');
})
.delegate('th[data-ord]', 'click', function (link) {
link.preventDefault();
const ordVal = $(this).attr('data-ord');
const tipoOrderEl = $('#tipoOrder');
const tipoOrder = (tipoOrderEl.val() === 'ASC') ? 'DESC' : 'ASC';
$('#order').val(ordVal);
tipoOrderEl.val(tipoOrder);
$('#searchForm').submit();
})
.delegate('select[data-refresh-search-form]', 'change', function (link) {
link.preventDefault();
$('#searchForm').submit();
})
/*******************************************
************* SEZIONE TABELLA *************
******************************************/
function setOrderThValue() {
const ordVal = $('#order').val();
const tipoOrd = $('#tipoOrder').val();
$('th[data-ord]').find('i').remove();
const thOrd = $('th[data-ord="' + ordVal + '"]');
const icon = (tipoOrd === 'ASC') ? 'fa-chevron-up' : 'fa-chevron-down';
const iconText = `<i class="fas ${icon}"></i>`;
thOrd.find('i').remove();
const thText = thOrd.html() + ' ' + iconText;
thOrd.html(thText);
}
function initTableFlotHeader() {
//Abilito l'header fisso
$table = $('.table.flot-header');
$table.floatThead({
autoReflow: true,
scrollContainer: function ($table) {
return $table.closest('.table-wrapper');
},
responsiveContainer: function ($table) {
return $table.closest('.table-responsive');
}
});
//Imposta l'altezza del table-wrapper
fixHeghtOfTableList();
}
function refreshTable() {
if ($table) {
fixHeghtOfTableList();
}
}
function fixHeghtOfTableList() {
let windowHeight = $(window).height();
let navbarHeight = $(".navbar").outerHeight() || 0;
let footerHeight = $(".main-footer").outerHeight() || 0;
let contentHeaderHeight = $(".content-header").outerHeight() || 0;
let boxHeaderHeight = $(".box-header").outerHeight() || 0;
let boxFooterHeight = $(".box-footer").outerHeight() || 0;
let tableWrapperHeight = windowHeight - (navbarHeight + footerHeight + contentHeaderHeight + boxHeaderHeight + boxFooterHeight + 15);
$('.table-wrapper').css("height", tableWrapperHeight + "px");
let theadHeight = $('.table-wrapper thead').outerHeight() + 1;
const totHeight = tableWrapperHeight - theadHeight;
$('td.no-rows').css("height", (totHeight) + "px");
}
$(window).resize(function () {
fixHeghtOfTableList();
$table.trigger('reflow');
});
/**************************************************
************* FUNZIONI SPECIALIZZATE *************
*************************************************/
function password_generator(len) {
let length = (len) ? (len) : (10);
let string = "abcdefghijklmnopqrstuvwxyz"; //to upper
let numeric = '0123456789';
let punctuation = '!@#$%^&*()_+~`|}{[]\:;?><,./-=';
let password = "";
let character = "";
let crunch = true;
while (password.length < length) {
let entity1 = Math.ceil(string.length * Math.random() * Math.random());
let entity2 = Math.ceil(numeric.length * Math.random() * Math.random());
let entity3 = Math.ceil(punctuation.length * Math.random() * Math.random());
let hold = string.charAt(entity1);
hold = (entity1 % 2 == 0) ? (hold.toUpperCase()) : (hold);
character += hold;
character += numeric.charAt(entity2);
character += punctuation.charAt(entity3);
password = character;
}
return password;
}
function copyToClipboard(elem) {
// create hidden text element, if it doesn't already exist
var targetId = "_hiddenCopyText_";
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
var origSelectionStart, origSelectionEnd;
if (isInput) {
// can just use the original source element for the selection and copy
target = elem;
origSelectionStart = elem.selectionStart;
origSelectionEnd = elem.selectionEnd;
} else {
// must use a temporary form element for the selection and copy
target = document.getElementById(targetId);
if (!target) {
var target = document.createElement("textarea");
target.style.position = "absolute";
target.style.left = "-9999px";
target.style.top = "0";
target.id = targetId;
document.body.appendChild(target);
}
target.textContent = elem.textContent;
}
// select the content
var currentFocus = document.activeElement;
target.focus();
target.setSelectionRange(0, target.value.length);
// copy the selection
var succeed;
try {
succeed = document.execCommand("copy");
} catch (e) {
succeed = false;
}
// restore original focus
if (currentFocus && typeof currentFocus.focus === "function") {
currentFocus.focus();
}
if (isInput) {
// restore prior selection
elem.setSelectionRange(origSelectionStart, origSelectionEnd);
} else {
// clear temporary content
target.textContent = "";
}
return succeed;
}
/**
* Questa funzione passato un template html ne sostituisce i parametri
* @param template
* @param params
*/
function prepareHTMLWithParams(template, params) {
if (params instanceof Array) {
params.forEach(function (val, key) {
template = template.replace(new RegExp('%' + key + '%', 'g'), val);
});
} else if (params instanceof Object) {
Object.keys(params).forEach(function (key) {
template = template.replace(new RegExp('%' + key + '%', 'g'), params[key]);
});
}
return template;
}
/************************************************************************************
************* SEZIONE FUNZIONI GENRICHE PER LA GESTIONE DELLE IMMAGINI *************
************************************************************************************/
/**
* Questa funzione carica l'immagine nel box anteprima
* @param basePathImage
* @param nomeVaribileFile
* @param valFile
*/
function popolaImmagine(basePathImage, nomeVaribileFile, valFile, custom_class) {
if (custom_class === undefined) {
custom_class = 'img-fluid img-thumbnail';
}
if (valFile) {
$('#preview_block_' + nomeVaribileFile).addClass(custom_class).attr('src', basePathImage + valFile);
$('#image-preview-filename-' + nomeVaribileFile).val(valFile);
$("#image-preview-input-title-" + nomeVaribileFile).text("Cambia");
$("#image-preview-clear-" + nomeVaribileFile).show();
}
}
/**
* Questa funzione resetta il blocco immagine in base al parametro nome File che riceve
* @param nomeVariabileFile
* @param baseImagePath
*/
function resetImageInput(nomeVariabileFile, baseImagePath) {
// $('#preview_block_' + nomeVariabileFile).attr('src', baseImagePath + 'noimage.jpg');
$('#preview_block_' + nomeVariabileFile).attr('src', baseImagePath + 'no_img.png');
$('#image-preview-filename-' + nomeVariabileFile).val('');
$('#image-preview-clear-' + nomeVariabileFile).hide();
$('#image-preview-input-title-' + nomeVariabileFile).html('Carica ...');
var input_file = $('input#image_' + nomeVariabileFile);
input_file.replaceWith(input_file.val('').clone(true));
}
/**
* Questa funzione definisce gli event handler per il nome immagine che riceve in entrata
*
* @param nome_immagine
* @param base_image_path
* @param custom_class [default value: img-fluid img-thumbnail']
* @param custom_style [default value: '']
*
* '?' sta a indicare la Varibile NomeFile che si passa, dovrebbe corrispondere al nome del campo immagine
* image-preview-clear-? = Identificativo del pulsante "Cancella"
* image-preview-input-title-? = Identifica il testo del pusante "Scegli..." o "Cambia"
* image-preview-input-? = Identificativo del input di tipo FILE dove andra dell'immagine
* image-preview-filename-? = Identificativo dell'input che contiene il nome del file immagine caricato
* image_preview_block_? = Identificativo del blocco che contiene l'html con il tag <IMG>
* preview_block_? = Identificatico dell'elemento immagine per visualizzare l'anteprima
*/
function defineEventHandlerForImageBlock(nome_immagine, base_image_path, custom_class, custom_style) {
if (custom_class === undefined) {
custom_class = 'img-fluid img-thumbnail';
}
if (custom_style === undefined) {
custom_style = '';
}
//Evento click pulsante cancella
$('#image-preview-clear-' + nome_immagine).click(function () {
resetImageInput(nome_immagine, base_image_path);
});
//Evento che al caricamento dell'immgaine ne crea il blocco anteprima
$("#image-preview-input-" + nome_immagine + " input:file").change(function () {
let img = $('<img/>', {
id: 'preview_block_' + nome_immagine,
class: custom_class,
style: custom_style
});
let nome_file_1 = this.files[0];
let reader_file_1 = new FileReader();
// Set preview image into the popover data-content
reader_file_1.onload = function (e) {
$("#image-preview-input-title-" + nome_immagine).text("Cambia");
$("#image-preview-clear-" + nome_immagine).show();
$("#image-preview-filename-" + nome_immagine).val(nome_file_1.name);
img.attr('src', e.target.result);
$("#image_preview_block_" + nome_immagine).html($(img)[0].outerHTML);
};
reader_file_1.readAsDataURL(nome_file_1);
});
}
@@ -0,0 +1,3 @@
$('document').ready(function () {
});
@@ -0,0 +1,177 @@
'use strict';
function beforeSubmit() {
modalLoader.removeClass('d-none').addClass('d-flex');
}
function errorOnSubmit() {
modalLoader.removeClass('d-flex').addClass('d-none');
}
function afterSubmit(resp) {
if (resp.success === 'invalid') {
showErrors(form_id, resp);
} else if (resp.success === true) {
let id;
let mex = '';
if (resp.op === 'insert') {
$('#tablebody').prepend(resp.text);
$('input#id').val(resp.data.id);
mex = 'Inserimento effettuato con successo';
id = resp.data.id;
} else {
$('tr[data-id=' + resp.id + ']').replaceWith(resp.text);
mex = 'Modifca effettuata con successo';
id = resp.id;
}
refreshFormComponents();
$('#norows').remove();
$(modal_id).modal('hide');
$('#save').attr('op', 'insert');
myResetForm('', form_id);
toastr.success(mex);
} else {
toastr.error(resp.shortMessage);
console.error(resp.message);
}
modalLoader.removeClass('d-flex').addClass('d-none');
}
//Specializzo la funzione resetForm nel caso ci sia bisogno di campi TEXTAREA o immagini da resettare
function myResetForm(tipo, formid) {
resetForm(tipo, formid);
}
function edit(id) {
$('#save').attr('op', 'edit');
var dati = 'id=' + id;
var url = $(form_id).attr('data-get');
myResetForm('all', form_id);
$.getJSON(url, dati, function (resp) {
if (resp.success) {
populateForm(resp, form);
$(modal_id).modal('show');
} else {
toastr.error(resp.message);
}
});
}
$(document).ready(function () {
initFormComponents();
initTableFlotHeader();
})
.delegate('#new', 'click', function (link) {
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
$(modal_id).modal('show');
})
.delegate('#save', 'click', function (link) {
link.preventDefault();
var operation = $(this).attr('op');
var options = {
target: '#ErrorDescription',
beforeSubmit: beforeSubmit,
success: afterSubmit,
error: errorOnSubmit,
data: {
op: operation
},
dataType: 'json',
resetForm: false
};
$(form_id).ajaxSubmit(options);
})
.delegate('#edit,#editLink', 'click', function (link) {
link.preventDefault();
const id = $(this).parents('tr').attr('data-id');
edit(id);
})
.delegate('#delete', 'click', function (link) {
link.preventDefault();
const url = $(form_id).attr('data-delete');
let tr = $(this).parents('tr');
const cod = tr.attr('data-cod');
let id = tr.attr('data-id');
let message = 'Sei sicuro di voler eliminare definitivamente l\'elemento?';
if (confirm(message)) {
$.ajax({
type: 'POST',
url: url,
data: 'id=' + id + "&cod=" + cod,
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
toastr.success('Eliminazione effettuata con successo');
} else {
toastr.error(resp.message);
}
}
});
}
})
.delegate('#delete_select', 'click', function (link) {
link.preventDefault();
let message = 'Sei sicuro di voler eliminare definitivamente gli elementi selezionati?';
if (confirm(message)) {
let data = [];
$('#tablebody').find(':checkbox').each(function () {
if (this.checked) {
data.push($(this).val());
}
});
let url = $(this).attr('href');
$.ajax({
type: 'POST',
url: url,
data: {
data: data
},
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
var ids = resp.id;
for (var i = 0; i < ids.length; i++) {
var tr = $('#tablebody tr[data-id=' + ids[i] + ']');
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
}
} else {
toastr.error(resp.message);
}
$('#tablebody').find(':checkbox').iCheck('uncheck');
}
});
}
})
.delegate(modal_id,'hidden.bs.modal',function(link){
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
});
@@ -0,0 +1,181 @@
'use strict';
function beforeSubmit() {
modalLoader.removeClass('d-none').addClass('d-flex');
}
function errorOnSubmit() {
modalLoader.removeClass('d-flex').addClass('d-none');
}
function afterSubmit(resp) {
if (resp.success === 'invalid') {
showErrors(form_id, resp);
} else if (resp.success === true) {
let id;
let mex = '';
if (resp.op === 'insert') {
$('#tablebody').prepend(resp.text);
$('input#id').val(resp.data.id);
mex = 'Inserimento effettuato con successo';
id = resp.data.id;
} else {
$('tr[data-id=' + resp.id + ']').replaceWith(resp.text);
mex = 'Modifca effettuata con successo';
id = resp.id;
}
refreshFormComponents();
$('#norows').remove();
$(modal_id).modal('hide');
$('#save').attr('op', 'insert');
myResetForm('', form_id);
toastr.success(mex);
} else {
toastr.error(resp.shortMessage);
console.error(resp.message);
}
modalLoader.removeClass('d-flex').addClass('d-none');
}
//Specializzo la funzione resetForm nel caso ci sia bisogno di campi TEXTAREA o immagini da resettare
function myResetForm(tipo, formid) {
resetForm(tipo, formid);
$('textarea#Testo').summernote('code', '');
}
function edit(id) {
$('#save').attr('op', 'edit');
var dati = 'id=' + id;
var url = $(form_id).attr('data-get');
myResetForm('all', form_id);
$.getJSON(url, dati, function (resp) {
if (resp.success) {
populateForm(resp, form);
$('textarea#Testo').summernote('code', resp.Testo);
$(modal_id).modal('show');
} else {
toastr.error(resp.message);
}
});
}
$(document).ready(function () {
initFormComponents();
initTableFlotHeader();
initSummernote();
})
.delegate('#new', 'click', function (link) {
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
$(modal_id).modal('show');
})
.delegate('#save', 'click', function (link) {
link.preventDefault();
var operation = $(this).attr('op');
var options = {
target: '#ErrorDescription',
beforeSubmit: beforeSubmit,
success: afterSubmit,
error: errorOnSubmit,
data: {
op: operation
},
dataType: 'json',
resetForm: false
};
$(form_id).ajaxSubmit(options);
})
.delegate('#edit,#editLink', 'click', function (link) {
link.preventDefault();
const id = $(this).parents('tr').attr('data-id');
edit(id);
})
.delegate('#delete', 'click', function (link) {
link.preventDefault();
const url = $(form_id).attr('data-delete');
let tr = $(this).parents('tr');
const cod = tr.attr('data-cod');
let id = tr.attr('data-id');
let message = 'Sei sicuro di voler eliminare definitivamente l\'elemento?';
if (confirm(message)) {
$.ajax({
type: 'POST',
url: url,
data: 'id=' + id + "&cod=" + cod,
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
toastr.success('Eliminazione effettuata con successo');
} else {
toastr.error(resp.message);
}
}
});
}
})
.delegate('#delete_select', 'click', function (link) {
link.preventDefault();
let message = 'Sei sicuro di voler eliminare definitivamente gli elementi selezionati?';
if (confirm(message)) {
let data = [];
$('#tablebody').find(':checkbox').each(function () {
if (this.checked) {
data.push($(this).val());
}
});
let url = $(this).attr('href');
$.ajax({
type: 'POST',
url: url,
data: {
data: data
},
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
var ids = resp.id;
for (var i = 0; i < ids.length; i++) {
var tr = $('#tablebody tr[data-id=' + ids[i] + ']');
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
}
} else {
toastr.error(resp.message);
}
$('#tablebody').find(':checkbox').iCheck('uncheck');
}
});
}
})
.delegate(modal_id,'hidden.bs.modal',function(link){
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
});
@@ -0,0 +1,97 @@
'use strict';
function resetForm(tipo) {
$('#Error_Description').html('').addClass('hidden');
$('.input-group').removeClass('has-error');
$('.form-control').removeClass('no-border');
$('.error-icon').addClass('hidden');
$('.label-error').addClass('hidden').html('');
if (tipo != 'errors') {
$('.form-control').val('');
}
}
function beforeSubmit() {
}
function errorOnSubmit() {
$('#modal-loader').addClass('hidden');
}
function afterSubmit(resp) {
$('.has-error').removeClass('has-error');
$.each(resp, function (index, val) {
if (val == 'OK') $('#' + index).addClass('has-success');
else $('#' + index).addClass('has-error');
});
toastr.success('Parametri di configurazione aggiornati con successo.');
}
$(document).ready(function () {
initDatePicker();
initTooltip();
initPopover();
initSwitchButton();
var options = {
target: '#Error_Description',
beforeSubmit: beforeSubmit,
error: errorOnSubmit,
success: afterSubmit,
dataType: 'json',
resetForm: false
};
$('a.setting-tab').click(function () {
var tabname = $(this).attr('href');
tabname = tabname.replace('#', '');
$.cookie('settings_tabname', tabname);
});
$(".btn-save").click(function (link) {
link.preventDefault();
const formID = $('.tab-pane.active').attr('id').capitalize();
const form = $('form#settings' + formID);
form.ajaxSubmit(options);
return false;
});
$('#btn-new-passoword').click(function (e) {
e.preventDefault();
var form = $('#password_form');
form.ajaxSubmit({
target: '#Error_Description',
success: function (resp) {
if (!resp.status) {
toastr.warning(" " + resp.message);
if (resp.resetForm) {
$('[form="password_form"]').val('');
}
} else {
$('[form="password_form"]').val('');
toastr.warning(" La password è stata reimpostata correttamente");
}
},
dataType: 'json',
resetForm: false
});
return false;
});
$("#BtnGeneraPassword").click(function (event) {
event.preventDefault();
$("#superPwd").val(password_generator(20));
});
$("#BtnCopyToClipboard").click(function (event) {
event.preventDefault();
$('#superPwd').attr('type', 'text');
copyToClipboard($('#superPwd')[0]);
$('#superPwd').attr('type', 'password');
});
});
@@ -0,0 +1,7 @@
$(function () {
$('input').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
});
@@ -0,0 +1,177 @@
'use strict';
function beforeSubmit() {
modalLoader.removeClass('d-none').addClass('d-flex');
}
function errorOnSubmit() {
modalLoader.removeClass('d-flex').addClass('d-none');
}
function afterSubmit(resp) {
if (resp.success === 'invalid') {
showErrors(form_id, resp);
} else if (resp.success === true) {
let id;
let mex = '';
if (resp.op === 'insert') {
$('#tablebody').prepend(resp.text);
$('input#id').val(resp.data.id);
mex = 'Inserimento effettuato con successo';
id = resp.data.id;
} else {
$('tr[data-id=' + resp.id + ']').replaceWith(resp.text);
mex = 'Modifca effettuata con successo';
id = resp.id;
}
refreshFormComponents();
$('#norows').remove();
$(modal_id).modal('hide');
$('#save').attr('op', 'insert');
myResetForm('', form_id);
toastr.success(mex);
} else {
toastr.error(resp.shortMessage);
console.error(resp.message);
}
modalLoader.removeClass('d-flex').addClass('d-none');
}
//Specializzo la funzione resetForm nel caso ci sia bisogno di campi TEXTAREA o immagini da resettare
function myResetForm(tipo, formid) {
resetForm(tipo, formid);
}
function edit(id) {
$('#save').attr('op', 'edit');
let dati = 'id=' + id;
let url = $(form_id).attr('data-get');
myResetForm('all', form_id);
$.getJSON(url, dati, function (resp) {
if (resp.success) {
populateForm(resp, form);
$(modal_id).modal('show');
} else {
toastr.error(resp.message);
}
});
}
$(document).ready(function () {
initFormComponents();
initTableFlotHeader();
})
.delegate('#new', 'click', function (link) {
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
$(modal_id).modal('show');
})
.delegate('#save', 'click', function (link) {
link.preventDefault();
let operation = $(this).attr('op');
let options = {
target: '#ErrorDescription',
beforeSubmit: beforeSubmit,
success: afterSubmit,
error: errorOnSubmit,
data: {
op: operation
},
dataType: 'json',
resetForm: false
};
$(form_id).ajaxSubmit(options);
})
.delegate('#edit,#editLink', 'click', function (link) {
link.preventDefault();
const id = $(this).parents('tr').attr('data-id');
edit(id);
})
.delegate('#delete', 'click', function (link) {
link.preventDefault();
const url = $(form_id).attr('data-delete');
let tr = $(this).parents('tr');
const cod = tr.attr('data-cod');
let id = tr.attr('data-id');
let message = 'Sei sicuro di voler eliminare definitivamente l\'elemento?';
if (confirm(message)) {
$.ajax({
type: 'POST',
url: url,
data: 'id=' + id + "&cod=" + cod,
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
toastr.success('Eliminazione effettuata con successo');
} else {
toastr.error(resp.message);
}
}
});
}
})
.delegate('#delete_select', 'click', function (link) {
link.preventDefault();
let message = 'Sei sicuro di voler eliminare definitivamente gli elementi selezionati?';
if (confirm(message)) {
let data = [];
$('#tablebody').find(':checkbox').each(function () {
if (this.checked) {
data.push($(this).val());
}
});
let url = $(this).attr('href');
$.ajax({
type: 'POST',
url: url,
data: {
data: data
},
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
var ids = resp.id;
for (var i = 0; i < ids.length; i++) {
var tr = $('#tablebody tr[data-id=' + ids[i] + ']');
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
}
} else {
toastr.error(resp.message);
}
$('#tablebody').find(':checkbox').iCheck('uncheck');
}
});
}
})
.delegate(modal_id,'hidden.bs.modal',function(link){
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
});
@@ -0,0 +1,316 @@
'use strict';
function beforeSubmit() {
modalLoader.removeClass('d-none').addClass('d-flex');
}
function errorOnSubmit() {
modalLoader.removeClass('d-flex').addClass('d-none');
}
function afterSubmit(resp) {
if (resp.success === 'invalid') {
showErrors(form_id, resp);
} else if (resp.success === true) {
let id;
let mex = '';
if (resp.op === 'insert') {
$('#tablebody').prepend(resp.text);
$('input#id').val(resp.data.id);
mex = 'Inserimento effettuato con successo';
id = resp.data.id;
} else {
$('tr[data-id=' + resp.id + ']').replaceWith(resp.text);
mex = 'Modifca effettuata con successo';
id = resp.id;
}
refreshFormComponents();
$('#norows').remove();
$(modal_id).modal('hide');
$('#save').attr('op', 'insert');
myResetForm('', form_id);
toastr.success(mex);
} else {
toastr.error(resp.shortMessage);
console.error(resp.message);
}
modalLoader.removeClass('d-flex').addClass('d-none');
}
//Specializzo la funzione resetForm nel caso ci sia bisogno di campi TEXTAREA o immagini da resettare
function myResetForm(tipo, formid) {
resetForm(tipo, formid);
}
function edit(id) {
$('#save').attr('op', 'edit');
let dati = 'id=' + id;
let url = $(form_id).attr('data-get');
myResetForm('all', form_id);
$.getJSON(url, dati, function (resp) {
if (resp.success) {
$('#main_contenitor').html(resp.text);
$(modal_id).modal('show');
} else {
toastr.error(resp.message);
}
});
}
$(document).ready(function () {
initFormComponents();
initTableFlotHeader();
})
.delegate('#new', 'click', function (link) {
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
$(modal_id).modal('show');
})
.delegate('#save', 'click', function (link) {
link.preventDefault();
var operation = $(this).attr('op');
var options = {
target: '#ErrorDescription',
beforeSubmit: beforeSubmit,
success: afterSubmit,
error: errorOnSubmit,
data: {
op: operation
},
dataType: 'json',
resetForm: false
};
$(form_id).ajaxSubmit(options);
})
.delegate('#edit,#editLink', 'click', function (link) {
link.preventDefault();
const id = $(this).parents('tr').attr('data-id');
edit(id);
})
.delegate('#delete', 'click', function (link) {
link.preventDefault();
const url = $(form_id).attr('data-delete');
let tr = $(this).parents('tr');
const cod = tr.attr('data-cod');
let id = tr.attr('data-id');
let message = 'Sei sicuro di voler eliminare definitivamente l\'elemento?';
if (confirm(message)) {
$.ajax({
type: 'POST',
url: url,
data: 'id=' + id + "&cod=" + cod,
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
toastr.success('Eliminazione effettuata con successo');
} else {
toastr.error(resp.message);
}
}
});
}
})
.delegate('#delete_select', 'click', function (link) {
link.preventDefault();
let message = 'Sei sicuro di voler eliminare definitivamente gli elementi selezionati?';
if (confirm(message)) {
let data = [];
$('#tablebody').find(':checkbox').each(function () {
if (this.checked) {
data.push($(this).val());
}
});
let url = $(this).attr('href');
$.ajax({
type: 'POST',
url: url,
data: {
data: data
},
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
var ids = resp.id;
for (var i = 0; i < ids.length; i++) {
var tr = $('#tablebody tr[data-id=' + ids[i] + ']');
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
}
} else {
toastr.error(resp.message);
}
$('#tablebody').find(':checkbox').iCheck('uncheck');
}
});
}
})
.delegate('select#state', 'change', function (link) {
link.preventDefault();
$('select#state').val($(this).val());
$('#searchForm').submit();
})
.delegate('#set-state','click',function (link) {
link.preventDefault();
var url = $(this).attr('data-url');
var tr = $(this).parents('tr');
var state = $(this).attr('data-state');
var id = tr.attr('data-id');
var message = 'Sei sicuro di voler modificare lo stato dell\'elemento?';
if (confirm(message)) {
$.ajax({
type: 'POST',
url: url,
data: 'id=' + id +'&state=' + state,
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
tr.replaceWith(resp.text);
refreshFormComponents();
} else {
alert(resp.message);
}
}
});
} else {
return;
}
})
.delegate('#setstate_select', 'click', function (link) {
link.preventDefault();
var url = $(this).attr('href');
var stateNum = null;
var data = [];
$('#tablebody').find(':checkbox').each(function () {
if (this.checked) {
data.push($(this).val());
}
});
if(data.length <= 0){
alert("Nessun elemento selezioanto");
return;
}
function confirmChoice() {
var val = $('select#selectState').val();
if(!val){
alert("E' necessario scegliere uno stato");
return;
}
stateNum = val;
dialog.dialog( "close" );
if (confirm("Sei sicuro di voler modificare lo stato degli elementi selezionati?")) {
$.ajax({
type: 'POST',
url: url,
data: {
data: data,
state:stateNum
},
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
var rows = resp.rows;
for (var i = 0; i < rows.length; i++) {
var tr = $('#tablebody tr[data-id=' + rows[i].id + ']');
tr.replaceWith(rows[i].tdRow);
}
$.growl({
type: 'success',
message: "Elementi aggiornati",
icon: 'fa fa-check fa-fw'
}, grownl_my_default_options);
} else {
$.growl({
type: 'danger',
message: resp.message,
icon: 'fa fa-times fa-fw'
}, grownl_my_default_options);
}
refreshFormComponents();
$('#tablebody').find(':checkbox').iCheck('uncheck');
}
});
}
}
var dialog = $('<div></div>')
.html(choicheHtmlModal)
.dialog({
title:"Scegli lo stato da impostare:",
autoOpen: false,
height: 200,
width: 350,
modal: true,
buttons: {
"OK": confirmChoice,
Cancel: function() {
$(this).dialog( "close" );
}
},
close: function() {
$(this).dialog( "destroy" );
}
});
dialog.dialog( "open" );
})
.delegate(modal_id,'hidden.bs.modal',function(link){
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
});
var choicheHtmlModal = `
<form>
<fieldset>
<select class="form-control" id="selectState" name="selectState">
<option value="1">New</option>
<option value="2">Pending</option>
<option value="3">Resolved</option>
<option value="4">Viewed</option>
</select>
</fieldset>
</form>`;
@@ -0,0 +1,114 @@
'use strict';
//Specializzo la funzione resetForm nel caso ci sia bisogno di campi TEXTAREA o immagini da resettare
function myResetForm(tipo, formid) {
resetForm(tipo, formid);
}
function edit(id) {
$('#save').attr('op', 'edit');
let dati = 'id=' + id;
let url = $(form_id).attr('data-get');
myResetForm('all', form_id);
$.getJSON(url, dati, function (resp) {
if (resp.success) {
$('#main_contenitor').html(resp.text);
$(modal_id).modal('show');
} else {
toastr.error(resp.message);
}
});
}
$(document).ready(function () {
initFormComponents();
initTableFlotHeader();
})
.delegate('#edit,#editLink', 'click', function (link) {
link.preventDefault();
const id = $(this).parents('tr').attr('data-id');
edit(id);
})
.delegate('#delete', 'click', function (link) {
link.preventDefault();
const url = $(form_id).attr('data-delete');
let tr = $(this).parents('tr');
const cod = tr.attr('data-cod');
let id = tr.attr('data-id');
let message = 'Sei sicuro di voler eliminare definitivamente l\'elemento?';
if (confirm(message)) {
$.ajax({
type: 'POST',
url: url,
data: 'id=' + id + "&cod=" + cod,
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
toastr.success('Eliminazione effettuata con successo');
} else {
toastr.error(resp.message);
}
}
});
}
})
.delegate('#delete_select', 'click', function (link) {
link.preventDefault();
let message = 'Sei sicuro di voler eliminare definitivamente gli elementi selezionati?';
if (confirm(message)) {
let data = [];
$('#tablebody').find(':checkbox').each(function () {
if (this.checked) {
data.push($(this).val());
}
});
let url = $(this).attr('href');
$.ajax({
type: 'POST',
url: url,
data: {
data: data
},
dataType: 'json',
complete: function (resp) {
resp = jQuery.parseJSON(resp.responseText);
if (resp.success) {
var ids = resp.id;
for (var i = 0; i < ids.length; i++) {
var tr = $('#tablebody tr[data-id=' + ids[i] + ']');
tr.animate({
'opacity': 'hide'
}, 500, function () {
tr.remove();
});
}
} else {
toastr.error(resp.message);
}
$('#tablebody').find(':checkbox').iCheck('uncheck');
}
});
}
})
.delegate(modal_id,'hidden.bs.modal',function(link){
link.preventDefault();
myResetForm('tutto', form_id);
$('#save').attr('op', 'insert');
});