'+
'| Prodotti | €##totProdotti## |
| Spedizione | '+
'€##totSpedizione## |
| Totale | €##tot## | '+
'
';
var html = '';
var prod = '';
var tuttiProd = '';
var tuttiHtml = '';
for(o in resp.ordini){
html = tblOrd.replace(/##nomecliente##/g, '['+resp.ordini[o].id.replace('"','\"')+'] '+'CL'+resp.ordini[o].idC+' '+resp.ordini[o].nomC.replace('"','\"'));
html = html.replace(/##articoli##/g, resp.ordini[o].art);
html = html.replace(/##totOrdine##/g, resp.ordini[o].totNoSped.replace('"','\"'));
tuttiProd = '';
for(p in resp.ordini[o].prod){
prod = trProdotto;
if(resp.ordini[o].prod[p].img.length>0){
prod = prod.replace(/##img##/g, resp.ordini[o].prod[p].img[0].replace('"','\"'));
}else{
prod = prod.replace(/##img##/g, "images/prodotti/generico.png");
}
prod = prod.replace(/##nome##/g, resp.ordini[o].prod[p].n.replace('"','\"'));
prod = prod.replace(/##qta##/g, resp.ordini[o].prod[p].qta.replace('"','\"'));
prod = prod.replace(/##prezzoU##/g, resp.ordini[o].prod[p].p.replace('"','\"'));
prod = prod.replace(/##prezzoT##/g, resp.ordini[o].prod[p].pTot.replace('"','\"'));
tuttiProd += prod;
}
html = html.replace(/##prodotti##/g, tuttiProd);
tuttiHtml += html;
}
tblTotale = tblTotale.replace(/##totProdotti##/g, parseFloat(resp.totNoSped).toFixed(2));
tblTotale = tblTotale.replace(/##totSpedizione##/g, parseFloat(resp.sped).toFixed(2));
tblTotale = tblTotale.replace(/##tot##/g, (parseFloat(resp.totNoSped)+parseFloat(resp.sped)).toFixed(2));
frm[0].innerHTML = tuttiHtml+tblTotale;
$(modal).modal('show');
}
}).fail(function(){alertSwal('error','', "Errore di connessione");})
.always(function(resp){hideLoader(resp,0);});
}
function impostaModale() {
var modal = document.getElementById('modals-conferma');// modale in cui scrivere
$(modal).modal('show');
$("#totModal").html($(".totaleCS").html());
}
function inviaPrenota(obj){
var frm = formica(obj);
flag = true;
flag = flag && controlForm(frm, "Indirizzo",'indirizzo');
flag = flag && controlForm(frm, "Città",'citta');
flag = flag && controlForm(frm, "CAP",'cap');
flag = flag && controlForm(frm, "privacy policy",'privacy');
flag = flag && controlForm(frm, "Termini e condizioni",'termini');
var strUri = frm.buildUri('php');
if(flag){
viewLoader('invio in corso');
$.post('https://www.dispensapantesca.com/inviaOrdine',strUri,function(){},'json')
.done(function(resp){
if(resp.s=="ok"){
$('#modals-conferma').modal('hide');
$("#modals-stripe").on('show.bs.modal', function (event) {
document.getElementById('totStripe').innerHTML = resp.t;
document.getElementById('totStripe2').innerHTML = resp.t;
});
$('#modals-stripe').modal('show');
}else if(resp.s=="dup"){
var fn = function (){$('#modals-conferma').modal('hide')}
alertSwal('warning',"Richiesta rigettata", resp.t, fn);
}else{
alertSwal('error','',"errore_contatto");
}
})
.fail(function(){alertSwal('error','', "errore di connessione");})
.always(function(resp){hideLoader(resp,0);});
}
}
// ********************* Profilo ******************
function modProfilo(obj){
var frm = formica(obj);
flag = true;
flag = flag && controlForm(frm, 'Nome','nome','');
flag = flag && controlForm(frm, 'Cognome','cognome','');
//flag = flag && controlForm(frm, 'Telefono','telefono','');
flag = flag && controlForm(frm, 'Indirizzo consegna','indirizzo','');
flag = flag && controlForm(frm, 'Città','citta','');
flag = flag && controlForm(frm, 'Provincia','provincia','');
flag = flag && controlForm(frm, 'C.A.P.','cap','');
if(frm.getValue('pass')!=''){
flag = flag && controlForm(frm, 'Password','pass','6','c<');
flag = flag && controlForm(frm, 'Password e ripeti password','pass','pass2','=');
}
if(flag){
viewLoader('Loading...');
$.post('https://www.dispensapantesca.com/modProfilo',frm.buildUri('php'),function(){},'json')
.done(function(resp){
if(resp.result=="ok"){
var fn = function(){};
alertSwal('success','Modifica effettuata', '',fn);
}else if(resp.result=="ko"){
alertSwal('error','Modifica fallita', '');
}
}).fail(function(){alertSwal('error','', "Errore di connessione");})
.always(function(resp){hideLoader(resp,0);});
}
}
// ************* Detrit *************
/* @version 23/02/2022 migliorata legenda
* Strutture array ad albero, con indicizzazione in memoria
* @example new detrit([{id:'1',name:'a'},{id:'2',name:'b'},{id:'3',name:'c'}],'id');
*
* @param array array array anche di oggetti di un recordset
* @param string key nome chiave primaria del recordset (univoca)
*
* @example if(objD==undefined) objD = new detrit([],'id');
*
* @function set aggiunge un elemento al recordset
* @param el elemento con dentro la chiave key
*
* @example objD.set({id:4,name:'d'});
*
* @function get restituisce un elemento al recordset
* @param key valore di key per l'elemento cercato
*
* @function del elimina un elemento al recordset
* @param key valore di key per l'elemento cercato
* @function setAttribute aggiunge un attributo al record
* @param key valore di key per l'elemento cercato
* @param name nome attributo
* @param value valore attributo
*
* objD.setAttribute(1,'coord',{x:'1',y:'2'})
* @function getAttribute restituisce un attributo del record
* @param key valore di key per l'elemento cercato
* @param name nome attributo cercato
* @function delAttribute elimina un attributo del record
* @param key valore di key per l'elemento cercato
* @param name nome attributo da eliminare
* @example ciclare gli elementi del recordset di nome r
* for(var k=r.keys.length-1;k>=0;k--){// eliminare tutti i record
var pId = r.keys[k];
var p = r.get(pId);
p.pObj.destroy();//distruggo un attributo di nome pObj
r.del(pId);// butto elemento detrit
}
*
* @throws No Exception
* @author Pastix
*/
// ************* Decimal tree *************
function detrit(array,key) {
this.id = key;// name of primary key
this.root = {};
this.keys = new Array();// All primary key values
for(k in array){
this.set(array[k]);
}
return this;
}
detrit.prototype.lastArray = function(str){// private
var n = str.length-1;
return([str[n],str.slice(0,n)]);
};
detrit.prototype.add = function(el,name){// private
var idx = this.lastArray(name);
if(this.pt[idx[0]]==undefined) this.pt[idx[0]] = {value:null};
this.pt = this.pt[idx[0]];
if(idx[1]==''){
this.pt.value = el;
this.keys.push(el[this.id]);
return this.pt.value;
}else{
this.add(el,idx[1]);
}
};
detrit.prototype.set = function(el){// public
this.pt = this.root;
if(el[this.id]==undefined) return false;
return this.add(el,String(el[this.id]));
};
detrit.prototype.get = function(key){// public
var keys = String(key).split('').reverse().join('][');
if(keys==''){
return undefined;
}else{
try{
return eval('this.root['+keys+'].value');
}catch(err) {return undefined;}
}
};
detrit.prototype.del = function(key){// public
var keys = String(key).split('').reverse().join('][');
if(keys==''){
return undefined;
}else{
try{
this.pt = eval('this.root['+keys+']');
var index = this.keys.indexOf(this.pt.value[this.id]);
if (index > -1) this.keys.splice(index, 1);
this.pt.value = null;
}catch(err) {return undefined;}
}
return undefined;
};
detrit.prototype.setAttribute = function(key,name,value){// public
var keys = String(key).split('').reverse().join('][');
if(keys=='' || name==''){
return false;
}else{
try{
this.pt = eval('this.root['+keys+']');
this.pt.value[name] = value;
return this.pt.value;
}catch(err) {return false;}
}
};
detrit.prototype.getAttribute = function(key,name){// public
var keys = String(key).split('').reverse().join('][');
if(keys=='' || name==''){
return false;
}else{
try{
this.pt = eval('this.root['+keys+']');
return this.pt.value[name];
}catch(err) {return undefined;}
}
};
detrit.prototype.delAttribute = function(key,name){// public
var keys = String(key).split('').reverse().join('][');
if(keys=='' || name==''){
return false;
}else{
try{
this.pt = eval('this.root['+keys+']');
delete this.pt.value[name];
return this.pt;
}catch(err) {return undefined;}
}
};
// ************* !Detrit *************//
var generico = {
//Instanza
instance:'generico',gui:{},carrello:{idProdotto:'0',qtaProdotto:0,qtaCarrello:'0',start:1,min:1,max:999,step:1,vp:"0"},tOutId:0,
initialize : function(box,ty){
try{ // Nome istanza
var inst = eval(this.instance+".instance");
if(this.instance!=inst){alert('Wrong instance name');return false;}
}catch(err) {alert('Wrong instance name');return false;}
// Elementi interfaccia
viewLoader('Caricamento in corso');
this.setInterface();
this.updOrdine();
hideLoader('',0);
},
setInterface:function(){ //GUI
this.gui.icon = document.getElementById('carrelloIco');
this.gui.gallery = document.getElementById('galleryProdotto') || false;
this.gui.tasti = document.getElementById('tastiProdotto') || false;
this.gui.foto = document.getElementById('immaginePr') || false;
if(this.gui.tasti){
this.carrello.idProdotto = this.gui.tasti.getAttribute('data-id');
this.carrello.start = parseInt(this.gui.tasti.getAttribute('data-start'),10);
this.carrello.min = parseInt(this.gui.tasti.getAttribute('data-min'),10);
this.carrello.max = parseInt(this.gui.tasti.getAttribute('data-max'),10);
this.carrello.step = parseInt(this.gui.tasti.getAttribute('data-step'),10);
this.carrello.vp = this.gui.tasti.getAttribute('data-vp');
}
//this.gui.foto.onclick = this.getDettaglio.bind(this);//### link modale
},
updOrdine: function(){
if(APERTURA.s=="ok"){
var nItem = 0;
for(p in ORDINE){
if(ORDINE[p].id!="0") nItem+=parseInt(ORDINE[p].art,10);
if(ORDINE[p].id==this.carrello.idProdotto) this.carrello.qtaProdotto = parseInt(ORDINE[p].qt,10);
}
this.carrello.qtaCarrello = nItem;
this.updNotifica(nItem);
if(this.carrello.idProdotto!="0") this.updInterface();
}else{
if(this.carrello.idProdotto!="0") this.gui.tasti.innerHTML = '';
}
},
updInterface:function(){
var oThis = this;
var spans = getChildTag(this.gui.tasti,"SPAN");
for(var l in spans){
switch(spans[l].className){
case "qta":
this.gui.qta = spans[l];//### span quantita
this.gui.qta.contentEditable = 'true';
this.gui.qta.innerHTML = this.carrello.qtaProdotto;
var fn = function(){
var exQTA = oThis.carrello.qtaProdotto;
var q = oThis.gui.qta.innerHTML.replace(/[^\d]/gm,'');
if(q=='') q='0';
oThis.gui.qta.innerHTML = q;
oThis.carrello.qtaProdotto = parseInt(q,10);
if(exQTA!=oThis.carrello.qtaProdotto) oThis.setTimeQuantita("0");
};
this.gui.qta.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
oThis.gui.qta.blur();
event.preventDefault();
}
});
this.gui.qta.onblur = fn;
$(this.gui.qta).tooltip();
break;
}
}
var links = getChildTag(this.gui.tasti,"A");
for(var l in links){
switch(links[l].className){
case "icon-chevron-right-l":
this.piu = links[l];//### link piu'
links[l].onclick = this.setTimeQuantita.bind(this,"+");
break;
case "icon-chevron-left-l":
links[l].onclick = this.setTimeQuantita.bind(this,"-");//### link meno
break;
case "tasto icona-fine":
links[l].onclick = this.switchQuantita.bind(this);
break;
}
}
// modale der il dettaglio
this.gui.modal = document.getElementById('modals-detProdotto');
},
setTimeQuantita: function(ty){
var qta = this.carrello.qtaProdotto;//INT
if(this.tOutId) clearTimeout(this.tOutId);
this.tOutId=0;
if(ty=='+'){
qta += this.carrello.step;
}else if(ty=='-'){
qta -= this.carrello.step;
}
if(qta<=0) qta=0;
if(qta>this.carrello.max) qta=this.carrello.max;
this.gui.qta.innerHTML = qta;
this.carrello.qtaProdotto = qta;
var oThis = this;
//var fn = function(){oThis.switchQuantita(idProdotto,qta);};
var fn = "generico.switchQuantita()";
// L non vuole l'invio automatico del prodotto al carrello
// lo vuole con il tasto aggiungi
// this.tOutId = setTimeout(fn,700);
return false;
},
switchQuantita: function(){
var qta = this.carrello.qtaProdotto;
var idProdotto = this.carrello.idProdotto;
var oThis = this;
viewLoader('Caricamento in corso...');
$.post(URLSITO+"setProdotto","idProdotto="+encodeURIComponent(idProdotto)+"&qta="+encodeURIComponent(qta),function(){},'json')
.done(function(resp){
if(resp.result=="ok"){
//if(qta!=0){
for(var i in resp.prodotti){
if(resp.prodotti[i].id==idProdotto){
var iconaz = URLSITO+"images/prodotti/generico.png";
if(resp.prodotti[i].img!=""){
iconaz = URLSITO+resp.prodotti[i].img[0];
}
if(resp.prodotti[i].qVar==0){
qtaz = qta+" pz";
}else{
qtaz = qta+" gr";
}
}
}
//}
notificaTopRight(resp.pzT,iconaz,resp.prodotti[i].n,qtaz);
oThis.switchQuantitaDone(idProdotto,resp);
}else if(resp.result=="disp"){
alertSwal('warning','', resp.t);
oThis.carrello.qtaProdotto = parseInt(resp.n,10);
oThis.gui.qta.innerHTML = resp.n;
oThis.switchQuantita();
//prod.switchQuantita(resp.n);
}
}).fail(function(){alertSwal('error','', "Errore di connessione");})
.always(function(resp){hideLoader(resp,0);});
},
switchQuantitaDone: function(idProdotto,resp){
this.updNotifica(resp.art);
},
updNotifica: function(nItem){
this.gui.icon.innerHTML = nItem;
if(nItem>0){
var li = this.gui.icon.parentNode;
li.style.display='inline-block';
}else{
var li = this.gui.icon.parentNode;
li.style.display='none';
}
},
getDettaglio: function(){
var self = this;
viewLoader('Caricamento in corso...');
$.post(URLSITO+'detProdotto','idProdotto='+this.carrello.idProdotto,function(){},'json')
.done(function(resp){self.getDettaglioDone(resp);})
.fail(function(){alertSwal('error','', "Errore di connessione");})
.always(function(resp){hideLoader(resp,0);});
},
getDettaglioDone: function(resp){
if(resp.result == "ok"){
var pr = resp.prodotto[0];
var a,b,c,d;
var divs = getChildTag(this.gui.modal,"DIV");
for(var l in divs){
switch(divs[l].className){
case "carousel-inner":
a=divs[l];
break;
case "pull-left nomeProdotto":
c=divs[l];
break;
case "modal-footer":
d=divs[l];
break;
}
}
/*var ols = getChildTag(this.modal,"OL");
for(var l in ols){
switch(ols[l].className){
case "carousel-indicators":
b=ols[l];
break;
}
}*/
// carosello
if(pr.img.length==0){
pr.img.push("images/prodotti/generico.png");
pr.imgDs.push({tt:'',st:'',ds:''});
}
var act="active",x='',y='';
for(var i in pr.img){
x += '';
/*x += '';
if(pr.imgDs[i]['tt']!='') x += '
'+pr.imgDs[i]['tt']+'
';
if(pr.imgDs[i]['st']!='') x += '
'+pr.imgDs[i]['st']+'
';
if(pr.imgDs[i]['ds']!='') x += '
'+pr.imgDs[i]['ds']+'
';
x += '
';*/
//y += '';
act='';
}
a.innerHTML = x;
//b.innerHTML = y;
c.innerHTML = pr.nome;
d.innerHTML = pr.dsc;
if(!$(this.gui.modal).hasClass('in')){$(this.gui.modal).modal('show');}
}
}
};
// ************* Prodotto *************
var tmplProdotto = ''+
'

'+
'
'+
'
##prezzo##
'+
'
€ ##prezzoKg## ##um##
'+
'
';
function prodotto(p) {
this.id = p.id;
this.tOutId=0;
var tmpl = tmplProdotto;//tmplProdotto.replace(/##id##/g, p.id);
tmpl = tmpl.replace(/##nome##/g, p.n.replace('"','\"'));
tmpl = tmpl.replace(/##marca##/g, p.c.replace('"','\"'));
tmpl = tmpl.replace(/##prezzo##/g, '€ '+parseFloat(p.p.pz).toFixed(2));
if(p.img.length==0) p.img = Array('images/prodotti/generico.png');
tmpl = tmpl.replace(/##img##/g, URLSITO+p.img[0]);
tmpl = tmpl.replace(/##prezzoKg##/g, parseFloat(p.p.kg).toFixed(2));
tmpl = tmpl.replace(/##um##/g, p.p.umk);
var ele = document.createElement('DIV');
ele.className = "col-md-4 col-sm-6 col-xs-12 default-item";
ele.style.display = "inline-block";
ele.innerHTML = tmpl;
var spans = getChildTag(ele,"SPAN");
for(var l in spans){
switch(spans[l].className){
case "quantita":
this.qta = spans[l];//### span quantita
this.qta.contentEditable = 'true';
var oThis = this;
var fn = function(){
var exQTA = oThis.carrello.qta;
var q = oThis.qta.innerHTML.replace(/[^\d]/gm,'');
if(q=='') q='0';
oThis.qta.innerHTML = q;
oThis.carrello.qta = parseInt(q,10);
if(exQTA!=oThis.carrello.qta) oThis.setTimeQuantita("0");
};
this.qta.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
oThis.qta.blur();
event.preventDefault();
}
});
this.qta.onblur = fn;
$(this.qta).tooltip();
break;
}
}
var ts = p.ts.split(":").map(function(x) {return parseInt(x, 10);});// tutto int
this.carrello = {qta:ts[0],qMax:ts[2],qStp:ts[3],qVar:ts[4]};//qMin e' 0 sempre
var links = getChildTag(ele,"A");
for(var l in links){
switch(links[l].className){
case "piu":
this.piu = links[l];//### link piu'
links[l].onclick = this.setTimeQuantita.bind(this,"+");
break;
case "meno":
links[l].onclick = this.setTimeQuantita.bind(this,"-");//### link meno
break;
case "detProdotto":
links[l].onclick = this.getDettaglio.bind(this);//### link modale
break;
}
}
// modale der il dettaglio
this.modal = document.getElementById('modals-detProdotto');
/*"inC": "0", "qMin":1*/
this.dom = ele;
this.switchQuantita(this.carrello.qta);
return this;
}
prodotto.prototype.setTimeQuantita = function(ty){
var qta = this.carrello.qta;//INT
//if(qta='') qta=0;
if(this.tOutId) clearTimeout(this.tOutId);
this.tOutId=0;
if(ty=='+'){
qta += this.carrello.qStp;
}else if(ty=='-'){
qta -= this.carrello.qStp;
}
if(qta<=0) qta=0;
if(qta>this.carrello.qMax) qta=this.carrello.qMax;
this.qta.innerHTML = qta;//+(this.carrello.qVar==1?'Gr':'')
this.carrello.qta = qta;
var idProdotto=this.id;
var fn = function(){dispatcher.switchQuantita(idProdotto,qta);};
this.tOutId = setTimeout(fn,700);//
};
prodotto.prototype.getDettaglio = function(){
var self = this;
viewLoader('Caricamento in corso...');
$.post(URLSITO+'detProdotto','idProdotto='+this.id,function(){},'json')
.done(function(resp){self.getDettaglioDone(resp);})
.fail(function(){alertSwal('error','', "Errore di connessione");})
.always(function(resp){hideLoader(resp,0);});
};
prodotto.prototype.getDettaglioDone = function(resp){
if(resp.result == "ok"){
var pr = resp.prodotto[0];
var a,b,c,d;
var divs = getChildTag(this.modal,"DIV");
for(var l in divs){
switch(divs[l].className){
case "carousel-inner":
a=divs[l];
break;
case "pull-left nomeProdotto":
c=divs[l];
break;
case "modal-footer":
d=divs[l];
break;
}
}
/*var ols = getChildTag(this.modal,"OL");
for(var l in ols){
switch(ols[l].className){
case "carousel-indicators":
b=ols[l];
break;
}
}*/
// carosello
if(pr.img.length==0){
pr.img.push("images/prodotti/generico.png");
pr.imgDs.push({tt:'',st:'',ds:''});
}
var act="active",x='',y='';
for(var i in pr.img){
x += '';
x += '';
if(pr.imgDs[i]['tt']!='') x += '
'+pr.imgDs[i]['tt']+'
';
if(pr.imgDs[i]['st']!='') x += '
'+pr.imgDs[i]['st']+'
';
if(pr.imgDs[i]['ds']!='') x += '
'+pr.imgDs[i]['ds']+'
';
x += '
';
//y += '';
act='';
}
a.innerHTML = x;
//b.innerHTML = y;
c.innerHTML = pr.nome;
d.innerHTML = pr.dsc;
if(!$(this.modal).hasClass('in')){$(this.modal).modal('show');}
}
};
prodotto.prototype.switchQuantita = function(qta){
qta = parseInt(qta,10);
if(qta<=0) qta=0;
if(qta>this.carrello.qMax) qta=this.carrello.qMax;
this.qta.innerHTML = qta;
this.carrello.qta = qta;
};
// ************* !Prodotto *************