Initial Commit
This commit is contained in:
@@ -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');
|
||||
});
|
||||
Reference in New Issue
Block a user