Merge main into bugs-uploads
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
115
web/site-cart.js
115
web/site-cart.js
@@ -4,6 +4,77 @@
|
||||
scope and run top to bottom, exactly as the original did. */
|
||||
// ── carrinho
|
||||
let itemAtual=null;
|
||||
// Ajuste Fino (front 1a): each art may be chosen under its warning, or the
|
||||
// general switch chooses every art of the paying items.
|
||||
function artesDoItem(it){
|
||||
if(it.partes && it.partes.length)
|
||||
return it.partes.reduce((t,p)=>t+((p.production&&p.production.sources||[]).length),0);
|
||||
return (it.production&&it.production.sources||[]).length;
|
||||
}
|
||||
function artesSelecionadas(aPagar=itensAPagar()){
|
||||
if(ajusteTudo) return aPagar.reduce((t,it)=>t+artesDoItem(it),0);
|
||||
return aPagar.reduce((t,it)=>{
|
||||
if(it.partes && it.partes.length)
|
||||
return t+it.partes.reduce((s,p)=>s+(p.ajusteSources||[]).length,0);
|
||||
return t+(it.ajusteSources||[]).length;
|
||||
},0);
|
||||
}
|
||||
// While a product is open, its files are not in the cart yet; the rule must
|
||||
// still see the arts the customer already checked under their warnings.
|
||||
function artesEscolhidasNaTela(){
|
||||
if(!modo) return 0;
|
||||
return (ehFolha()?folhas:artes).filter(x=>x.ajuste).length;
|
||||
}
|
||||
// What the cart snapshot compares: the switch and every chosen source.
|
||||
function ajusteSnapshot(){
|
||||
return {tudo:!!ajusteTudo, itens:itensAPagar().map(it=>({
|
||||
escolhas:it.ajusteSources||[],
|
||||
partes:(it.partes||[]).map(p=>p.ajusteSources||[])
|
||||
}))};
|
||||
}
|
||||
// A final cart item (after a split sheet becomes its own items) to the pairs.
|
||||
function tratamentoParaItens(itens){
|
||||
if(!(TAXA_TRATAMENTO>0)) return false;
|
||||
if(ajusteTudo) return true;
|
||||
const pairs=[];
|
||||
itens.forEach((it,itemIndex)=>{
|
||||
for(const source of it.ajusteSources||[]) pairs.push([itemIndex,source]);
|
||||
});
|
||||
return pairs.length?pairs:false;
|
||||
}
|
||||
function materializaAjuste(){
|
||||
if(!ajusteTudo) return;
|
||||
ajusteTudo=false;
|
||||
for(const it of itensAPagar()){
|
||||
if(it.partes && it.partes.length){
|
||||
for(const part of it.partes)
|
||||
part.ajusteSources=Array.from({length:(part.production&&part.production.sources||[]).length},(_,i)=>i);
|
||||
}else{
|
||||
it.ajusteSources=Array.from({length:(it.production&&it.production.sources||[]).length},(_,i)=>i);
|
||||
}
|
||||
}
|
||||
for(const x of folhas) x.ajuste=true;
|
||||
for(const a of artes) a.ajuste=true;
|
||||
}
|
||||
function limpaAjuste(){
|
||||
ajusteTudo=false;
|
||||
for(const it of itensAPagar()){
|
||||
it.ajusteSources=[];
|
||||
for(const part of it.partes||[]) part.ajusteSources=[];
|
||||
}
|
||||
for(const x of folhas) x.ajuste=false;
|
||||
for(const a of artes) a.ajuste=false;
|
||||
}
|
||||
// Update the per-art boxes without repainting the list, which would discard
|
||||
// the item the customer is still building.
|
||||
function pintaAjusteCheckboxes(){
|
||||
document.querySelectorAll('[data-ajuste]').forEach(el=>{
|
||||
const x=folhas[+el.dataset.ajuste]; if(x)el.checked=ajusteTudo||!!x.ajuste;
|
||||
});
|
||||
document.querySelectorAll('[data-ajustea]').forEach(el=>{
|
||||
const a=artes[+el.dataset.ajustea]; if(a)el.checked=ajusteTudo||!!a.ajuste;
|
||||
});
|
||||
}
|
||||
function invalidaItemAtual(){
|
||||
if(!itemAtual) return;
|
||||
itemAtual=null;
|
||||
@@ -31,7 +102,8 @@ function limpaPaineis(){
|
||||
}
|
||||
|
||||
// Front 8.5: when the worst grade of the paying items is below the rule and
|
||||
// the treatment is offered, the designer's treatment is required.
|
||||
// Ajuste Fino is offered, it is required. The simple rule the server keeps:
|
||||
// at least one art must be chosen; with none, the general switch selects all.
|
||||
function mostraAvisoTratamento(texto){
|
||||
const box=$('tratamentoBox'); if(!box)return;
|
||||
let el=$('tratamentoAviso');
|
||||
@@ -48,12 +120,27 @@ function aplicaTratamento(aPagar){
|
||||
const required=offered&&rule>0&&worst!==null&&worst<rule;
|
||||
box.hidden=!offered;
|
||||
if(!offered){
|
||||
check.checked=false;check.disabled=false;mostraAvisoTratamento('');
|
||||
check.checked=false;check.disabled=false;
|
||||
ajusteTudo=false;
|
||||
for(const it of aPagar){
|
||||
it.ajusteSources=[];
|
||||
for(const part of it.partes||[]) part.ajusteSources=[];
|
||||
}
|
||||
for(const x of folhas) x.ajuste=false;
|
||||
for(const a of artes) a.ajuste=false;
|
||||
mostraAvisoTratamento('');
|
||||
}else if(required){
|
||||
check.checked=true;check.disabled=true;
|
||||
mostraAvisoTratamento('Sua arte tem nota '+worst+': para imprimir com qualidade, o tratamento pelo designer é obrigatório neste pedido.');
|
||||
const chosen=!!ajusteTudo || artesSelecionadas(aPagar)>0 || artesEscolhidasNaTela()>0;
|
||||
if(!chosen){
|
||||
ajusteTudo=true;
|
||||
for(const x of folhas) x.ajuste=true;
|
||||
for(const a of artes) a.ajuste=true;
|
||||
document.querySelectorAll('[data-ajuste],[data-ajustea]').forEach(el=>{el.checked=true;});
|
||||
}
|
||||
check.checked=ajusteTudo;check.disabled=true;
|
||||
mostraAvisoTratamento('Sua arte tem nota '+worst+': para imprimir com qualidade, o Ajuste Fino é obrigatório neste pedido.');
|
||||
}else{
|
||||
check.disabled=false;mostraAvisoTratamento('');
|
||||
check.checked=ajusteTudo;check.disabled=false;mostraAvisoTratamento('');
|
||||
}
|
||||
}
|
||||
// O carrinho junta itens de produtos diferentes e cobra uma vez só.
|
||||
@@ -100,7 +187,8 @@ function pintaPedido(){
|
||||
$('bEsvaziar').hidden = pedido.length+(itemAtual?1:0) < 2;
|
||||
const itens = aPagar.reduce((t,it)=>t+it.total,0);
|
||||
const frete = entrega.tipo==='frete' && entrega.cotado ? entrega.valor : 0;
|
||||
const tratamento=$('fTratamento')?.checked&&TAXA_TRATAMENTO>0?TAXA_TRATAMENTO:0;
|
||||
const artesAjuste = TAXA_TRATAMENTO>0 ? artesSelecionadas(aPagar) : 0;
|
||||
const tratamento = artesAjuste ? Math.round(precoAjuste(artesAjuste)*artesAjuste*100)/100 : 0;
|
||||
const soma = itens + frete + tratamento;
|
||||
const n = aPagar.length, noCarrinho = pedido.length + (itemAtual?1:0);
|
||||
$('resLin').innerHTML =
|
||||
@@ -110,7 +198,8 @@ function pintaPedido(){
|
||||
'</span><b>'+
|
||||
(entrega.tipo==='retira' ? '<span style="color:var(--verde-ml)">Grátis</span>'
|
||||
: entrega.cotado ? rs(frete) : 'a cotar')+'</b></div>'+
|
||||
(tratamento?'<div class="l"><span>Tratamento da arte · +24 h</span><b>'+rs(tratamento)+'</b></div>':'')+
|
||||
(tratamento?'<div class="l"><span>Ajuste Fino · '+artesAjuste+(artesAjuste===1?' arte':' artes')+
|
||||
' · +24 h</span><b>'+rs(tratamento)+'</b></div>':'')+
|
||||
'<div class="l"><span>Revisão e reencaixe</span>'+
|
||||
'<b><span style="color:var(--verde-ml)">Grátis</span></b></div>';
|
||||
$('carrTot').textContent=rs(soma);
|
||||
@@ -156,6 +245,7 @@ function carrinho(){
|
||||
'<div class="l" style="color:var(--laranja2)"><span>Revisão e reencaixe</span><b>grátis</b></div>';
|
||||
$('carrLin').innerHTML=l;
|
||||
$('atual').style.display='';
|
||||
const escolhidas=lista=>lista.map((x,i)=>ajusteTudo||x.ajuste?i:null).filter(i=>i!==null);
|
||||
const sources=(ehFolha()?folhas:artes).map(x=>ehFolha()
|
||||
? {kind:'sheet',width_cm:x.med?.larg||larguraFilme(),length_cm:+(x.m*100).toFixed(4),
|
||||
copies:x.rep||1,rotation_degrees:0,mirrored:false,
|
||||
@@ -180,6 +270,7 @@ function carrinho(){
|
||||
localFiles:f.artes.map(x=>x.f), fotos:f.artes.map(x=>x.fotoSrc||null),
|
||||
metros:+(f.layout.height_cm/100).toFixed(4),
|
||||
production:{version:3,film_width_cm:larguraFilme(),sources:f.artes.map(fonteDaArte),...f.layout},
|
||||
ajusteSources:escolhidas(f.artes),
|
||||
residueAccepted:residuosDasArtes(f.artes), ...tracoDoItem(f.artes,f.layout)}));
|
||||
layout=null;
|
||||
}else{
|
||||
@@ -194,6 +285,7 @@ function carrinho(){
|
||||
arquivos:(ehFolha()?folhas:artes).length,
|
||||
production:layout?{version:3,film_width_cm:larguraFilme(),sources,...layout}:null,
|
||||
partes,
|
||||
...(partes?{}:{ajusteSources:escolhidas(ehFolha()?folhas:artes)}),
|
||||
qualityStatus:$('ciente').classList.contains('recusa')?'rejected':
|
||||
$('ciente').classList.contains('on')?'warning':nota===0?'unverified':'ok',
|
||||
qualityAcknowledged:false,
|
||||
@@ -215,7 +307,14 @@ function avisaDesfazer(texto,acao){
|
||||
function fechaDesfazer(){ clearTimeout(desfazerTimer); desfazerAcao=null; $('desfazer').hidden=true; }
|
||||
addEventListener('dtf-page-changed',fechaDesfazer);
|
||||
$('desfazerBtn').addEventListener('click',()=>{ const acao=desfazerAcao; fechaDesfazer(); if(acao) acao(); });
|
||||
$('fTratamento')?.addEventListener('change',()=>pintaPedido());
|
||||
$('fTratamento')?.addEventListener('change',()=>{
|
||||
if($('fTratamento').checked) ajusteTudo=true;
|
||||
else limpaAjuste();
|
||||
// The art cards show the same choice, one checkbox under each warning; do
|
||||
// not repaint them, or the item being built is discarded.
|
||||
pintaAjusteCheckboxes();
|
||||
pintaPedido();
|
||||
});
|
||||
$('bEsvaziar').addEventListener('click',()=>{
|
||||
const antes=pedido.slice();
|
||||
pedido=[]; invalidaItemAtual(); pintaPedido();
|
||||
|
||||
Reference in New Issue
Block a user