/**
* @param {String} url
* @param {Object} data
* @param {Function} onSuccess
* @param {array} params
* @param {Function} onError
* @return void
*/
var _isLock = false;
function setSelect2ajaxValue($uiSelect, data, id, formatSelect){
let newOption = new Option('', id, true, true);
$uiSelect.html(newOption);
setTimeout(function(){
$uiSelect.next().find('.select2-selection__rendered').html(formatSelect(data));
},100);
}
function setSelect2Value($ui, data, id, formatSelect){
let newOption = new Option('', id, true, true);
$ui.html(newOption);
setTimeout(function(){
$ui.next().find('.select2-selection__rendered').html(formatSelect(data));
},100);
}
function setSelect2ValuePopolaGui($uiSelect, id, label, optSelect2){ //** da usare per la 2.14, cambiato nome per mantenere il progresso in prod
if ($uiSelect.length == 0){
return;
}
if ($uiSelect.html().indexOf('value="'+id+'"') === -1 ){
$uiSelect.html($uiSelect.html() + '');
}
$uiSelect.val(id).select2(optSelect2);
}
/**
* @param selettore
* @return oggetto con value e text oppure null se non c'è nulla selezionato
*/
function getSelect2ValuePopolaBusiness($uiSelect){ //** da usare per la 2.14, cambiato nome per mantenere il progresso in prod
let objOut = {};
if ($uiSelect.length == 0){
return null;
}
objOut.value = $uiSelect.find('option:disabled:selected').val();
objOut.text = $uiSelect.find('option:disabled:selected').text();
if (objOut.value === undefined){
objOut.value = !$uiSelect.val() ? 0 : $uiSelect.val();
objOut.text = $uiSelect.find('option:selected').text();
}
return objOut;
}
function getSelect2Value($uiSelect){
if ($uiSelect.length == 0){
return;
}
let id = $uiSelect.find('option:disabled:selected').val();
if (id === undefined){
id = !$uiSelect.val() ? 0 : $uiSelect.val();
}
return id;
}
function getSelectMultiValue($uiSelect){
let listaId = [];
$uiSelect.find('option:disabled:selected').each(function(){
listaId.push($(this).val());
});
if (listaId.length > 0){
return listaId.concat($uiSelect.val());
}else{
return $uiSelect.val();
}
}
function $ajaxFly(tabella, textAlertCheck, textAlertLoading, keyCookies, url, data, onSuccess, params, onError) { //** ajax senza LocalStorage
var params = params || [];
var onError = onError || null;
if ($('#os-screen-wait').css("display") != "block") {
onShowWait('Controllo aggiornamento ' + textAlertCheck);
} else {
setShowWaitLabel('Controllo aggiornamento ' + textAlertCheck);
}
if (_isLock) {
console.log('Attenzione: ho avuto una chiamata a ' + url + ' senza aver esaudito la precedente richiesta ' + _precendenteRichiesta);
}
if (!_isLock) {
_isLock = true;
$ajax("../services/transitionjson/gestionesalcef_transition.php", "m=getUltimoAggiornamento&tabella=" + tabella, function (objResult) {
var or = objResult;
timestampServer = or.obj;
ts = Cookies.get(keyCookies)
_isLock = false;
if (!isNaN(ts) && ts == timestampServer) {
var or = objResult;
or.obj = null;
or.message = GlobalConstants.AJAX_FLY_NESSUN_CAMBIAMENTO;
onSuccess(or, params);
} else {
var txt = "Sto aggiornando " + textAlertLoading + "...";
if (isNaN(ts)) {
txt = "Sto caricando " + textAlertLoading + "...";
}
setShowWaitLabel(txt);
_precendenteRichiesta = url;
$ajax(url, data, function (dataResult) {
Cookies.set(keyCookies, timestampServer)
onSuccess(dataResult);
}, params, function (data) {
if (onError != null)
onError(data);
else
fault(data);
});
}
}, [], function (data) {
_isLock = false;
if (onError != null)
onError(data);
else
fault(data);
});
}
}
function $ajax(url, data, onSuccess, params, onError,timeout) {
var params = params || [];
var onError = onError || null;
var timeout = timeout || 60;
$.ajax({
type: "POST",
url: url,
data: data,
timeout: timeout * 1000,
success: function (data){CommonUi.successAjax(data,onSuccess,params,onError)},
error: function(jqXHR, textStatus, errorThrown){ CommonUi.errorAjax(jqXHR, textStatus, errorThrown, onError)}
});
}
function $ajaxPostData(url, postData, onSuccess, params, onError, textProgress, textProgressComplete) {
var params = params || [];
var onError = onError || null;
var textProgress = textProgress || null;
var textProgressComplete = textProgressComplete || '';
$.ajax({
type: "POST",
url: url,
data: postData,
dataType: "json",
cache: false,
timeout: 10 * 60 * 1000,
xhr: function(){var myXhr = $.ajaxSettings.xhr(); return CommonUi.xhrAjax(myXhr, textProgress, textProgressComplete);},
success: function (data){CommonUi.successAjax(data,onSuccess,params,onError)},
error: function(jqXHR, textStatus, errorThrown){ CommonUi.errorAjax(jqXHR, textStatus, errorThrown, onError)}
});
}
//function $ajaxPromise(url, data, params) {
// var params = params || [];
//
// return new Promise( (resolve, reject) => {
// $.ajax({
// type: "POST",
// url: url,
// data: data,
// timeout: 30 * 1000,
// success: function (data){
// if (data != null) {
// if (data.messageError == '') {
//// params.unshift(data); // TODO
// resolve(data);
// } else if (data != null && data.messageError === undefined) {
// reject('Error in transition');
// } else if (data != null && data.messageError != '') {
// reject(data.messageError);
// }
// } else {
// reject('Unexpected error');
// }
//
// },
// error: function(jqXHR, textStatus, errorThrown){
// reject(jqXHR, textStatus, errorThrown);
//
// }
// });
// });
//}
//function PromiseQueue() {
// var promise = $.Deferred().resolve();
//
// return {
// push: function(fn) {
// promise = promise.then(fn, fn);
// return this;
// }
// };
//};
/**
* @param {String} url
* @param {Object} data
* @param {Function} onSuccess
* @param {array} params
* @param {Function} onError
* @return void
*/
function $ajaxFormData(url, formData, onSuccess, params, onError, textProgress, textProgressComplete) {
var params = params || [];
var onError = onError || null;
var textProgress = textProgress || null;
var textProgressComplete = textProgressComplete || '';
$.ajax({
type: "POST",
url: url,
data: formData,
contentType: false,
cache: false,
processData: false,
timeout: 10 * 60 * 1000,
xhr: function(){var myXhr = $.ajaxSettings.xhr(); return CommonUi.xhrAjax(myXhr, textProgress,textProgressComplete);},
success: function (data){CommonUi.successAjax(data,onSuccess,params,onError)},
error: function(jqXHR, textStatus, errorThrown){ CommonUi.errorAjax(jqXHR, textStatus, errorThrown, onError)}
});
}
function fault(text, codeError) {
codeError = codeError || null;
if (codeError == 300){
noty({
text: text,
type: 'error',
timeout:CommonUi.getTimeout(text),
callback: {
afterClose: function() {location.reload();},
},
});
}else{
noty({text: text,type: "error",timeout:CommonUi.getTimeout(text)});
}
onHideWait();
}
function onShowWait(label) {
var label = label || '';
$('#os-screen-wait').css("display", "block");
$('#os-screen-wait-label').css("display", "block");
$('#os-screen-wait-label').html(label);
}
function setShowWaitLabel(label) {
console.log('setShowWaitLabel = ' + label)
var label = label || '';
$('#os-screen-wait-label').html(label);
}
function onHideWait() {
$('#os-screen-wait').css("display", "none");
$('#os-screen-wait-label').css("display", "none");
}
function onShowWaitProgress(text, formName, textSuccess) {
var textSuccess = textSuccess || '';
setTimeout(function () {
var perc = $.ajax({
type: "POST",
url: "../phplets/progress.php",
data: {formName: formName},
timeout: 30 * 1000,
async: false
}).responseText;
if (perc < 100) {
$('#os-screen-wait-label').html(text + perc + '%');
onShowWaitProgress(text, formName);
} else {
$('#os-screen-wait-label').html(textSuccess);
}
}, 500);
}
function onSubmitAllegato() {
onShowWait(_('Caricamento') + '... ');
onShowWaitProgress(_('Caricamento') + '... ', 'file');
}
function removeTooltip(){
$('.tooltip').remove();
}
$('html').click(removeTooltip);
var CommonUi = function (){
var listaEventi=[];
return {
contentHeight:0,
// Arguments :
// verb : 'GET'|'POST'
// target : an optional opening target (a name, or "_blank"), defaults to "_self"
openWindow : function(verb, url, data, target) {
var form = document.createElement("form");
form.action = url;
form.method = verb;
form.target = target || "_self";
if (data) {
for (var key in data) {
var input = document.createElement("textarea");
input.name = key;
input.type = 'hidden';
input.value = typeof data[key] === "object" ? JSON.stringify(data[key]) : data[key];
form.appendChild(input);
}
}
form.style.display = 'none';
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
},
showSmallDialog: function(txt, fun, id){
id = id || null;
CommonUi.$_rimuoviTuttiEventiDaElement('click', '#btnMessaggioConferma');
CommonUi.$_on(document, 'click', '#btnMessaggioConferma', fun);
$('#bx-messaggio-testo').html(txt);
$('#d-messaggio').modal('show');
if (id != null){
$('#btnMessaggioConferma').attr('data-id',id);
}
},
getDomFromComment: function ($container) {
var dom = $container.contents().filter(function() {return this.nodeType === 8;}).get(0).nodeValue;
return dom;
},
getGuiCarousel : function (listaBxAllegato, isPopolaGui, idName){
isPopolaGui = isPopolaGui || false;
idName = idName || 'carousel';
let a, i, n = listaBxAllegato.length;
let activeId = isPopolaGui ? 0 : (n-1);
let numShowedThumb = 6;
if (n == 0){
return '';
}
let dataTarget = '', dataItem = '', dataThumb='
';
for(i=0; i < n; i++){
a = listaBxAllegato[i].obj;
dataTarget += '
';
dataItem += '
'; //** test http://placehold.it/1000x800?text=Product+01
if (i > 0 && i % numShowedThumb == 0){
dataThumb += '
';
}
dataThumb += '
';
}
dataThumb += '
';
var tpl = CommonUi.getDomFromComment($( "#tmpl-slider" ));
tpl = tpl.replace('[dataThumb]',dataThumb);
if (n > 1){
tpl = tpl.replace('[dataTarget]',''+dataTarget+'
');
tpl = tpl.replace('[dataControl]',
'\
\
Precedente\
\
\
\
Successivo\
'
);
}else{
tpl = tpl.replace('[dataControl]','');
tpl = tpl.replace('[dataTarget]','');
}
tpl = tpl.replace('[dataItem]',dataItem);
return tpl;
},
setDivEnabled: function ($div, value) {
$div.find('label').each(function () {
$(this).css('opacity', (value ? 1 : 0.5));
});
$div.find('.chosen-select').each(function () {
$(this).prop('disabled', !value).trigger("chosen:updated");
});
$div.find('input').each(function () {
$(this).prop('disabled', !value);
});
$div.find('.checker').each(function () {
if (value) {
$(this).removeClass('disabled');
} else {
$(this).addClass('disabled');
}
});
$div.find('.btn').each(function () {
if (value) {
$(this).removeClass('disabled');
} else {
$(this).addClass('disabled');
}
});
$div.find('.fileinput-filename').each(function () {
if (value) {
$(this).removeClass('disabled');
} else {
$(this).addClass('disabled');
}
});
$div.find('.close.fileinput-exists').each(function () {
if (value) {
$(this).removeClass('disabled');
} else {
$(this).addClass('disabled');
}
});
$div.find('.datepicker2 .input-group-addon').each(function () {
if (value) {
$(this).off('click', onShowDatepicket);
$(this).on('click', onShowDatepicket);
$(this).css('opacity', 1);
$(this).css('cursor', 'pointer');
} else {
$(this).off('click', onShowDatepicket);
$(this).css('opacity', 0.5);
$(this).css('cursor', 'auto');
}
});
$div.find('.radio').each(function () {
console.log($(this))
});
//**TODO radio, number, ecc..
},
onSuccessAllegato:function($ui, url, nomeOriginale, dataUploaded){
// onSuccessAllegato:function($ui, url, nomeOriginale, dataUploaded, destination){
// var destination = destination || 'show';
var inputFile = $ui.find('input[type="file"]');
var ss = inputFile.data('callback-success');
var rr = inputFile.data('callback-remove');
var $btnSfoglia = $ui.find('.fileinput-btn');
$btnSfoglia.addClass('hidden d-none');
$btnSfoglia.after('');
$btnSfoglia.after('');
$ui.find('.btnRemove').on('click',function(){
$btnSfoglia.removeClass('hidden d-none');
setTimeout(function (){//** messo setTimeout altrimenti il remove non esegue evento dopo la cancellazione, come il metodo setHasDoneChanged
$ui.find('.btnRemove').remove();
$ui.find('.btnShow').remove();
if(!!rr){
eval(rr+'($ui)');
}
$ui.find('.btnRemove').off('click');
$ui.find('.btnShow').off('click');
},10);
});
$ui.find('.btnShow').on('click',function(){
// if (destination == 'media') CommonUi.openWindow('GET', '/media/' + url, {}, '_blank');
// else CommonUi.openWindow('POST', '/show', {path: url, nome_file:nomeOriginale}, '_blank');
CommonUi.openWindow('GET', url, {}, '_blank')
});
$ui.tooltip();
if(!!ss){
eval(ss+'(dataUploaded, $ui)');
}
},
resetValidate:function(){
$(".evidenzia-campo-obbligatorio").removeClass("evidenzia-campo-obbligatorio");
$(".evidenzia-testo-obbligatorio").removeClass("evidenzia-testo-obbligatorio");
$(".info-errore").remove();
},
setFieldUpdated:function(e, $ui){//** viene utilizzato per aggiornare la data GS per il computer di bordo
e = e || null;
$ui = $ui || null;
var classRow = '.bx-row';
if (e != null ){
$ui = $(this).closest(classRow);
}else if ($ui != null){
$ui.closest(classRow);
}else{
console.log('Definisci i paramentri correttamente')
}
$ui.addClass('row-updated');
},
isFieldUpdated:function($ui, $uiParent){
$ui = $ui || null;
$uiParent = $uiParent || null;
var classRow = '.bx-row';
if ($ui != null){
return $ui.closest(classRow).hasClass('row-updated');
}else if ($uiParent != null){
return $uiParent.hasClass('row-updated');
}else{
console.log('Definisci i paramentri correttamente')
}
},
removeAllFieldUpdated:function(){
$('.row-updated').removeClass('row-updated');
},
popolaGuiAllegato:function(allegato, $ui){
$ui.find('.fileinput-btn').removeClass('hidden d-none');
$ui.find('.btnShow').remove();
$ui.find('.btnRemove').remove();
if (allegato.nome != ''){
data = {};
data.fileName = allegato.nome;
data.fileExtension = allegato.estensione;
data.originalFileName = allegato.nomeOriginale;
data.size = allegato.size;
data.path = allegato.path;
data.media = allegato.media;
data.allegato = allegato; //** quando esiste questa proprietà faccio capire al client che sto facendo un popolaGUI
CommonUi.onSuccessAllegato($ui, allegato.media, allegato.nomeOriginale, data);
}
},
isVisibleInScroll : function (element, fullyInView) {
fullyInView = fullyInView || true;
var pageTop = $(window).scrollTop();
var pageBottom = pageTop + $(window).height();
var elementTop = $(element).offset().top;
var elementBottom = elementTop + $(element).height();
if (fullyInView === true) {
return ((pageTop < elementTop) && (pageBottom > elementBottom));
} else {
return ((elementTop <= pageBottom) && (elementBottom >= pageTop));
}
},
getBuildComboOption: function (){
return {
listaProprietaDescrizione: null,
listaProprietaTooltip: null,
separatore: null,
proprietaId: null,
listaProprietaData: null,
isValueSuffix :false,
selectedIdClassName:'',
isMulti: false,
isAllowClear:true, //** vale solo per select2, TODO per multiselect
}
},
buildCombo: function(lista, $ui, selectedId, option){
selectedId = selectedId || null;
option = option || null;
if (option === null){
option = CommonUi.getBuildComboOption();
}
let listaProprietaDescrizione = option.listaProprietaDescrizione || null;
let listaProprietaTooltip = option.listaProprietaTooltip|| null;
let separatore = option.separatore|| null;
let separatoreTooltip = option.separatoreTooltip|| null;
let proprietaId = option.proprietaId|| null;
let listaProprietaData = option.listaProprietaData|| null;
let isValueSuffix = option.isValueSuffix || false
let selectedIdClassName = option.selectedIdClassName || '';
let isMulti = option.isMulti || false;
let isAllowClear = option.isAllowClear || true;
let sspp;
if (isValueSuffix && selectedId != null && selectedIdClassName == ''){
console.log('Attenzione: devi valorizzare selectedIdClassName!')
}
if (listaProprietaDescrizione === null ){
listaProprietaDescrizione = ['descrizione'];
}
if (proprietaId === null){
proprietaId='id';
}
if (separatore === null){
separatore = ' ';
}
if (separatoreTooltip === null){
separatoreTooltip = ' ';
}
let i,n,j,m, opt, desc='', aa, bb, tooltip;
let k, kk, lpt=0, dataTxt;
// if (isMulti){
opt = '';
// }else{
// opt = '';
// }
n = lista.length;
m = listaProprietaDescrizione.length;
if (listaProprietaTooltip !== null ){
lpt = listaProprietaTooltip.length;
}
for (i=0; i < n; i++){
aa = [];
bb = [];
for(j=0; j < m; j++){
aa.push(lista[i][listaProprietaDescrizione[j]]);
}
for(k=0; k < lpt; k++){
bb.push(lista[i][listaProprietaTooltip[k]]);
}
desc = aa.join(separatore);
if (listaProprietaTooltip !== null ){
tooltip = bb.join(separatoreTooltip);
}else{
tooltip = desc;
}
opt += '';
}
$ui.html(opt);
$ui.val(null);
if (isMulti){
if (!!selectedId){
$ui.val(selectedId+selectedIdClassName);
}
$ui.multiselect('rebuild');
}else{
if (!!selectedId){
$ui.val(selectedId+selectedIdClassName);
}
$ui.select2(isAllowClear ? optSelect2AllowClear : optSelect2);
}
},
buildComboAddValueSuffix : function(lista, $ui, selectedId, selectedIdClassName, option){
option = option || null;
if (option === null){
option = CommonUi.getBuildComboOption();
}
option.isValueSuffix=true;
option.selectedIdClassName = selectedIdClassName;
CommonUi.buildCombo(lista, $ui, selectedId, option);
},
buildComboDenyClear : function(lista, $ui, selectedId, option){
option = option || null;
if (option === null){
option = CommonUi.getBuildComboOption();
}
option.isAllowClear=false;
CommonUi.buildCombo(lista, $ui, selectedId, option);
},
buildComboMulti : function(lista, $ui, selectedId, option){
option = option || null;
if (option === null){
option = CommonUi.getBuildComboOption();
}
option.isMulti=true;
CommonUi.buildCombo(lista, $ui, selectedId, option);
},
progressHandlingFunction: function (e, textProgress, textProgessComplete) {
var textProgress = textProgress || '';
var textProgessComplete = textProgessComplete || null;
if (e.lengthComputable) {
var perc = e.loaded < e.total ? Math.ceil(e.loaded / e.total * 100) : 100;
$('#os-screen-wait-label').html(textProgress + perc + '%');
if (textProgessComplete != '' && perc == 100){
$('#os-screen-wait-label').html(textProgessComplete);
}
}
},
xhrAjax:function (myXhr, textProgress, textProgessComplete) { // Custom XMLHttpRequest
var textProgress = textProgress || null;
var textProgessComplete = textProgessComplete || null;
if (textProgress != null && myXhr.upload) { // Check if upload property exists
if ($('#os-screen-wait').css("display") != "block") {
onShowWait('');
}
myXhr.upload.addEventListener('progress', function (e) {
CommonUi.progressHandlingFunction(e, textProgress, textProgessComplete);
}, false); // For handling the progress of the upload
}
return myXhr;
},
successAjax: function (data, onSuccess, params, onError) {
params = params || [];
onError = onError || null;
if (data != null) {
if (data.messageError == '' && data.codeError == 0) {
params.unshift(data);
onSuccess.apply(this, params);
} else if (data != null && data.messageError === undefined) {
if (onError == null) {
fault('Error in transition');
} else {
onError('Error in transition');
}
} else if (data != null && (data.messageError != '' || data.codeError != 0)) {
if (onError == null) {
fault(data.messageError, data.codeError, data.data);
} else {
onError(data.messageError, data.codeError, data.data);
}
}else{
if (onError == null) {
fault('Error in transition');
} else {
onError('Error in transition');
}
}
} else {
if (onError == null) {
fault('Unexpected error');
} else {
onError('Unexpected error');
}
}
},
errorAjax: function (jqXHR, textStatus, errorThrown, onError) {
var onError = onError || null;
if (onError == null) {
fault('Call failed: ' + textStatus + " / " + errorThrown);
} else {
onError(textStatus, errorThrown);
}
},
checkExist: function(value,tag){
var tag, attr;
if (tag == 'js'){
tag = 'script';
attr = 'src'
}else{
tag = 'link';
attr = 'href'
}
$(tag).each(function () {
var _this = $(this);
if (_this.attr("src") != undefined && _this.attr(attr).indexOf(value) != -1) {
return true;
}
});
return false;
},
Option : function() {
this.listaJs=[];
this.listaCss=[];
this.typeJs='text/javascript';
this.typeCss='text/css';
},
getUid : function (){
var dt = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (dt + Math.random()*16)%16 | 0;
dt = Math.floor(dt/16);
return (c=='x' ? r :(r&0x3|0x8)).toString(16);
});
return uuid;
},
load: function (option){
var option = option || null;
var listaCss, listaJs;
if (option == null){
option = new CommonUi.Option();
}
listaCss = option.listaCss;
listaJs = option.listaJs;
typeJs = option.typeJs;
typeCss = option.typeCss;
var i, n;
var id, js = '', css = '';
if (listaCss.length > 0){
n = listaCss.length;
for(i=0; i\n';
}else{
css += '\n';
}
}
$('head').append(css);
}
if (listaJs.length > 0){
n = listaJs.length;
for(i=0; i\n';
}
$('script:last').after(js);
}
},
unload: function (option){
var listaJs = listaJs || [];
var listaCss = listaCss || [];
var i, n = listaJs.length;
var id, js = '', css = '';
for(i=0; i < n; i++){
id = listaJs[i].replace(/^.*[\\\/]/, '');
$('#'+id).remove();
}
n = listaCss.length;
for(i=0; i < n; i++){
id = listaCss[i].replace(/^.*[\\\/]/, '')
$('#'+id).remove();
}
},
getTooltipTable: function (value, maxLength){
value = value || null;
maxLength = maxLength || 0;
if (value == null || value == ''){
return '';
}
if (maxLength === 0){
return ''+value+'';
}else if (value.length > maxLength){
return ''+value.substring(0,maxLength-3)+'...';
}else{
return value;
}
},
setWidthTable: function (dataTable, listaObj, $ui){ //[{targets:0, width:"200px"}]
var trg, obj, i, n = listaObj.length;
$ui = $ui || null;
if ($ui == null){
$ui = $('#bx-table');
}
for(i=0; i < n; i++){
obj = listaObj[i];
trg = obj.targets + 1;
$ui.find('table th:nth-child('+trg+')').each(function(){
$(this).css('width',obj.width).css('min-width',obj.width).css('max-width',obj.width);
});
$ui.find('table td:nth-child('+trg+')').each(function(){
$(this).css('width',obj.width).css('min-width',obj.width).css('max-width',obj.width);
});
}
dataTable.DataTable().columns.adjust().draw();
},
getEllipsis: function(value, width){
width = width || null;
var ss = '';
if (width != null){
ss = 'style="width:'+width+'px"';
}
return ''+ value +'
';
},
getCommonOptModal: function(){
return {
title: "titolo",
message: "messaggio",
draggable: true,
nl2br: false, //** true sostituisce \n con
closable: true,
closeByBackdrop: false,
size: BootstrapDialog.SIZE_WIDE,
onshow: function (dialogRef){
var $ui = $(dialogRef.getModalBody());
$ui.append('')
},
onshown: function(dialogRef){
CommonUi.modalResize(dialogRef);
$(dialogRef.getModalBody()).find('.modal-body-wait').remove();
},
};
},
getCommonOptPercentDigits2: function() {
return {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: '',
minimumValue: 0.00,
maximumValue: 100.00,
}
},
getCommonOptYear: function() {
return {
digitGroupSeparator: '',
decimalPlaces:0,
minimumValue: 0,
maximumValue: 9999,
}
},
getCommonOptIntegerWithoutSeparetor: function() {
return {
digitGroupSeparator: '',
minimumValue: 0,
maximumValue: 999999999,
decimalPlaces:0,
}
},
getCommonOptInteger: function() {
return {
digitGroupSeparator: '.',
decimalCharacter: ',',
minimumValue: 0,
maximumValue: 999999999,
decimalPlaces:0
}
},
getCommonOptIntegerDigits3: function() {
return {
digitGroupSeparator: '.',
decimalCharacter: ',',
minimumValue: 0,
maximumValue: 999,
}
},
getCommonOptCurrencyWithNegative: function() { //** da cambiare in getCommonOptDecimal2WithNegative
return {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: '',
minimumValue: -999999999.99,
maximumValue: 999999999.99,
}
},
getCommonOptCurrency1: function() { //** da cambiare in getCommonOptDecimal1
return {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: '',
minimumValue: 0.0,
maximumValue: 999999999.9,
decimalPlaces:1
}
},
getCommonOptCurrency: function() { //** da cambiare in getCommonOptDecimal2
return {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: '',
minimumValue: 0.00,
maximumValue: 999999999.99,
}
},
getCommonOptCurrency3: function() { //** da cambiare in getCommonOptDecimal3
return {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: '',
minimumValue: 0.000,
maximumValue: 999999999.999,
decimalPlaces:3
}
},
getCommonOptCurrencyEuro: function() {
return {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: '\u202f€',
minimumValue: 0.00,
maximumValue: 999999999.99,
}
},
getDateTagJQueryTable : function (value, format){
return ''+value+''+moment(value).format(format);
},
modalResize: function(dialogRef){
$(dialogRef.$modalContent).resizable();
var hhH = dialogRef.$modalHeader.height();
var hhF = dialogRef.$modalFooter.height();
var hhP = parseInt(dialogRef.$modalBody.css('padding-top').replace('px','')) + parseInt(dialogRef.$modalBody.css('padding-bottom').replace('px',''));
$('.modal-content').css('min-height', dialogRef.$modalContent.height()+'px');
$(dialogRef.$modalContent).on('resize',function (e){
if (home.isModalBodyResize){
dialogRef.$modalBody.height(dialogRef.$modalContent.height() - hhH - hhF - hhP - 60);
}
});
},
getTimeout: function (text){
var text = text || null;
if (text == null){
return 0;
}
var to = text.split(' ').length * 1000;
if (to < 2000 ) to = 2000;
if (to > 10000) to = 10000;
return to;
},
getMillisecondByDate: function (v){
if (!v){
return 0;
}else if (isNaN(moment(v, 'DD/MM/YYYY'))){
return 0;
}else{
return moment(v+ ' 12:00:00', 'DD/MM/YYYY HH:mm:ss').unix() * 1000;
}
},
getMillisecondByDatepicker: function ($ui){//** DEPRECATO
return this.getMillisecondByDate($ui.val());
},
getMillisecondWithTimeByDatepicker: function ($ui){//** DEPRECATO
var v = $ui.val();
if (!v){
return 0;
}else if (isNaN(moment(v, 'DD/MM/YYYY'))){
return 0;
}else{
return moment(v, 'DD/MM/YYYY').unix() * 1000;
}
},
getMillisecondTimeByTimepicker: function ($ui){//** DEPRECATO
var v = $ui.val();
if (!v){
return 0;
}else if (isNaN(moment(v, 'HH:mm'))){
return 0;
}else{
return moment(v, 'HH:mm').unix() * 1000;
}
},
getMillisecondByDateTime: function (v){
if (!v){
return 0;
}else if (isNaN(moment(v, 'DD/MM/YYYY'))){
return 0;
}else{
return moment(v, 'DD/MM/YYYY HH:mm:ss').unix() * 1000;
}
},
getMillisecondByDateMinute: function (v){
if (!v){
return 0;
}else if (isNaN(moment(v, 'DD/MM/YYYY'))){
return 0;
}else{
return moment(v + ':00', 'DD/MM/YYYY HH:mm:ss').unix() * 1000;
}
},
getMillisecondByMonthYear: function ($ui){
if ($ui.val() != ''){
var aa = $ui.val().split('/') ;
dd = moment([aa[1],aa[0]-1]); //.endOf('month');
if (dd.isValid()){
return dd.unix() * 1000;
}
}
return 0;
},
triggerCerca: function(e, callback) {
if($('.modal-body').is(':visible')){
return;
}
if (!$(e.target).is('body')){
return;
}
if(e.which == 13) {
callback();
}
},
getListaEventiBySelector: function ($ui){//** metti $ui = $(document)
let events = $._data( $ui[0], 'events' );
return events;
},
$_on: function(document, event, element, fun){
$(document).on(event, element, fun);
listaEventi.push({document:document, event:event, element:element});
},
$_rimuoviTuttiEventiDaElement: function(event, element){
let i = listaEventi.length;
while(--i > -1){
if (listaEventi[i].element == element){
$(listaEventi[i].document).off(listaEventi[i].event, listaEventi[i].element);
listaEventi.splice(i, 1);
}
}
},
rimuoviEventi: function(){
let i, n= listaEventi.length;
for(i=0; i < n; i++){
$(listaEventi[i].document).off(listaEventi[i].event, listaEventi[i].element);
}
listaEventi.length=0;
},
isFather: function($uiPadre, $uiFiglio) {
return $uiFiglio.parents($uiPadre).length?true:false;
},
wrap:function(el, dom){
if (el == ''){
return dom;
}
return el+dom+el.substring(0,1)+'/'+el.substring(1);
},
popolaAllegatoByUploadFile : function(a, response){
a.nome = response.fileName;
a.estensione = response.fileExtension;
a.nomeOriginale = response.originalFileName;
a.size = response.size;
a.path = response.path;
a.media = response.media;
},
getObjectByUid : function (listaBxObject, uid){
var i, n = listaBxObject.length;
for(i=0; i < n; i++){
if (listaBxObject[i].uid == uid){
return listaBxObject[i].obj;
break;
}
}
return null;
},
addObjectByUid : function (listaBxObject, a, uid){
var i, n = listaBxObject.length;
for(i=0; i < n; i++){
if (listaBxObject[i].uid == uid){
listaBxObject[i].obj = a;
break;
}
}
if (i >= n){
listaBxObject.push({uid: uid, obj: a});
}
},
removeObjectByUid : function (listaBxObject, uid){
var i, n = listaBxObject.length;
for(i=0; i < n; i++){
if (uid == listaBxObject[i].uid){
listaBxObject.splice(i,1);
break;
}
}
},
highlightString: function (searchStr, text, classHighlight) {
classHighlight = classHighlight || 'highlight';
var re = new RegExp('(' + searchStr + ')', 'gi');
return text.replace(re, '$1');
},
cleanData: function( elems ) {//** cancella elemento e i listener collegati
var data, elem, type, key,
special = jQuery.event.special,
i = 0;
for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
if ( jQuery.acceptData( elem ) ) {
key = elem[ data_priv.expando ];
if ( key && (data = data_priv.cache[ key ]) ) {
if ( data.events ) {
for ( type in data.events ) {
if ( special[ type ] ) {
jQuery.event.remove( elem, type );
// This is a shortcut to avoid jQuery.event.remove's overhead
} else {
jQuery.removeEvent( elem, type, data.handle );
}
}
}
if ( data_priv.cache[ key ] ) {
// Discard any remaining `private` data
delete data_priv.cache[ key ];
}
}
}
// Discard any remaining `user` data
delete data_user.cache[ elem[ data_user.expando ] ];
}
},
getTraduzione: function (obj, property){
property = property || 'descrizione';
return obj[property+''];
},
placeToLocalizzazione : function (place, inputAddress) {
let localizzazione;
localizzazione = {"id":0,"googleid":"","address":"","latitudine":0,"longitudine":0,"url":"","street_number":"","route":"","locality":"","administrative_area_level_3":"","administrative_area_level_2":"","administrative_area_level_2_label":"","administrative_area_level_1":"","country":"","postal_code":""};
localizzazione.googleid = place.place_id;
localizzazione.address = inputAddress; //place.formatted_address;
localizzazione.latitudine = place.geometry.location.lat();
localizzazione.longitudine = place.geometry.location.lng();
localizzazione.url = place.url;
if (place.address_components) {
let i, n = place.address_components.length;
let component;
for (i = 0; i < n; i++) {
component = place.address_components[i];
localizzazione[place.address_components[i].types[0]] = place.address_components[i].short_name;
}
}
return localizzazione;
}
}
}();
$(document).ready(function () {
$('body').append('');
});
CommonUi.resetValidate = function (){
$(".evidenzia-campo-obbligatorio").removeClass("evidenzia-campo-obbligatorio");
$(".evidenzia-testo-obbligatorio").removeClass("evidenzia-testo-obbligatorio");
$(".evidenzia-background-obbligatorio").removeClass("evidenzia-background-obbligatorio");
$(".info-errore").remove();
$('.bx-msg-required').addClass('d-none');
}
CommonUi.onSuccessAllegato = function($ui, url, nomeOriginale, dataUploaded){
// var destination = destination || 'show';
var inputFile = $ui.find('input[type="file"]');
$ui.addClass('btn-group').removeClass('input-group-btn');
let ss = inputFile.data('callback-success');
let rr = inputFile.data('callback-remove');
let $btnSfoglia = $ui.find('.fileinput-btn');
$btnSfoglia.addClass('hidden d-none');
$btnSfoglia.after('');
$btnSfoglia.after('');
$ui.find('.btnRemove').on('click',function(){
$btnSfoglia.removeClass('hidden d-none');
$ui.find('.btnRemove').remove();
$ui.find('.btnShow').remove();
if(!!rr){
eval(rr+'($ui)');
}
$ui.find('.btnRemove').off('click');
$ui.find('.btnShow').off('click');
});
$ui.find('.btnShow').on('click',function(){
// if (destination == 'media') CommonUi.openWindow('GET', '/media/' + url, {}, '_blank');
// else CommonUi.openWindow('POST', '/show', {path: url, nome_file:nomeOriginale}, '_blank');
CommonUi.openWindow('GET', url, {}, '_blank')
});
$ui.tooltip();
if(!!ss){
eval(ss+'(dataUploaded, $ui)');
}
},
CommonUi.toast = function (text,icon, callback){
$.toast({
text:text, // Text that is to be shown in the toast
heading: '', // Optional heading to be shown on the toast
icon: icon, // Type of toast icon
showHideTransition: 'slide', // fade, slide or plain
allowToastClose: true, // Boolean value true or false
hideAfter: CommonUi.getTimeout(text), // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: 5, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'top-center', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: true, // Whether to show loader or not. True by default
loaderBg: '#0076b9', // Background color of the toast loader
beforeShow: function () {}, // will be triggered before the toast is shown
afterShown: function () {}, // will be triggered after the toat has been shown
beforeHide: function () {}, // will be triggered before the toast gets hidden
afterHidden: callback // will be triggered after the toast has been hidden
});
}
function fault(text, codeError) {
codeError = codeError || null
if (codeError == 300){
CommonUi.toast(text, 'error', function() {location.reload();});
}else{
CommonUi.toast(text, 'error');
}
onHideWait();
}