2024-10-04
This commit is contained in:
parent
7b90cf9d33
commit
95d7fb829a
88 changed files with 9822 additions and 616 deletions
|
|
@ -1,2 +1,229 @@
|
|||
import{r as d,p as k,z as p,N as s}from"./index.Dxgx1GXj.js";import{x as i}from"./chunk-7BKSRZNG.F4GWJRq9.js";import{p as A}from"./index.DYThEupQ.js";import{R as D,b as B}from"./api2.js";import{a as W,b as x,c as j,d as q,e as Q,f as z,g as G,A as F}from"./dom.js";import{N as b,T}from"./messages3.js";import{a as H,r as J,b as X}from"./dom2.js";import{l as R,a as f,b as g,c as S,E as O,d as I,r as h}from"./erreurs.js";import{e as P,a as U}from"./gardes.js";import{v as Y}from"./messages.js";import{p as v}from"./reseau.js";import{W as K}from"./cart-remove-item.js";import{W as M}from"./cart-update-item.js";import{W as y}from"./cart.js";import{e as n}from"./erreurs2.js";import{a as V,r as Z}from"./utils.js";import{M as C,E as L}from"./Either.DDEPhGsy.js";import"./exports.CqgMoAXr.js";import"./messages2.js";import"./cart2.js";const w=_etats,$=i(V(W),H),ee=i(Z(x),J),te=E=>u=>i(X(E)(u),J),re=()=>{$.forEach(E=>{const u=te(E),c=C.fromNullable(E.getAttribute(j)).ifNothing(()=>{E.remove()}).orDefault("CLE_PANIER_INEXISTANTE"),m=u(q),_=u(Q),N=u(z),o=u(G);o.addEventListener("click",()=>{o.textContent="C= C= C= C= C=┌(;・ω・)┘",L.encase(()=>A(K,{key:c})).map(l=>{v({corps:JSON.stringify(l),nonce:w.nonce,route:D}).then(async a=>{P(a)&&R("500 Server Error"),i(await a.json(),e=>p(e).with({body:s.select(),status:400},n,f).with({body:s.select(),status:401},n,g).with({body:s.select(),status:404},n,S).with(s._,r=>A(y,r)).otherwise(r=>i(r,O,I)),k("items_count"),d(e=>{console.debug("nombreArticlesPanier",e),new BroadcastChannel(b).postMessage({donnees:e,type:T.MiseAJourPanier}),E.remove()}))}).catch(a=>{U(a)?h(a):console.error("e n'est pas une Erreur ?!",a)})})}),m.addEventListener("click",()=>{C.fromNullable(_.valueAsNumber).filter(l=>l>1).ifJust(l=>{o.textContent="C= C= C= C= C=┌(;・ω・)┘",m.toggleAttribute("disabled"),N.toggleAttribute("disabled"),o.toggleAttribute("disabled"),L.encase(()=>A(M,{key:c,quantity:l-1})).map(a=>{v({corps:JSON.stringify(a),nonce:w.nonce,route:B}).then(async e=>{P(e)&&R("500 Server Error"),i(await e.json(),r=>p(r).with({body:s.select(),status:400},n,f).with({body:s.select(),status:401},n,g).with({body:s.select(),status:404},n,S).with(s._,t=>A(y,t)).otherwise(t=>i(t,O,I)),d(r=>{new BroadcastChannel(b).postMessage({donnees:r.items_count,type:T.MiseAJourPanier})}),d(r=>{C.fromNullable(r.items.find(t=>c===t.key)?.quantity).ifJust(t=>_.setAttribute("value",String(t))),m.toggleAttribute("disabled"),N.toggleAttribute("disabled"),o.toggleAttribute("disabled"),o.textContent="Remove"}))}).catch(e=>{U(e)?h(e):console.error("e n'est pas une Erreur ?!",e)})})})}),N.addEventListener("click",()=>{C.fromNullable(_.valueAsNumber).ifJust(l=>{o.textContent="C= C= C= C= C=┌(;・ω・)┘",m.toggleAttribute("disabled"),N.toggleAttribute("disabled"),o.toggleAttribute("disabled"),L.encase(()=>A(M,{key:c,quantity:l+1})).map(a=>{v({corps:JSON.stringify(a),nonce:w.nonce,route:B}).then(async e=>{P(e)&&R("500 Server Error"),i(await e.json(),r=>p(r).with({body:s.select(),status:400},n,f).with({body:s.select(),status:401},n,g).with({body:s.select(),status:404},n,S).with(s._,t=>A(y,t)).otherwise(t=>i(t,O,I)),d(r=>{new BroadcastChannel(b).postMessage({donnees:r.items_count,type:T.MiseAJourPanier})}),d(r=>{C.fromNullable(r.items.find(t=>c===t.key)?.quantity).ifJust(t=>_.setAttribute("value",String(t))),m.toggleAttribute("disabled"),N.toggleAttribute("disabled"),o.toggleAttribute("disabled"),o.textContent="Remove"}))}).catch(e=>{U(e)?h(e):console.error("e n'est pas une Erreur ?!",e)})})})})})},se=()=>{const E=new BroadcastChannel(b);E.onmessage=u=>{Y(u).ifRight(c=>{ee.setAttribute(F,String(c.donnees!==0))})}};document.addEventListener("DOMContentLoaded",()=>{re(),se()});
|
||||
import { r, z, N, p } from "./index.y02cst4L.js";
|
||||
import { x } from "./chunk-7BKSRZNG.C39W3Wne.js";
|
||||
import { p as parse } from "./index.DD7qm8S6.js";
|
||||
import { R as ROUTE_API_RETIRE_ARTICLE_PANIER, b as ROUTE_API_MAJ_ARTICLE_PANIER } from "./api2.js";
|
||||
import { a as SELECTEUR_ENTREES_PANIER, b as SELECTEUR_CONTENEUR_PANIER, c as SELECTEUR_TOTAL_PANIER, d as ATTRIBUT_CLE_PANIER, e as SELECTEUR_BOUTON_SOUSTRACTION_QUANTITE, f as SELECTEUR_CHAMP_QUANTITE_LIGNE_PANIER, g as SELECTEUR_BOUTON_ADDITION_QUANTITE, h as SELECTEUR_BOUTON_SUPPRESSION_PANIER, A as ATTRIBUT_CONTIENT_ARTICLES, i as SELECTEUR_PRIX_LIGNE_PANIER } from "./dom.js";
|
||||
import { N as NOM_CANAL_BOUTON_PANIER, a as NOM_CANAL_CONTENU_PANIER, T as TYPES_MESSAGES } from "./messages3.js";
|
||||
import { r as recupereElementOuLeve, a as recupereElementAvecSelecteur } from "./dom2.js";
|
||||
import { l as leveServerError, a as leveBadRequestError, b as leveUnauthorizedError, c as leveNotFoundError, E as ErreurInconnue, d as leveErreur, r as reporteErreur } from "./erreurs.js";
|
||||
import { e as estReponse500, a as estError } from "./gardes.js";
|
||||
import { v as valideMessageMajBoutonPanier, a as valideMessageMajContenuPanier } from "./messages.js";
|
||||
import { p as postBackendWC } from "./reseau.js";
|
||||
import { W as WCStoreCartRemoveItemArgsSchema } from "./cart-remove-item.js";
|
||||
import { W as WCStoreCartUpdateItemArgsSchema } from "./cart-update-item.js";
|
||||
import { W as WCStoreCartSchema } from "./cart.js";
|
||||
import { e as estWCError } from "./erreurs2.js";
|
||||
import { a as recupereElementsDocumentEither, r as recupereElementDocumentEither } from "./utils.js";
|
||||
import { M as Maybe, E as Either } from "./Either.wHNxn7Os.js";
|
||||
import "./exports.DNZBdkMD.js";
|
||||
import "./messages2.js";
|
||||
import "./cart2.js";
|
||||
const ETATS_PAGE = _etats;
|
||||
const ENTREES_PANIER_EITHER = recupereElementsDocumentEither(
|
||||
SELECTEUR_ENTREES_PANIER
|
||||
);
|
||||
const CONTENEUR_PANIER = x(
|
||||
recupereElementDocumentEither(SELECTEUR_CONTENEUR_PANIER),
|
||||
recupereElementOuLeve
|
||||
);
|
||||
const TOTAL_PANIER = x(
|
||||
recupereElementDocumentEither(SELECTEUR_TOTAL_PANIER),
|
||||
recupereElementOuLeve
|
||||
);
|
||||
const recupereElementDansEntreePanierOuLeve = (
|
||||
/* eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- Nécessaire pour
|
||||
documenter le type d'Element attendu */
|
||||
(entree) => (selecteur) => x(
|
||||
recupereElementAvecSelecteur(entree)(selecteur),
|
||||
recupereElementOuLeve
|
||||
)
|
||||
);
|
||||
const initialiseScriptsPagePanier = () => {
|
||||
ENTREES_PANIER_EITHER.ifRight(
|
||||
(entrees) => entrees.forEach((entree) => {
|
||||
const recupereElementDansEntree = recupereElementDansEntreePanierOuLeve(entree);
|
||||
const clePanier = Maybe.fromNullable(entree.getAttribute(ATTRIBUT_CLE_PANIER)).ifNothing(() => {
|
||||
entree.remove();
|
||||
return;
|
||||
}).orDefault("CLE_PANIER_INEXISTANTE");
|
||||
const boutonSoustraction = recupereElementDansEntree(SELECTEUR_BOUTON_SOUSTRACTION_QUANTITE);
|
||||
const champQuantite = recupereElementDansEntree(SELECTEUR_CHAMP_QUANTITE_LIGNE_PANIER);
|
||||
const boutonAddition = recupereElementDansEntree(SELECTEUR_BOUTON_ADDITION_QUANTITE);
|
||||
const boutonSuppression = recupereElementDansEntree(SELECTEUR_BOUTON_SUPPRESSION_PANIER);
|
||||
boutonSuppression.addEventListener("click", () => {
|
||||
boutonSuppression.textContent = "C= C= C= C= C=┌(;・ω・)┘";
|
||||
Either.encase(() => parse(WCStoreCartRemoveItemArgsSchema, { key: clePanier })).map(
|
||||
(args) => {
|
||||
postBackendWC({
|
||||
corps: JSON.stringify(args),
|
||||
nonce: ETATS_PAGE.nonce,
|
||||
route: ROUTE_API_RETIRE_ARTICLE_PANIER
|
||||
}).then(async (reponse) => {
|
||||
if (estReponse500(reponse)) leveServerError("500 Server Error");
|
||||
x(
|
||||
// Récupère la Réponse
|
||||
await reponse.json(),
|
||||
// Traite tous les codes HTTPs possibles
|
||||
(corpsReponse) => z(corpsReponse).with({ body: N.select(), status: 400 }, estWCError, leveBadRequestError).with({ body: N.select(), status: 401 }, estWCError, leveUnauthorizedError).with({ body: N.select(), status: 404 }, estWCError, leveNotFoundError).with(N._, (corpsOkInconnu) => parse(WCStoreCartSchema, corpsOkInconnu)).otherwise((e) => x(e, ErreurInconnue, leveErreur)),
|
||||
r((panier) => {
|
||||
new BroadcastChannel(NOM_CANAL_CONTENU_PANIER).postMessage({
|
||||
donnees: {
|
||||
produits: panier.items,
|
||||
totalPanier: Number(panier.totals.total_items / 100)
|
||||
},
|
||||
type: TYPES_MESSAGES.MajContenuPanier
|
||||
});
|
||||
new BroadcastChannel(NOM_CANAL_BOUTON_PANIER).postMessage({
|
||||
donnees: panier.items_count,
|
||||
type: TYPES_MESSAGES.MajBoutonPanier
|
||||
});
|
||||
entree.remove();
|
||||
})
|
||||
);
|
||||
}).catch((e) => {
|
||||
if (estError(e)) {
|
||||
reporteErreur(e);
|
||||
} else {
|
||||
console.error("e n'est pas une Erreur ?!", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
boutonSoustraction.addEventListener("click", () => {
|
||||
Maybe.fromNullable(champQuantite.valueAsNumber).filter((valeur) => valeur > 1).ifJust((valeur) => {
|
||||
boutonSuppression.textContent = "C= C= C= C= C=┌(;・ω・)┘";
|
||||
boutonSoustraction.toggleAttribute("disabled");
|
||||
boutonAddition.toggleAttribute("disabled");
|
||||
boutonSuppression.toggleAttribute("disabled");
|
||||
Either.encase(
|
||||
() => parse(WCStoreCartUpdateItemArgsSchema, { key: clePanier, quantity: valeur - 1 })
|
||||
).map(
|
||||
(args) => {
|
||||
postBackendWC({
|
||||
corps: JSON.stringify(args),
|
||||
nonce: ETATS_PAGE.nonce,
|
||||
route: ROUTE_API_MAJ_ARTICLE_PANIER
|
||||
}).then(async (reponse) => {
|
||||
if (estReponse500(reponse)) leveServerError("500 Server Error");
|
||||
x(
|
||||
// Récupère la Réponse
|
||||
await reponse.json(),
|
||||
// Traite tous les codes HTTPs possibles
|
||||
(corpsReponse) => z(corpsReponse).with({ body: N.select(), status: 400 }, estWCError, leveBadRequestError).with({ body: N.select(), status: 401 }, estWCError, leveUnauthorizedError).with({ body: N.select(), status: 404 }, estWCError, leveNotFoundError).with(N._, (corpsOkInconnu) => parse(WCStoreCartSchema, corpsOkInconnu)).otherwise((e) => x(e, ErreurInconnue, leveErreur)),
|
||||
r((panier) => {
|
||||
new BroadcastChannel(NOM_CANAL_BOUTON_PANIER).postMessage({
|
||||
donnees: panier.items_count,
|
||||
type: TYPES_MESSAGES.MajBoutonPanier
|
||||
});
|
||||
new BroadcastChannel(NOM_CANAL_CONTENU_PANIER).postMessage({
|
||||
donnees: {
|
||||
produits: panier.items,
|
||||
totalPanier: Number(panier.totals.total_items / 100)
|
||||
},
|
||||
type: TYPES_MESSAGES.MajContenuPanier
|
||||
});
|
||||
boutonSoustraction.toggleAttribute("disabled");
|
||||
boutonAddition.toggleAttribute("disabled");
|
||||
boutonSuppression.toggleAttribute("disabled");
|
||||
boutonSuppression.textContent = "Remove";
|
||||
})
|
||||
);
|
||||
}).catch((e) => {
|
||||
if (estError(e)) {
|
||||
reporteErreur(e);
|
||||
} else {
|
||||
console.error("e n'est pas une Erreur ?!", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
boutonAddition.addEventListener("click", () => {
|
||||
Maybe.fromNullable(champQuantite.valueAsNumber).ifJust((valeur) => {
|
||||
boutonSuppression.textContent = "C= C= C= C= C=┌(;・ω・)┘";
|
||||
boutonSoustraction.toggleAttribute("disabled");
|
||||
boutonAddition.toggleAttribute("disabled");
|
||||
boutonSuppression.toggleAttribute("disabled");
|
||||
Either.encase(
|
||||
() => parse(WCStoreCartUpdateItemArgsSchema, { key: clePanier, quantity: valeur + 1 })
|
||||
).map(
|
||||
(args) => {
|
||||
postBackendWC({
|
||||
corps: JSON.stringify(args),
|
||||
nonce: ETATS_PAGE.nonce,
|
||||
route: ROUTE_API_MAJ_ARTICLE_PANIER
|
||||
}).then(async (reponse) => {
|
||||
if (estReponse500(reponse)) leveServerError("500 Server Error");
|
||||
x(
|
||||
// Récupère la Réponse
|
||||
await reponse.json(),
|
||||
// Traite tous les codes HTTPs possibles
|
||||
(corpsReponse) => z(corpsReponse).with({ body: N.select(), status: 400 }, estWCError, leveBadRequestError).with({ body: N.select(), status: 401 }, estWCError, leveUnauthorizedError).with({ body: N.select(), status: 404 }, estWCError, leveNotFoundError).with(N._, (corpsOkInconnu) => parse(WCStoreCartSchema, corpsOkInconnu)).otherwise((e) => x(e, ErreurInconnue, leveErreur)),
|
||||
r((panier) => {
|
||||
new BroadcastChannel(NOM_CANAL_BOUTON_PANIER).postMessage({
|
||||
donnees: panier.items_count,
|
||||
type: TYPES_MESSAGES.MajBoutonPanier
|
||||
});
|
||||
new BroadcastChannel(NOM_CANAL_CONTENU_PANIER).postMessage({
|
||||
donnees: {
|
||||
produits: panier.items,
|
||||
totalPanier: Number(panier.totals.total_items / 100)
|
||||
},
|
||||
type: TYPES_MESSAGES.MajContenuPanier
|
||||
});
|
||||
boutonSoustraction.toggleAttribute("disabled");
|
||||
boutonAddition.toggleAttribute("disabled");
|
||||
boutonSuppression.toggleAttribute("disabled");
|
||||
boutonSuppression.textContent = "Remove";
|
||||
})
|
||||
);
|
||||
}).catch((e) => {
|
||||
if (estError(e)) {
|
||||
reporteErreur(e);
|
||||
} else {
|
||||
console.error("e n'est pas une Erreur ?!", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
};
|
||||
const initialiseMajConteneurPanier = () => {
|
||||
const CANAL_BOUTON_PANIER = new BroadcastChannel(NOM_CANAL_BOUTON_PANIER);
|
||||
CANAL_BOUTON_PANIER.onmessage = (evenementMessage) => {
|
||||
valideMessageMajBoutonPanier(evenementMessage).ifRight((message) => {
|
||||
CONTENEUR_PANIER.setAttribute(ATTRIBUT_CONTIENT_ARTICLES, String(message.donnees !== 0));
|
||||
});
|
||||
};
|
||||
};
|
||||
const initialiseEcouteCanalMajContenuPanier = () => {
|
||||
new BroadcastChannel(NOM_CANAL_CONTENU_PANIER).onmessage = (evenementMessage) => {
|
||||
valideMessageMajContenuPanier(evenementMessage).map(p("donnees")).ifRight((donnees) => {
|
||||
donnees.produits.forEach((ligne) => {
|
||||
ENTREES_PANIER_EITHER.ifRight((entrees) => {
|
||||
Maybe.fromNullable(entrees.find((entree) => entree.getAttribute(ATTRIBUT_CLE_PANIER) === ligne.key)).ifJust((entree) => {
|
||||
const recupereElementDansEntree = recupereElementDansEntreePanierOuLeve(entree);
|
||||
const prixLigne = recupereElementDansEntree(SELECTEUR_PRIX_LIGNE_PANIER);
|
||||
const champQuantite = recupereElementDansEntree(
|
||||
SELECTEUR_CHAMP_QUANTITE_LIGNE_PANIER
|
||||
);
|
||||
prixLigne.textContent = `${String(Number(ligne.totals.line_total) / 100)} €`;
|
||||
champQuantite.setAttribute("value", String(ligne.quantity));
|
||||
TOTAL_PANIER.textContent = `${donnees.totalPanier} €`;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
initialiseScriptsPagePanier();
|
||||
initialiseMajConteneurPanier();
|
||||
initialiseEcouteCanalMajContenuPanier();
|
||||
});
|
||||
//# sourceMappingURL=scripts-page-panier.js.map
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue