var apx = apx || {}; apx.apxform = {}; apx.apxform.loadwco = async (id, ctx) => { // check if not authenticate, do nothing cause by default screensignin and wait authentification // if authenticate, if url xhash then redirect if no url then change wco-link=screenmyworld // if (dayjs(apx.data.headers.xdays).diff(dayjs(), "hours") >= 24) apx.apxauth.checkisauth(); //load main.mustache of the component //when wco-xxx change it run this function console.log( `Load wconame:apxauth apx.apxauth.loadwco with id:${id} and ctx: ${JSON.stringify( ctx )}` ); // Check that in localdb tpl exist if not means it is not authenticated if (!apx.data.tpl[`apxauthscreen${ctx.link}`]) ctx.link="signin"; const tpldataname = `${apx.data.pagename}_${id}_apxauth`; const apxauthid = document.getElementById(id); const data = apx.apxauth.getdata(id, ctx); if (apxauthid.innerHTML.trim() === "") { apxauthid.innerHTML = Mustache.render(apx.data.tpl.apxauthmain, data); } apxauthid.querySelector(`.screenaction`).innerHTML = Mustache.render( apx.data.tpl[`apxauthscreen${ctx.link}`], data ); apxauthid.querySelector(`.msginfo`).innerHTML = ""; }; apx.apxauth.getdata = (id, ctx) => { const tpldataname = `${apx.data.pagename}_${id}_apxauth`; const data = JSON.parse(JSON.stringify(apx.data.tpldata[tpldataname])); data.id = id; data.xalias = apx.data.headers.xalias; data.xtribe = apx.data.headers.xtribe; data.emailsupport = apx.data?.appdata?.emailsupport ? apx.data.appdata.emailsupport : ""; console.log("data:",data) switch (ctx.link) { case "myworld": if (!data.profils) data.profils = []; apx.data.headers.xprofils.forEach((p) => { if (!["anonymous", "pagans", "persons"].includes(p)) { data.profils.push(apx.data.options.profil.itms[p].title); } }); data.noprofils = data.profils.length == 0; data.member = apx.data.headers.xprofils.includes("persons"); data.websites = apx.data?.appdata?.websites || []; data.optionlinks=apx.data.tpldata[tpldataname].optionlinks data.town=apx.data.town data.nation=apx.data.nation if (1==1 || apx.data.headers.xprofils.includes('major')){ apx.data.tpldata[tpldataname].optionlinksmajor.forEach(o=>data.optionlinks.push(o)) apx.save() } if (!apx.data.itms) apx.data.itms={} if (!apx.data.wco) apx.data.wco={} // get towns list axios .get(`/api/apxtri/odmdb/idx/apxtri/towns/towns`, { headers: apx.data.headers, withCredentials:true }) .then((rep) => { console.log(rep) if (rep.status==200){ apx.data.itms.towns=rep.data.data.idx data.townsnumber= Object.keys(apx.data.itms.towns).length; apx.data.wco.townsnumber={textContent:Object.keys(apx.data.itms.towns).length}; apx.listendatawco('townsnumber'); apx.save() } }) .catch((err) => { console.log("ERROR, geting towns itms not available",err) }); axios .get(`/api/apxtri/odmdb/idx/apxtri/pagans/lst_alias`, { headers: apx.data.headers, withCredentials:true }) .then((rep) => { if (rep.status==200){ console.log(rep) data.pagansnumber=rep.data.data.idx.length apx.data.wco.pagansnumber={textContent:rep.data.data.idx.length}; apx.listendatawco('pagansnumber'); apx.save(); } }) .catch((err) => { console.log("ERROR, geting pagans itms not available",err) }); break; case "information": break; default: break; } console.log("data for tpl:", data); return data; };