';
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);});
}
// ************* 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 dispatcher = {
//Instanza
instance:'dispatcher',
controllers:[],
initialize : function(){
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;}
if(typeof generico != 'undefined' && generico.instance=="generico") this.controllers.push(generico);
},
switchQuantita: function(idProdotto,qta){
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);
var prod = window.generico.prodotti.get(idProdotto);
prod.switchQuantita(resp.n);
}
}).fail(function(){alertSwal('error','', "Errore di connessione");})
.always(function(resp){hideLoader(resp,0);});
},
switchQuantitaDone: function(idProdotto,resp){
for(var j in this.controllers) this.controllers[j].switchQuantita(idProdotto,resp);
}
};
addEvent(window, 'load', function () {
dispatcher.initialize();
});
var generico = {
//Instanza
instance:'generico',gui:{},fascia:'',
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');
//window.requestAnimationFrame(function(){viewLoader('Caricamento in corso...');});
this.setInterface(box);
this.getGenerici();
hideLoader('',0);
//window.requestAnimationFrame(function(){hideLoader('',0);});
//;
},
setInterface:function(box){ //GUI
this.gui.box = document.getElementById(box);
this.gui.icon = document.getElementById('carrelloIco');
this.gui.categorie = document.getElementById('categorieBox');
this.gui.notifica = false;
if(this.gui.icon!=null){
var spans = getChildTag(this.gui.icon,"SPAN");
for(var l in spans){
if(spans[l].className=="s_color_bg p_color") this.gui.notifica = spans[l];//### icona articoli
}
}else{
var tasto = document.getElementById('tastoCarrello');
tasto.style.display = 'none';
var clm = document.getElementById('colonnaSx');
clm.style.display = 'none';
}
if(this.prodotti==undefined) this.prodotti = new detrit([],'id');
this.gui.box.innerHTML = '';
},
//************ ricevo i generici dal server ***********
getGenerici: function(ty){
var self = this;
$.post(URLSITO+'prodotti','',function(){},'json')
.done(function(resp){self.updProdotti(resp);})
.fail(function(){alertSwal('error','', "Errore di connessione");})
.always(function(resp){});
},
updProdotti: function(resp){
if(resp.result=="ok"){
this.fascia = {da:resp.o.da,da:resp.o.a};
if(resp.prodotti.length==0){
this.gui.box.innerHTML="Spiacente, nessun prodotto trovato.";
}else{
var categoria='';
var nItem = 0;
for(var p in resp.prodotti){
if(this.prodotti.get(resp.prodotti[p].id)){// aggiorna
}else{// crea
// categoria
if(resp.prodotti[p].c!=categoria){
// separatori di categoria
var ele = document.createElement('DIV');
ele.className = "comment-box"; ele.style.position = "relative"; ele.style.display = "inline-block";
ele.style.width = "100%"; ele.style.paddingTop='0';
ele.innerHTML = '
'+resp.prodotti[p].c+'
';
this.gui.box.appendChild(ele);
// elenco delle categorie
ele = document.createElement('LI');
ele.innerHTML = ''+resp.prodotti[p].c+'';
this.gui.categorie.appendChild(ele);
categoria = resp.prodotti[p].c;
};
// prodotto
var prod = new prodotto(resp.prodotti[p]);
this.gui.box.appendChild(prod.dom);
this.prodotti.set(prod);
nItem += parseInt(resp.prodotti[p].art,10);
};
}
this.updNotifica(nItem);
}
}else{
var mex ='
'+
'
'+
'
'+
'
Siamo spiacenti ma il negozio è chiuso.';
if(resp.o.s=='ko'){
if(resp.o.prev!='') mex +=' L\'ultima data utile per effettuare l\'ordine è stata il '+resp.o.prev;
}
mex +='
La prossima apertura è prevista dal '+resp.o.next[0]+' al '+resp.o.next[1]+'
';
}
mex += '
Per informazioni sui prodotti del negozio vi invitiamo a contattarci.
';
mex += '
Al fine di evitare che le nostre e-mail finiscano tra lo spam o la posta indesiderata, ti consigliamo di inserire tra i tuoi contatti di posta elettronica la nostra e-mail noreply@igelsielatalpa.it
';
mex += '
';
this.gui.box.innerHTML = mex;
}
},
switchQuantita: function(idProdotto,resp){
//var prod = this.prodotti.get(idProdotto);
// il resp contiene i dati ordine, e prodotto, passo solo il necessario
//if(prod) prod.switchQuantita(resp.prodotti[0].qta);
this.updNotifica(resp.art);
},
updNotifica: function(nItem){
if(this.gui.notifica) this.gui.notifica.innerHTML = nItem;
}
};
// ************* Prodotto *************
var tmplProdotto = '
';
eleOrd.innerHTML = html;
var curOrdine = {id:ord.idO,idC:ord.idC};
var box ='';
var tbls = getChildTag(eleOrd,"TABLE");
for(var l in tbls){
switch(tbls[l].className){
case "table table-1":
box = tbls[l];//### TR del prodotto
break;
}
}
var tbls = getChildTag(eleOrd,"TD");
for(var l in tbls){
switch(tbls[l].className){
case "totOrdine":
curOrdine.totBox = tbls[l];//### totale Ordine
break;
}
}
var tbls = getChildTag(eleOrd,"SPAN");
for(var l in tbls){
switch(tbls[l].className){
case "totArt":
curOrdine.totArt = tbls[l];//### totale Ordine
break;
}
}
curOrdine.prodotti = new detrit([],'id');
for(var p in ord.prod){// prodotto
var prod = new prodottoCarrello(ord.prod[p],ord.idO);
box.appendChild(prod.dom);
curOrdine.prodotti.set(prod);
//nItem += parseInt(resp.prodotti[p].art,10);
}
this.gui.box.appendChild(eleOrd);
this.ordini.set(curOrdine);
}
}
}
}else{
var mex ='
'+
'
'+
'
'+
'
Siamo spiacenti ma il negozio è chiuso.';
if(resp.o.s=='ko'){
if(resp.o.prev!='') mex +=' L\'ultima data utile per effettuare l\'ordine è stata il '+resp.o.prev;
}
mex +='
La prossima apertura è prevista dal '+resp.o.next[0]+' al '+resp.o.next[1]+'
';
}
mex += '
Per informazioni sui prodotti del negozio vi invitiamo a contattarci.
';
mex += '
Al fine di evitare che le nostre e-mail finiscano tra lo spam o la posta indesiderata, ti consigliamo di inserire tra i tuoi contatti di posta elettronica la nostra e-mail noreply@igelsielatalpa.it
';
mex += '
';
this.gui.box.innerHTML = mex;
this.gui.tot.style.display='none';
}
},
switchQuantita: function(idProdotto,idOrdine,qta){// retrocompatibilita'
//var prod = this.prodotti.get(idProdotto);
// il resp contiene i dati ordine, e prodotto, passo solo il necessario
//if(prod) prod.switchQuantita(resp.prodotti[0].qta);
var self = this;
var strUri = 'idProdotto='+idProdotto+'&idOrdine='+idOrdine+'&qta='+qta;
$.post(URLSITO+'prodottiCarrello',strUri,function(){},'json')
.done(function(resp){self.updProdotti(resp);})
.fail(function(){alertSwal('error','', "Errore di connessione");})
.always(function(resp){});
},
updProdotto : function(resp,idProdotto,idOrdine){
//Totale: €'+(parseFloat(ord.totNoSped)+parseFloat(ord.sped)).toFixed(2)
},
updNotifica: function(nItem){
if(this.gui.notifica) this.gui.notifica.innerHTML = nItem;
}
};
// ************* Prodotto *************
var tmplProdottoCarrello = '