feat: new layout phase B, the Site tab as on the canvas
Roadmap Novo Layout, phase B (canvas S1 to S6): tabs Produtos e preços, Cupons, Nota da arte and Vídeos; the products table with the on/off switch, bands and next change; the price dialog with Agora/Agendar on the Kanban calendar (calendar() takes options, Números unchanged), bands and the live "O cliente vê" line; coupons, grade rules and videos in tables with their dialogs; stacked rows and full-screen dialogs on the phone. Same API calls and rules as before. Built by Prensa. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -33,53 +33,95 @@ function statsPeriod(){
|
||||
wrap.replaceChildren(open);
|
||||
}
|
||||
// The calendar: presets on the left, a month where a click starts the
|
||||
// period and the next one ends it.
|
||||
function calendar(){
|
||||
const pop=node('div',undefined,'pop calpop');pop.setAttribute('role','dialog');pop.setAttribute('aria-label','Escolher o período');
|
||||
// period and the next one ends it. `single`, `future` and `time` add the
|
||||
// Site's price picker (one future day and a time); without options this is
|
||||
// exactly the Números range picker.
|
||||
function calendar(options={}){
|
||||
const single=!!options.single, future=!!options.future, withTime=!!options.time;
|
||||
const onApply=options.onApply||null, onCancel=options.onCancel||null;
|
||||
const pop=node('div',undefined,'pop calpop'+(single?' single':''));
|
||||
pop.setAttribute('role','dialog');pop.setAttribute('aria-label',single?'Escolher a data':'Escolher o período');
|
||||
pop.onclick=e=>e.stopPropagation();
|
||||
const today=todayIso();
|
||||
let pick=statsRange?{...statsRange}:null, month=new Date((statsRange?.end||today)+'T12:00:00');month.setDate(1);
|
||||
const initial=options.value||null;
|
||||
let pick=single
|
||||
?(initial?.date?{start:initial.date,end:initial.date}:null)
|
||||
:statsRange?{...statsRange}:null;
|
||||
let month=new Date(((single?pick?.start:pick?.end)||today)+'T12:00:00');month.setDate(1);
|
||||
const presets=node('div',undefined,'presets'),grid=node('div',undefined,'dgrid'),title=node('b');
|
||||
const label=node('span','','lbl');
|
||||
const time=node('input');time.type='time';time.className='inp';time.value=initial?.time||'08:00';
|
||||
const apply=node('button','Aplicar','btn pri');apply.type='button';
|
||||
const cancel=node('button','Cancelar','btn ghost right');cancel.type='button';cancel.onclick=()=>pop.remove();
|
||||
apply.onclick=()=>{if(!pick?.end)return;statsRange=pick;pop.remove();loadStats().catch(e=>say(e.message,true));};
|
||||
const back=n=>{const d=new Date(today+'T12:00:00');d.setDate(d.getDate()-n);return isoDay(d);};
|
||||
const first=new Date(today+'T12:00:00');first.setDate(1);
|
||||
const prevEnd=new Date(first);prevEnd.setDate(0);const prevStart=new Date(prevEnd);prevStart.setDate(1);
|
||||
for(const [text,range] of [['Hoje',[today,today]],['Últimos 7 dias',[back(6),today]],['Últimos 30 dias',[back(29),today]],
|
||||
['Este mês',[isoDay(first),today]],['Mês passado',[isoDay(prevStart),isoDay(prevEnd)]],['Últimos 90 dias',[back(89),today]]]){
|
||||
const b=node('button',text,'preset');b.type='button';b.dataset.range=range.join('|');
|
||||
b.onclick=()=>{pick={start:range[0],end:range[1]};month=new Date(range[1]+'T12:00:00');month.setDate(1);paint();};presets.append(b);
|
||||
const cancel=node('button','Cancelar','btn ghost right');cancel.type='button';
|
||||
cancel.onclick=()=>{onCancel?.();pop.remove();};
|
||||
apply.onclick=()=>{
|
||||
if(single){
|
||||
if(!pick?.start)return;
|
||||
if(onApply)onApply({date:pick.start,time:withTime?time.value||'08:00':null});
|
||||
pop.remove();return;
|
||||
}
|
||||
if(!pick?.end)return;
|
||||
if(onApply){onApply({start:pick.start,end:pick.end});pop.remove();return;}
|
||||
statsRange=pick;pop.remove();loadStats().catch(e=>say(e.message,true));
|
||||
};
|
||||
if(!single){
|
||||
const back=n=>{const d=new Date(today+'T12:00:00');d.setDate(d.getDate()-n);return isoDay(d);};
|
||||
const first=new Date(today+'T12:00:00');first.setDate(1);
|
||||
const prevEnd=new Date(first);prevEnd.setDate(0);const prevStart=new Date(prevEnd);prevStart.setDate(1);
|
||||
for(const [text,range] of [['Hoje',[today,today]],['Últimos 7 dias',[back(6),today]],['Últimos 30 dias',[back(29),today]],
|
||||
['Este mês',[isoDay(first),today]],['Mês passado',[isoDay(prevStart),isoDay(prevEnd)]],['Últimos 90 dias',[back(89),today]]]){
|
||||
const b=node('button',text,'preset');b.type='button';b.dataset.range=range.join('|');
|
||||
b.onclick=()=>{pick={start:range[0],end:range[1]};month=new Date(range[1]+'T12:00:00');month.setDate(1);paint();};presets.append(b);
|
||||
}
|
||||
}
|
||||
const prev=iconButton(IC.left,'Mês anterior',()=>{month.setMonth(month.getMonth()-1);paint();},'btn sq ghost');
|
||||
const next=iconButton(IC.right,'Próximo mês',()=>{month.setMonth(month.getMonth()+1);paint();},'btn sq ghost');
|
||||
const head=node('div',undefined,'mhd');head.append(title,prev,next);
|
||||
function paint(){
|
||||
title.textContent=month.toLocaleDateString('pt-BR',{month:'long',year:'numeric'}).replace(/^./,c=>c.toUpperCase());
|
||||
next.disabled=isoDay(month)>=today.slice(0,8)+'01';
|
||||
next.disabled=future?false:isoDay(month)>=today.slice(0,8)+'01';
|
||||
for(const b of presets.children){const [a,z]=b.dataset.range.split('|');b.classList.toggle('on',!!pick&&pick.start===a&&pick.end===z);}
|
||||
const days=[...['D','S','T','Q','Q','S','S'].map(w=>node('span',w,'dow'))];
|
||||
const start=new Date(month);start.setDate(1-start.getDay());
|
||||
for(let i=0;i<42;i++){
|
||||
const d=new Date(start);d.setDate(start.getDate()+i);const iso=isoDay(d);
|
||||
if(i>=35&&d.getMonth()!==month.getMonth())break;
|
||||
const end=pick?.end||pick?.start;
|
||||
const cls=['day'];if(d.getMonth()!==month.getMonth())cls.push('mute');if(iso>today)cls.push('future');if(iso===today)cls.push('today');
|
||||
if(pick&&iso===pick.start)cls.push('s');if(pick&&iso===end)cls.push('e');if(pick&&iso>pick.start&&iso<end)cls.push('in');
|
||||
const allowed=future?iso>=today:iso<=today;
|
||||
const cls=['day'];if(d.getMonth()!==month.getMonth())cls.push('mute');if(!allowed)cls.push('future');if(iso===today)cls.push('today');
|
||||
if(single){
|
||||
if(pick&&iso===pick.start)cls.push('s');
|
||||
}else{
|
||||
const end=pick?.end||pick?.start;
|
||||
if(pick&&iso===pick.start)cls.push('s');if(pick&&iso===end)cls.push('e');if(pick&&iso>pick.start&&iso<end)cls.push('in');
|
||||
}
|
||||
const b=node('button',undefined,cls.join(' '));b.type='button';b.append(node('span',String(d.getDate())));
|
||||
b.setAttribute('aria-label',dayLabel(iso));b.disabled=iso>today;
|
||||
b.onclick=()=>{if(!pick||pick.end)pick={start:iso,end:null};else if(iso<pick.start)pick={start:iso,end:pick.start};else pick.end=iso;paint();};
|
||||
b.setAttribute('aria-label',dayLabel(iso));b.disabled=!allowed;
|
||||
b.onclick=()=>{
|
||||
if(single)pick={start:iso,end:iso};
|
||||
else if(!pick||pick.end)pick={start:iso,end:null};
|
||||
else if(iso<pick.start)pick={start:iso,end:pick.start};
|
||||
else pick.end=iso;
|
||||
paint();
|
||||
};
|
||||
days.push(b);
|
||||
}
|
||||
grid.replaceChildren(...days);
|
||||
label.textContent=pick?dayLabel(pick.start)+(pick.end?' a '+dayLabel(pick.end):', escolha o fim'):'Escolha o início';
|
||||
apply.disabled=!pick?.end;
|
||||
if(single){
|
||||
label.textContent=pick?dayLabel(pick.start)+(withTime?' · '+(time.value||'08:00'):''):'Escolha o dia';
|
||||
apply.disabled=!pick;
|
||||
}else{
|
||||
label.textContent=pick?dayLabel(pick.start)+(pick.end?' a '+dayLabel(pick.end):', escolha o fim'):'Escolha o início';
|
||||
apply.disabled=!pick?.end;
|
||||
}
|
||||
}
|
||||
if(withTime)time.oninput=()=>paint();
|
||||
const monthBox=node('div',undefined,'month');monthBox.append(head,grid);
|
||||
const body=node('div',undefined,'cal');body.append(presets,monthBox);
|
||||
const body=node('div',undefined,'cal'+(single?' single':''));
|
||||
if(single)body.append(monthBox);else body.append(presets,monthBox);
|
||||
const timeBox=node('div',undefined,'time');
|
||||
if(withTime)timeBox.append(node('span','Horário'),time);
|
||||
const foot=node('div',undefined,'popfoot');foot.append(label,cancel,apply);
|
||||
pop.append(body,foot);paint();
|
||||
pop.append(body,...(withTime?[timeBox]:[]),foot);paint();
|
||||
document.addEventListener('click',()=>pop.remove(),{once:true});
|
||||
return pop;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user