610 lines
16 KiB
JavaScript
610 lines
16 KiB
JavaScript
// 1.2.1
|
|
//11/10/2017 checkFields non più obbligatorio
|
|
//05/10/2016 corretto submit tabulazioneSuInvio
|
|
//14-01-2016 gestione automatica checkbox
|
|
//15-09-2014 connessione a _ablia.js
|
|
//17-07-2014 aggiungo checkBoxes su refresh
|
|
//15-07-2014 rimesso il submitaj su savecommand
|
|
//13-05-2014 corretto refresh()
|
|
//12-04-2014 aggiunto _callType per capire come comportarti in caso di caduta sessione
|
|
//09-04-2014 aggiunto submit su cancellazione immagini
|
|
//02-04-2014 corretto errore sul ritorno del salvataggio!!! non salvava l'id
|
|
//31-3-2014 versione iniziale
|
|
///////////////////////////////////////////////////
|
|
// SCRIPT COMUNI PER MASCHERE DI TIPO RICERCA E DETTAGLIO
|
|
///////////////////////////////////////////////////
|
|
|
|
window.onbeforeunload = function() {
|
|
return "Tutto il lavoro non salvato andra' perso!";
|
|
};
|
|
|
|
//*************************************************
|
|
//*************************************************
|
|
// ************ RICERCA **************************
|
|
//*************************************************
|
|
//*************************************************
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
//PULSANTE RICERCA SU MASCHERA DI RICERCA
|
|
///////////////////////////////////////////////////
|
|
function searching()
|
|
{
|
|
formSearching();
|
|
Ab.submitAj('main');
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
//RICERCA SU INVIO DELLA MASCHERA DI DETTAGLIO
|
|
///////////////////////////////////////////////////
|
|
function formSearching()
|
|
{
|
|
if(typeof checkBoxesCR != "undefined")
|
|
checkBoxesCR();
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#flgReport").val("");
|
|
$("#cmd", "#main").val("search");
|
|
$("#act","#main").val("");
|
|
$("#cmd2").val("");
|
|
$("#act2").val("");
|
|
$("#pageNumber").val("1");
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
//REPORT STANDARD. IN PRATICA FA UNA SEARCHING IMPOSTATO IL REPORT A S
|
|
///////////////////////////////////////////////////
|
|
function report()
|
|
{
|
|
//alert('pio');
|
|
//inutile adesso
|
|
//if(typeof checkBoxesCR != "undefined")
|
|
// checkBoxesCR();
|
|
swal({
|
|
title: "Report",
|
|
text: "Verra' creato un report in base ai criteri di ricerca selezionati. Sei Sicuro?",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonClass: "btn-danger",
|
|
confirmButtonText: "si",
|
|
cancelButtonText: "no",
|
|
closeOnConfirm: true,
|
|
closeOnCancel: true
|
|
},
|
|
function(isConfirm) {
|
|
if (isConfirm) {
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#flgReport").val("S");
|
|
$("#cmd", "#main").val("search");
|
|
$("#act","#main").val("");
|
|
$("#cmd2").val("");
|
|
$("#act2").val("");
|
|
$("#pageNumber").val("1");
|
|
Ab.submitAj('main');
|
|
} else {
|
|
|
|
}
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
//NUOVO RECORD DALLA PAGINA DI RICERCA
|
|
///////////////////////////////////////////////////
|
|
function newCommand()
|
|
{
|
|
//alert($("#actionPage").val());
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#cmd", "#main").val("ni");
|
|
Ab.submitAj('main');
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////
|
|
function modifyCommand(id)
|
|
{
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#cmd", "#main").val("md");
|
|
$("#act","#main").val("");
|
|
$("#cmd2").val("");
|
|
$("#act2").val("");
|
|
$("#"+$("#_id_name").val()).val(id);
|
|
Ab.submitAj('main');
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////
|
|
function deleteCommandCR(id,l_tmst)
|
|
{
|
|
swal({
|
|
title: "Sei sicuro?",
|
|
text: "I dati saranno cancellati. Vuoi continuare?",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "Si",
|
|
cancelButtonText: "No",
|
|
closeOnConfirm: true
|
|
}, function(){
|
|
if(typeof checkBoxesCR != "undefined")
|
|
checkBoxesCR();
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#cmd", "#main").val("asq");
|
|
$("#act","#main").val("delCR");
|
|
$("#lastUpdTmst").val("l_tmst");
|
|
$("#"+$("#_id_name").val()).val(id);
|
|
Ab.submitAj('main');
|
|
});
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////
|
|
function deleteCommandCRx(id)
|
|
{
|
|
if (Ab.confirmDelete())
|
|
{
|
|
if(typeof checkBoxesCR != "undefined")
|
|
checkBoxesCR();
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#cmd", "#main").val("asq");
|
|
$("#act","#main").val("delCR");
|
|
$("#"+$("#_id_name").val()).val(id);
|
|
Ab.submitAj('main');
|
|
}
|
|
|
|
}
|
|
|
|
//*************************************************
|
|
//*************************************************
|
|
// ************ DETTAGLIO ************************
|
|
//*************************************************
|
|
//*************************************************
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
//AGGIORNAMENTO DELLA PAGINA DI DETTAGLIO
|
|
///////////////////////////////////////////////////
|
|
function refresh()
|
|
{
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#cmd", "#main").val("md");
|
|
$("#act","#main").val("refresh");
|
|
if(typeof checkBoxes != "undefined")
|
|
checkBoxes();
|
|
Ab.submitAj('main');
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
// SALVATAGGIO DEL BEAN
|
|
///////////////////////////////////////////////////
|
|
function saveCommand(postProcess,async)
|
|
{
|
|
var pass=true;
|
|
if(typeof checkFields != "undefined")
|
|
pass=checkFields();
|
|
|
|
if (pass)
|
|
{
|
|
if(typeof checkBoxes != "undefined"){
|
|
checkBoxes();
|
|
}
|
|
formSaveCommand();
|
|
if(postProcess==null){
|
|
if($("#imgFile").length>0 && $("#imgFile").val()!="" || $("#cmd2").val()=="delImg")
|
|
$("#main").submit();
|
|
else{
|
|
//$("#main").submit();
|
|
Ab.submitAj('main');
|
|
//submitSaveAj(null,async)
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Ab.submitAj("main", null, null,postProcess,async);
|
|
//submitSaveAj(postProcess,async)
|
|
}
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
//SALVATAGGIO DEL BEAN SU INVIO
|
|
///////////////////////////////////////////////////
|
|
function formSaveCommand()
|
|
{
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#cmd", "#main").val("asq");
|
|
$("#act","#main").val("save");
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
//NUOVO RECORD DALLA PAGINA DI DETTAGLIO
|
|
///////////////////////////////////////////////////
|
|
function newCommandPD(evt)
|
|
{
|
|
if(evt!=undefined){
|
|
evt.preventDefault();
|
|
}
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
if(confirm("Nuovo Record. Vuoi salvare il record corrente?"))
|
|
{
|
|
/*
|
|
console.log(evt);
|
|
if(evt.stopPropagation)
|
|
{
|
|
evt.stopPropagation();
|
|
}
|
|
evt.cancelBubble=true;
|
|
*/
|
|
var pass=true;
|
|
if(typeof checkFields != "undefined")
|
|
pass=checkFields();
|
|
if (pass)
|
|
{
|
|
if(typeof checkBoxes != "undefined"){
|
|
checkBoxes();
|
|
}
|
|
$("#cmd", "#main").val("asq");
|
|
$("#act","#main").val("ni");
|
|
Ab.submitAj('main');
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$("#cmd", "#main").val("ni");
|
|
Ab.submitAj('main');
|
|
}
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
//CANCELLAZIONE RECORD
|
|
///////////////////////////////////////////////////
|
|
function deleteCommand()
|
|
{
|
|
|
|
swal({
|
|
title: "Sei sicuro?",
|
|
text: "I dati saranno cancellati. Vuoi continuare?",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#DD6B55",
|
|
confirmButtonText: "Si",
|
|
cancelButtonText: "No",
|
|
closeOnConfirm: true
|
|
}, function(){
|
|
$("#main").attr("action",$("#actionPage").val());
|
|
$("#cmd", "#main").val("asq");
|
|
$("#act","#main").val("del");
|
|
Ab.submitAj('main');
|
|
});
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////
|
|
// funzione simile alla Ab.submitAj
|
|
// ad hoc per la funzione save
|
|
// ritorna un json con id e timestamp
|
|
//////////////////////////////////////////////
|
|
function submitSaveAj(postProcess,async)
|
|
{
|
|
//gestione async
|
|
if(async!= undefined && async!=null){
|
|
$("#_async").val(async);
|
|
}
|
|
else
|
|
{
|
|
$("#_async").val("");
|
|
}
|
|
//comando per salvataggio json
|
|
$("#_callType").val("_json");
|
|
$("#act","#main").val("saveJson");
|
|
//
|
|
$.ajax({
|
|
type: "POST",
|
|
url: $("#main").attr("action"),
|
|
data: $("#main").serialize(),
|
|
dataType: 'html',
|
|
success: function (response) {
|
|
//leggo il json di ritorno e carico id e timestamp
|
|
var jObj = $.parseJSON(response);
|
|
//leggo lo stato
|
|
//Se è false, effetto un ricarico del
|
|
//bean
|
|
if(jObj.status==false)
|
|
{
|
|
$('#messaggi').fadeIn();
|
|
$("#messaggi").html(jObj.msg);
|
|
//blocco la pagina sfruttando il parametro async
|
|
//basta mettere qualcosa !=false
|
|
$('#_async').val("load");
|
|
//lancio tra n secondi il ricarico della pagina
|
|
setTimeout( "modifyCommand("+jObj._id+")",5000 );;
|
|
}
|
|
else
|
|
{
|
|
//metto i dati necessari
|
|
$("#_id").val(jObj._id);
|
|
$("#"+$("#_id_name").val()).val(jObj._id);
|
|
$("#lastUpdTmst").val(jObj.lastUpdTmst);
|
|
$("#lastUpdInfo").html(jObj.lastUpdInfo);
|
|
//messaggi
|
|
$('#messaggi').fadeIn();
|
|
$("#messaggi").html(jObj.msg+".");
|
|
var msgInterval=setTimeout( "$('#messaggi').fadeOut(200);msgGone=true",10000 );
|
|
//focus
|
|
//alert($("#currentFocus").val());
|
|
Ab.setFocus($("#currentFocus").val());
|
|
//postprocess
|
|
if(postProcess != undefined && postProcess!=null){
|
|
Ab.executeProcess(postProcess);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
//********************************************************
|
|
//********************************************************
|
|
//Metodo per gestire le checkbox
|
|
//
|
|
// N.B. Per convenzione tutti i name e gli id delle checkbox devono avere "ck" all'inizio
|
|
// Ci vuole anche una input che non hai il "ck" ma che ha name e id uguali alla checkbox
|
|
//********************************************************
|
|
//********************************************************
|
|
|
|
$(":checkbox").on("ifChecked", null, null, function () {
|
|
// trovo l'input collegato alla checkbox
|
|
var name = $(this).attr("name").replace("ck", "");
|
|
|
|
// controllo lo stato della checkbox e valorizzo la input
|
|
if ($(this).is(":checked"))
|
|
{
|
|
$("#" + name).val(1);
|
|
}
|
|
else
|
|
{
|
|
$("#" + name).val(0);
|
|
}
|
|
});
|
|
|
|
$(document).on("click", "input:checkbox[name^=ck]", function()
|
|
{
|
|
// trovo l'input collegato alla checkbox
|
|
var name = $(this).attr("name").replace("ck", "");
|
|
|
|
// controllo lo stato della checkbox e valorizzo la input
|
|
if ($(this).is(":checked"))
|
|
{
|
|
$("#" + name).val(1);
|
|
}
|
|
else
|
|
{
|
|
$("#" + name).val(0);
|
|
}
|
|
});
|
|
|
|
//********************************************************
|
|
//********************************************************
|
|
//gestione tasto esc
|
|
//********************************************************
|
|
//********************************************************
|
|
$(document).on("keydown",function(e) // ,:not(.ajSearchText)
|
|
{
|
|
//console.log("bean.js onkeydown "+e.keyCode);
|
|
var focused = $(':focus');
|
|
//console.log("focused: "+focused);
|
|
|
|
if (!focused.hasClass("ajSearchText"))
|
|
{
|
|
if(e.keyCode===27){
|
|
//escape
|
|
//gestione comando per tornare indietro
|
|
if($("#pageType").val()=="D"){
|
|
if(typeof backEscape == 'function')
|
|
{
|
|
backEscape();
|
|
}
|
|
else
|
|
{
|
|
Ab.dashboard();
|
|
}
|
|
}
|
|
else if($("#pageType").val()=="R"){
|
|
if(typeof backEscapeCR == 'function')
|
|
{
|
|
backEscapeCR();
|
|
}
|
|
else
|
|
{
|
|
Ab.dashboard();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
//tasti FUNZIONE che non uso un ahasSearchText
|
|
if(e.keyCode===112)
|
|
{
|
|
//tasto F1 help generico
|
|
$('.input-sm').each(function(){
|
|
//alert($(this));
|
|
$(this).popover("hide");
|
|
focused.attr("title","");
|
|
}
|
|
);
|
|
|
|
|
|
Ab.fetch4("../config/Help.abl", "cmd=fetchTableHelp&id_name="+$("#_id_name").val()+"&fieldName="+focused.attr("id"), null, function(response){
|
|
if (response && response.trim() != "") {
|
|
$(".help-body").html(response);
|
|
$(".help-body").load("../menu/Help.abl?cmd=");
|
|
$("#modalHelp").modal('show').draggable({ handle: ".modal-header" });
|
|
}
|
|
},false);
|
|
|
|
}
|
|
else
|
|
if(e.keyCode===113)
|
|
{
|
|
//TASTO F2 -- HELP =""
|
|
//$('.input-sm').popover("hide");
|
|
$('.input-sm').each(function(){
|
|
//alert($(this));
|
|
$(this).popover("hide");
|
|
focused.attr("title","");
|
|
}
|
|
);
|
|
|
|
//su _id_name ho il nome dell'id della pagina id_xxxxx
|
|
focused.attr("data-placement","top");
|
|
focused.attr("title","Help");
|
|
|
|
Ab.fetch4("../config/Help.abl", "cmd=fetchFieldHelp&id_name="+$("#_id_name").val()+"&fieldName="+focused.attr("id"), null, function(response){
|
|
if (response && response.trim() != "") {
|
|
focused.attr("data-content",response);
|
|
focused.popover('toggle');
|
|
focused.attr("title","");
|
|
}
|
|
},false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
//********************************************************
|
|
//********************************************************
|
|
//gestione tasto invio
|
|
// bind su input e select
|
|
//********************************************************
|
|
//********************************************************
|
|
$(document).on("keydown","input,select",function(e) // ,:not(.ajSearchText)
|
|
{
|
|
if (!$(this).hasClass("ajSearchText")) {
|
|
if(e.keyCode===13){
|
|
tabulazioneSuInvio(this);
|
|
}
|
|
}
|
|
});
|
|
|
|
//********************************************************
|
|
//********************************************************
|
|
//gestione tasto invio
|
|
// bind su select2
|
|
//********************************************************
|
|
//********************************************************
|
|
$(document).on("select2:select",".select2", function (e) {
|
|
|
|
|
|
tabulazioneSuInvio(this);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
//********************************************************
|
|
//********************************************************
|
|
//gestione campo autofocus sul caricamento pagina
|
|
//********************************************************
|
|
//********************************************************
|
|
$(document).on("focus","input[autofocus]",function(e) // ,:not(.ajSearchText)
|
|
{
|
|
$(this).select();
|
|
});
|
|
|
|
|
|
//********************************************************
|
|
//********************************************************
|
|
// parte principale di gestione tabulazione su invio
|
|
//se aggiungo submit mi fa la submit form
|
|
//********************************************************
|
|
//********************************************************
|
|
function tabulazioneSuInvio(that)
|
|
{
|
|
//submit
|
|
if(that.hasAttribute("submit"))
|
|
{
|
|
Ab.submitForm();
|
|
}
|
|
else
|
|
{
|
|
//campo successivo
|
|
if($(that).attr("nextFocus"))
|
|
{
|
|
//console.log($(that).attr("nextFocus"));
|
|
//console.log($("#"+ $(that).attr("nextFocus")).val());
|
|
|
|
//passo al campo successivo
|
|
if($("#"+ $(that).attr("nextFocus")).hasClass("numberInput"))
|
|
{
|
|
$("#"+ $(that).attr("nextFocus")).select();
|
|
$("#"+ $(that).attr("nextFocus")).focus();
|
|
}
|
|
else
|
|
{
|
|
$("#"+ $(that).attr("nextFocus")).select();
|
|
$("#"+ $(that).attr("nextFocus")).focus();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//console.log($(that).attr("id"));
|
|
|
|
//next field
|
|
Ab.setFocusNextField($(that).attr("id"));
|
|
}
|
|
}
|
|
}
|
|
//********************************************************
|
|
//********************************************************
|
|
// attesa sulle chiamate ajax sincrone
|
|
//********************************************************
|
|
//********************************************************
|
|
$(document).on({
|
|
ajaxStart: function() {
|
|
if($('#_async').val()==="" || $('#_async').val()==="false"){
|
|
$("body").addClass("loading");
|
|
}
|
|
else
|
|
{
|
|
//alert('pio');
|
|
}
|
|
|
|
},
|
|
ajaxStop: function() {
|
|
if($('#_async').val()==="" || $('#_async').val()==="false"){
|
|
$("body").removeClass("loading");
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
//********************************************************
|
|
//********************************************************
|
|
// GESTISCE currentTab PER LE TABS
|
|
//********************************************************
|
|
//********************************************************
|
|
//salva l'href ogni volta che cambio tab
|
|
$(document).on('shown.bs.tab', function(event) {
|
|
|
|
if($('#currentTab').length>0 )
|
|
{
|
|
$('#currentTab').val($(event.target).attr('href'));
|
|
}
|
|
});
|
|
|
|
|
|
|