feat: the art grade becomes configurable, off by default (front 8.5)

Gestão sets in the Site tab below which grade the designer is warned and
below which the designer treatment is required (only while it is offered).
The decision is stored with the approved quote, so a later change never
rewrites old orders; the card shows 'Nota N: conferir a arte', the Site
forces the treatment box with the reason. With no rule nothing changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 16:13:30 -03:00
parent 1d0353fe54
commit 272755d2bc
16 changed files with 338 additions and 13 deletions

View File

@@ -148,6 +148,66 @@ function sitePriceBlock(product){
return block;
}
// ── Nota da arte (front 8.5) ────────────────────────────────────────────────
function ensureGradePanel(){
let panel=$('site-grade-panel');
if(panel)return panel;
panel=node('section',undefined,'panel clip');panel.id='site-grade-panel';
const head=node('div',undefined,'phead');head.append(node('h2','Nota da arte'));
panel.append(head,node('p','A menor nota dos itens do pedido decide. Sem regra, a nota não muda nada.','phint'));
const body=node('div',undefined,'siteGradeBody');body.id='site-grade-body';panel.append(body);
const coupons=$('site-coupons-panel');
if(coupons)coupons.before(panel);
else{
const videos=$('site-videos-panel');
if(videos)videos.before(panel);else $('tab-site').append(panel);
}
return panel;
}
function gradeRuleRow(label, value){
const row=node('div',undefined,'siteGradeRow');
const on=node('input');on.type='checkbox';on.checked=value!=null;
const word=node('span',on.checked?'Ligado':'Desligado');
const toggle=node('label',undefined,'siteSwitch');toggle.append(on,word);
const num=node('input');num.type='number';num.min='1';num.max='100';num.step='1';
num.className='siteGradeNumber';num.value=value!=null?String(value):'';num.disabled=!on.checked;
on.onchange=()=>{
word.textContent=on.checked?'Ligado':'Desligado';
num.disabled=!on.checked;
if(on.checked)num.focus();
};
const fieldLabel=node('label',undefined,'siteGradeField');
fieldLabel.append(node('span',label),num);
row.append(toggle,fieldLabel);
return {row,on,num};
}
async function loadGradeRules(){
if(!may('manage'))return;
ensureGradePanel();
const data=await api('/site/grade-rules');
const aviso=gradeRuleRow('Avisar o designer abaixo de',data.aviso);
const tratamento=gradeRuleRow('Exigir o tratamento abaixo de',data.tratamento);
const save=button('Salvar',async()=>{
const avisoValue=aviso.on.checked?Number(aviso.num.value):null;
const tratamentoValue=tratamento.on.checked?Number(tratamento.num.value):null;
for(const value of [avisoValue,tratamentoValue])
if(value!==null&&(!Number.isInteger(value)||value<1||value>100))
throw new Error('A nota vai de 1 a 100.');
if(avisoValue!==null&&tratamentoValue!==null&&tratamentoValue>avisoValue)
throw new Error('A regra do tratamento precisa ser menor ou igual à do aviso.');
await api('/site/grade-rules',{aviso:avisoValue,tratamento:tratamentoValue});
say('Regras da nota da arte salvas.');
await loadGradeRules();
},'btn pri');
const children=[aviso.row,tratamento.row];
if(!data.treatment_offered)
children.push(node('p','Ative e dê preço ao Tratamento pelo designer para esta regra valer.','siteGradeWarn'));
const foot=node('div',undefined,'siteGradeSave');foot.append(save);children.push(foot);
$('site-grade-body').replaceChildren(...children);
}
// ── Cupons (front 8.3) ──────────────────────────────────────────────────────
// A "ficha" of the date in the browser's timezone, for datetime-local inputs.
function couponDate(iso){
@@ -298,6 +358,7 @@ async function loadSiteAdmin(){
$('site-products').replaceChildren(...data.products.map(siteProductRow));
$('site-prices').replaceChildren(...data.products.map(sitePriceBlock));
await loadSiteCoupons();
await loadGradeRules();
await loadSiteVideos();
}