feat: new layout phase F, Montar as on the canvas
Some checks failed
Build and deploy / Validate source (push) Successful in 12s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled

Roadmap Novo Layout, phase F step 1 (canvas M1, M2, M3): the header with
the folder chip and Ajustes; "Adicionar estampa" by code with the found
card; the sheet list with steppers, metres and the live packed preview;
the side panel with Interno/Venda by role, the Tiny customer card,
delivery as real radio choices, brand per stamp and sticky totals; the
"Escolha a pasta dos pedidos" state; and Ajustes (sizes and the internal
customer) in the shared dialog with one save. Same reads, packing,
permissions and API calls. Built by Bobina.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-16 11:05:06 -03:00
parent 040ef46f94
commit 392a21082e
3 changed files with 435 additions and 224 deletions

View File

@@ -8,6 +8,8 @@ const MONTAR_CODE=/^[A-Za-z0-9_-]{1,40}$/;
// The Site's ruler (web/site-config.js): the same numbers, copied there too.
const MONTAR_DPI_REFUSE=96, MONTAR_DPI_WARN=200;
const MONTAR_FILM_CM=57, MONTAR_GAP_CM=0.5;
// Phosphor gear, for the Ajustes button in the page header.
const MONTAR_GEAR='M128 80a48 48 0 1 0 48 48a48.05 48.05 0 0 0-48-48m0 80a32 32 0 1 1 32-32a32 32 0 0 1-32 32m109.94-52.79a8 8 0 0 0-3.89-5.4l-29.83-17l-.12-33.62a8 8 0 0 0-2.83-6.08a111.9 111.9 0 0 0-36.72-20.67a8 8 0 0 0-6.46.59L128 41.85L97.88 25a8 8 0 0 0-6.47-.6a112.1 112.1 0 0 0-36.68 20.75a8 8 0 0 0-2.83 6.07l-.15 33.65l-29.83 17a8 8 0 0 0-3.89 5.4a106.5 106.5 0 0 0 0 41.56a8 8 0 0 0 3.89 5.4l29.83 17l.12 33.62a8 8 0 0 0 2.83 6.08a111.9 111.9 0 0 0 36.72 20.67a8 8 0 0 0 6.46-.59L128 214.15L158.12 231a7.9 7.9 0 0 0 3.9 1a8.1 8.1 0 0 0 2.57-.42a112.1 112.1 0 0 0 36.68-20.73a8 8 0 0 0 2.83-6.07l.15-33.65l29.83-17a8 8 0 0 0 3.89-5.4a106.5 106.5 0 0 0-.03-41.52m-15 34.91l-28.57 16.25a8 8 0 0 0-3 3c-.58 1-1.19 2.06-1.81 3.06a7.94 7.94 0 0 0-1.22 4.21l-.15 32.25a95.9 95.9 0 0 1-25.37 14.3L134 199.13a8 8 0 0 0-3.91-1h-3.83a8.1 8.1 0 0 0-4.1 1l-28.84 16.1A96 96 0 0 1 67.88 201l-.11-32.2a8 8 0 0 0-1.22-4.22c-.62-1-1.23-2-1.8-3.06a8.1 8.1 0 0 0-3-3.06l-28.6-16.29a90.5 90.5 0 0 1 0-28.26l28.52-16.28a8 8 0 0 0 3-3c.58-1 1.19-2.06 1.81-3.06a7.94 7.94 0 0 0 1.22-4.21l.15-32.25a95.9 95.9 0 0 1 25.37-14.3L122 56.87a8 8 0 0 0 4.1 1h3.64a8.1 8.1 0 0 0 4.1-1l28.84-16.1A96 96 0 0 1 188.12 55l.11 32.2a8 8 0 0 0 1.22 4.22c.62 1 1.23 2 1.8 3.06a8.1 8.1 0 0 0 3 3.06l28.6 16.29a90.5 90.5 0 0 1 .05 28.29Z';
const MONTAR={sizes:[],lines:[],seq:0,preview:null,timer:null,dirty:false,token:0,
layout:null,layoutTimer:null,layoutToken:0,layoutPending:false,creating:false,requestKey:null,
kind:null,internal:null,internalDirty:false,brands:new Map(),contactToken:0,contactTimer:null,
@@ -54,16 +56,27 @@ function montarSetKind(kind){
montarClearCustomer();
montarPaintKind();montarPaintCustomer();montarPaintActions();
}
const montarInitials=name=>String(name||'').trim().split(/\s+/).slice(0,2).map(word=>word[0]).join('').toUpperCase()||'·';
function montarPaintCustomer(){
const interno=MONTAR.kind==='interno';
$('montar-customer-title').textContent=interno?'Cliente interno':'Cliente';
$('montar-customer-search').hidden=interno;
const ready=interno?montarInternalReady():montarCustomerFilled();
$('montar-customer-title').textContent=interno?'Cliente interno':'Cliente do Tiny';
$('montar-customer-search').hidden=interno||ready;
$('montar-customer-card').hidden=!ready;
$('montar-interno-note').hidden=!interno;
$('montar-customer-fields').hidden=interno;
$('montar-delivery').hidden=interno;
for(const [id,key] of [['montar-name','name'],['montar-doc','cnpj'],['montar-zap','zap'],['montar-mail','mail']]){
$(id).disabled=interno;
if(interno)$(id).value=montarInternalField(key);
}
if(ready){
const name=interno?montarInternalField('name'):$('montar-name').value.trim();
$('montar-customer-avatar').textContent=montarInitials(name);
$('montar-customer-name').textContent=name||'Cliente';
$('montar-customer-note').textContent=interno?'Cliente interno':'Contato do Tiny';
$('montar-customer-change').hidden=interno;
}
}
const montarDelivery=()=>document.querySelector('input[name="montar-delivery"]:checked')?.value||'pickup';
function montarPaintDelivery(){
@@ -234,16 +247,30 @@ function montarBrandRow(code,stamp){
return row;
}
// Without the folder there is no Estampas/ to read: only the size table works.
// Without the folder there is no Estampas/ to read: the main column asks for it
// and the side panel stays, as the canvas' no-folder screen.
function montarPaintFolder(){
const ok=montarFolderReady();
$('montar-nofolder').hidden=ok;
$('montar-setup').querySelector('.montar-add').hidden=!ok;
$('montar-preview').hidden=!ok;
$('montar-nofolder-panel').hidden=ok;
$('montar-setup').hidden=!ok;
$('montar-sheet').hidden=!ok;
$('montar-folder').textContent=ok?'Pasta “'+FOLDER.handle.name+'” · Estampas/':'';
const chip=$('montar-folder-chip');
if(chip){
chip.classList.toggle('warn',!ok);
chip.querySelector('span').textContent=ok?'Pasta: '+FOLDER.handle.name:'Sem pasta neste computador';
}
const ajustes=$('montar-ajustes-open');
if(ajustes)ajustes.hidden=!may('manage');
if(!ok){montarDropPreview();$('montar-preview').replaceChildren();}
}
async function montarChooseFolder(){
await chooseFolder();
montarPaintFolder();
if(!montarFolderReady())return;
montarPaintLines();
if($('montar-code').value.trim())montarQueuePreview();else montarPaintHint();
montarPaintActions();
}
function montarFolderError(error){
if(error&&['NotAllowedError','SecurityError'].includes(error.name)){
say('Para ler as estampas, escolha a pasta dos pedidos em Integrações neste computador.',true);
@@ -277,18 +304,31 @@ function montarPicture(url){
function montarDropPreview(){
if(MONTAR.preview)URL.revokeObjectURL(MONTAR.preview.url);
MONTAR.preview=null;
const block=$('montar-brand-block');
if(block){block.hidden=true;$('montar-brand-slot').replaceChildren();}
}
function montarFoundMetres(found){
const qty=Math.max(1,Math.round(Number($('montar-qty').value)||1));
const perRow=Math.max(1,Math.floor((MONTAR_FILM_CM-MONTAR_GAP_CM)/(found.widthCm+MONTAR_GAP_CM)));
const rows=Math.ceil(qty/perRow);
return (MONTAR_GAP_CM+rows*(montarHeight(found)+MONTAR_GAP_CM))/100;
}
function montarPaintPreview(found,stamp){
montarDropPreview();
MONTAR.preview=found;
const words=node('span',undefined,'montar-stampinfo');
words.append(node('b',found.code),
node('span',cm(found.widthCm)+' cm de largura · '+cm(montarHeight(found))+' cm de altura · '+Math.floor(montarDpi(found))+' DPI'));
const img=node('img');img.src=found.url;img.alt='Estampa '+found.code;
const body=node('div',undefined,'montar-stampbody');
body.append(words,montarBrandRow(found.code,stamp));
const wrap=node('div',undefined,'montar-stamp');wrap.append(img,body);
const qty=Math.max(1,Math.round(Number($('montar-qty').value)||1));
const dpi=montarDpi(found);
const words=node('div',undefined,'montar-foundinfo');
words.append(node('b',found.code+' encontrada'),
node('span',qty+' × '+cm(found.widthCm)+' cm de largura · cerca de '+metres(montarFoundMetres(found))+' de filme'));
if(dpi<MONTAR_DPI_REFUSE)words.append(node('span','Só '+Math.floor(dpi)+' DPI em '+$('montar-size').value+': pequena demais para imprimir.','montar-missing'));
else if(dpi<MONTAR_DPI_WARN)words.append(node('span',Math.floor(dpi)+' DPI: abaixo de '+MONTAR_DPI_WARN+' DPI.','montar-dpiwarn'));
const img=node('img',undefined,'montar-foundthumb');img.src=found.url;img.alt='Estampa '+found.code;
const wrap=node('div',undefined,'montar-found');wrap.append(img,words);
$('montar-preview').replaceChildren(wrap);
$('montar-brand-title').textContent='Marca da estampa '+found.code;
$('montar-brand-slot').replaceChildren(montarBrandRow(found.code,stamp));
$('montar-brand-block').hidden=false;
}
function montarPaintNotFound(){
montarDropPreview();
@@ -332,13 +372,19 @@ function montarEstimate(){
return (MONTAR_GAP_CM+total)/100;
}
function montarPaintTotals(){
const count=MONTAR.lines.length;
const pieces=MONTAR.lines.reduce((total,line)=>total+line.qty,0);
const done=MONTAR.layout&&!MONTAR.layoutPending;
$('montar-total').textContent=done
? 'Montagem: '+metres(MONTAR.layout.altura/100)
: 'Estimativa: '+metres(montarEstimate())+(MONTAR.layoutPending?' · montando…':'');
$('montar-count').textContent=MONTAR.lines.length?plural(MONTAR.lines.length,'estampa','estampas'):'';
$('montar-clear').disabled=!MONTAR.lines.length;
$('montar-warning').hidden=!(MONTAR.lines.length>20||MONTAR.lines.some(line=>line.qty>200));
const film=count?(done?MONTAR.layout.altura/100:montarEstimate()):0;
$('montar-count').textContent=count?plural(count,'estampa','estampas')+', '+plural(pieces,'peça','peças'):'';
$('montar-sum-stamps').textContent=String(count);
$('montar-sum-pieces').textContent=String(pieces);
$('montar-sum-film').textContent=count?(done?metres(film):metres(film)+' …'):'—';
$('montar-film-length').textContent=count?metres(film):'—';
$('montar-film-hint').textContent='em filme de 57 cm, já encaixada. Atualiza a cada mudança na lista.'+
(count&&!done?' Calculando a montagem…':'');
$('montar-clear').disabled=!count;
$('montar-warning').hidden=!(count>20||MONTAR.lines.some(line=>line.qty>200));
montarPaintActions();
}
// The line's image, loaded once and kept for the packing and the preview.
@@ -357,7 +403,7 @@ function montarChanged(){
MONTAR.requestKey=null;
montarResetFreight();
montarPaintLines();
if(!MONTAR.lines.length)montarDrawPreview(null);
montarDrawPreview(MONTAR.layout);
clearTimeout(MONTAR.layoutTimer);
MONTAR.layoutTimer=setTimeout(()=>montarLayout(MONTAR.layoutToken).catch(e=>say(e.message,true)),300);
}
@@ -385,12 +431,15 @@ async function montarLayout(token){
montarPaintTotals();
montarDrawPreview(MONTAR.layout);
}
// The sheet's preview: 57 cm across the panel, white film and the outline.
// The sheet's preview: 57 cm across the film column, white film and the
// outline; the set of stamps and their length sit beside it.
function montarDrawPreview(layout){
const box=$('montar-layout'),canvas=$('montar-canvas');
if(!layout){box.hidden=true;return;}
const box=$('montar-layout'),film=$('montar-film'),canvas=$('montar-canvas'),wait=$('montar-film-wait');
if(!MONTAR.lines.length){box.hidden=true;return;}
box.hidden=false;
const width=box.clientWidth-24; // the box's padding
canvas.hidden=!layout;wait.hidden=!!layout;
if(!layout)return;
const width=film.clientWidth;
if(width<60)return;
const px=width/MONTAR_FILM_CM;
const height=Math.max(20,layout.altura*px);
@@ -555,22 +604,38 @@ async function montarCreate(){
finally{MONTAR.creating=false;montarPaintActions();}
}
function montarLineMetres(line){
const qty=Math.max(1,Math.round(Number(line.qty)||1));
const perRow=Math.max(1,Math.floor((MONTAR_FILM_CM-MONTAR_GAP_CM)/(line.widthCm+MONTAR_GAP_CM)));
const rows=Math.ceil(qty/perRow);
return (MONTAR_GAP_CM+rows*(line.heightCm+MONTAR_GAP_CM))/100;
}
function montarLine(line){
const row=node('div',undefined,'montar-line');
const img=node('img',undefined,'montar-thumb');img.src=line.url;img.alt='';
const words=node('span',undefined,'montar-linemeta');
words.append(node('b',line.code),node('span',line.letter+' · '+cm(line.widthCm)+' cm'));
const words=node('div',undefined,'montar-linemeta');
words.append(node('b',line.code),node('span','tamanho '+line.letter+' · '+cm(line.widthCm)+' cm','sub'));
if(line.dpi<MONTAR_DPI_WARN)words.append(badge(Math.floor(line.dpi)+' DPI','warn','Abaixo de '+MONTAR_DPI_WARN+' DPI.'));
const step=node('div',undefined,'montar-step');
const minus=node('button','−','montar-stepbtn');minus.type='button';minus.setAttribute('aria-label','Menos uma');
const qty=node('input',undefined,'montar-qty');qty.type='number';qty.min='1';qty.max='9999';qty.step='1';
qty.value=String(line.qty);qty.setAttribute('aria-label','Quantidade de '+line.code+' '+line.letter);
const plus=node('button','+','montar-stepbtn');plus.type='button';plus.setAttribute('aria-label','Mais uma');
minus.disabled=line.qty<=1;plus.disabled=line.qty>=9999;
const setQty=value=>{
const next=Math.min(9999,Math.max(1,Math.round(Number(value)||1)));
line.qty=next;qty.value=String(next);montarChanged();
};
minus.onclick=()=>setQty(line.qty-1);
plus.onclick=()=>setQty(line.qty+1);
qty.onchange=()=>{
const value=Math.round(Number(qty.value));
if(!Number.isInteger(value)||value<1||value>9999){qty.value=String(line.qty);return;}
line.qty=value;qty.value=String(value);montarChanged();
};
const dpi=node('span',undefined,'montar-dpi');
if(line.dpi<MONTAR_DPI_WARN)dpi.append(badge(Math.floor(line.dpi)+' DPI','warn','Abaixo de '+MONTAR_DPI_WARN+' DPI.'));
row.append(img,words,qty,dpi,node('span',cm(line.heightCm)+' cm','montar-height'),
iconButton(IC.close,'Remover '+line.code+' '+line.letter,()=>montarRemoveLine(line)));
step.append(minus,qty,plus);
row.append(img,words,step,node('span',metres(montarLineMetres(line)),'montar-h'),
iconButton(IC.close,'Remover '+line.code+' '+line.letter,()=>montarRemoveLine(line),'btn sq ghost montar-x'));
return row;
}
function montarPaintLines(){
@@ -632,35 +697,49 @@ function montarSizeRow(size){
const width=node('input',undefined,'montar-width');width.type='number';width.min='0.01';width.max='56';width.step='0.01';
width.value=size?Number(size.width_cm):'';width.setAttribute('aria-label','Largura em centímetros');
width.oninput=()=>{MONTAR.dirty=true;};
const remove=iconButton(IC.close,'Remover tamanho',()=>{row.remove();MONTAR.dirty=true;});
row.append(letter,width,remove);
const remove=iconButton(IC.close,'Remover tamanho',()=>{row.remove();MONTAR.dirty=true;},'btn sq ghost montar-sizex');
row.append(letter,width,node('em','cm'),remove);
return row;
}
function montarPaintSizeEditor(){
const panel=$('montar-sizes-panel');
if(!may('manage')){panel.hidden=true;return;}
panel.hidden=false;
const head=node('div',undefined,'montar-size-head');
head.append(node('span','Letra'),node('span','Largura (cm)'),node('span'));
$('montar-sizes').replaceChildren(head,...MONTAR.sizes.map(montarSizeRow));
const box=$('montar-sizes');
if(!box)return;
if(!may('manage')){box.replaceChildren();return;}
box.replaceChildren(...MONTAR.sizes.map(montarSizeRow));
}
async function montarSaveSizes(){
function montarCollectSizes(){
const rows=[...$('montar-sizes').querySelectorAll('.montar-size-row')];
const sizes=[],seen=new Set();
for(const row of rows){
const letter=row.querySelector('.montar-letter').value.trim().toUpperCase();
const width=Number(row.querySelector('.montar-width').value);
if(!/^[A-Z]{1,2}$/.test(letter))return say('Cada tamanho precisa de uma letra de A a ZZ.',true);
if(seen.has(letter))return say('A letra '+letter+' aparece mais de uma vez.',true);
if(!(width>0&&width<=56))return say('A largura de '+letter+' vai de 0,01 a 56 cm.',true);
if(!/^[A-Z]{1,2}$/.test(letter)){say('Cada tamanho precisa de uma letra de A a ZZ.',true);return null;}
if(seen.has(letter)){say('A letra '+letter+' aparece mais de uma vez.',true);return null;}
if(!(width>0&&width<=56)){say('A largura de '+letter+' vai de 0,01 a 56 cm.',true);return null;}
seen.add(letter);sizes.push({letter,width_cm:Number(width.toFixed(2))});
}
if(!sizes.length)return say('A tabela precisa de pelo menos um tamanho.',true);
if(!sizes.length){say('A tabela precisa de pelo menos um tamanho.',true);return null;}
return sizes;
}
async function montarSaveAdjustments(){
const sizes=montarCollectSizes();
if(!sizes)return false;
let customer=null;
if(MONTAR.internalDirty){
customer={name:$('montar-interno-name').value.trim(),cnpj:$('montar-interno-doc').value.trim(),
zap:$('montar-interno-zap').value.trim(),mail:$('montar-interno-mail').value.trim()};
if(!['name','cnpj','zap','mail'].every(key=>customer[key])){
say('Preencha todos os campos do cliente interno.',true);
return false;
}
}
await api('/stamp-sizes',{sizes});
MONTAR.dirty=false;
say('Tamanhos salvos.');
await montarLoadSizes(true);
if(customer)await api('/internal-customer',customer);
MONTAR.dirty=false;MONTAR.internalDirty=false;
say(customer?'Ajustes salvos.':'Tamanhos salvos.');
await Promise.all([montarLoadSizes(true),montarLoadInternal(true)]);
montarQueuePreview();
return true;
}
async function montarLoadSizes(repaint){
MONTAR.sizes=(await api('/stamp-sizes')).sizes||[];
@@ -670,7 +749,7 @@ async function montarLoadSizes(repaint){
// The fixed internal customer, completed by Gestão in the panel next to the
// size table. Copied into the form only while it is not being edited.
function montarPaintInternalFields(){
if(!may('manage'))return;
if(!may('manage')||!$('montar-interno-name'))return;
$('montar-interno-name').value=montarInternalField('name');
$('montar-interno-doc').value=montarInternalField('cnpj');
$('montar-interno-zap').value=montarInternalField('zap');
@@ -678,22 +757,11 @@ function montarPaintInternalFields(){
}
async function montarLoadInternal(repaint){
MONTAR.internal=await api('/internal-customer');
const panel=$('montar-interno-panel');
panel.hidden=!may('manage');
if(may('manage')&&(repaint||!MONTAR.internalDirty))montarPaintInternalFields();
montarPaintKind();
montarPaintCustomer();
montarPaintActions();
}
async function montarSaveInternal(){
const customer={name:$('montar-interno-name').value.trim(),cnpj:$('montar-interno-doc').value.trim(),
zap:$('montar-interno-zap').value.trim(),mail:$('montar-interno-mail').value.trim()};
if(!['name','cnpj','zap','mail'].every(key=>customer[key]))return say('Preencha todos os campos do cliente interno.',true);
await api('/internal-customer',customer);
MONTAR.internalDirty=false;
say('Cliente interno salvo.');
await montarLoadInternal(true);
}
// The Venda customer comes from Tiny's contacts, by name or CPF/CNPJ.
async function montarSearchContacts(){
const token=++MONTAR.contactToken,q=$('montar-customer-q').value.trim(),hits=$('montar-customer-hits');
@@ -731,6 +799,7 @@ function montarPickContact(contact){
if(montarDelivery()==='ship'&&(!recipient||recipient===previous))
$('montar-ship-recipient').value=contact.name||'';
MONTAR.requestKey=null;
montarPaintCustomer();
montarPaintActions();
const missing=MONTAR_CUSTOMER.find(id=>!$(id).value.trim());
if(missing)$(missing).focus();
@@ -747,7 +816,7 @@ async function loadMontador(){
else montarPaintHint();
}
montarPaintLines();
if(MONTAR.layout)montarDrawPreview(MONTAR.layout);
if(MONTAR.lines.length)montarDrawPreview(MONTAR.layout);
}
// 2b splits an order that passes these limits into more than one sheet; from
@@ -773,17 +842,16 @@ $('montar-add').onclick=async()=>{
};
$('montar-clear').onclick=()=>montarClear();
$('montar-build').onclick=()=>montarCreate();
for(const id of MONTAR_CUSTOMER)$(id).addEventListener('input',()=>{MONTAR.requestKey=null;montarPaintActions();});
$('montar-size-add').onclick=()=>{MONTAR.dirty=true;$('montar-sizes').append(montarSizeRow(null));};
$('montar-size-save').onclick=async()=>{
$('montar-size-save').disabled=true;
try{await montarSaveSizes();}catch(e){say(e.message,true);}finally{$('montar-size-save').disabled=false;}
for(const id of MONTAR_CUSTOMER)$(id).addEventListener('input',()=>{MONTAR.requestKey=null;montarPaintCustomer();montarPaintActions();});
$('montar-customer-change').onclick=()=>{
for(const id of MONTAR_CUSTOMER)$(id).value='';
$('montar-customer-q').value='';$('montar-customer-hits').hidden=true;
MONTAR.requestKey=null;montarPaintCustomer();montarPaintActions();$('montar-customer-q').focus();
};
for(const id of ['montar-interno-name','montar-interno-doc','montar-interno-zap','montar-interno-mail'])
$(id).addEventListener('input',()=>{MONTAR.internalDirty=true;});
$('montar-interno-save').onclick=async()=>{
$('montar-interno-save').disabled=true;
try{await montarSaveInternal();}catch(e){say(e.message,true);}finally{$('montar-interno-save').disabled=false;}
$('montar-nofolder-choose').onclick=async()=>{
$('montar-nofolder-choose').disabled=true;
try{await montarChooseFolder();}catch(e){say(e.message,true);}
finally{$('montar-nofolder-choose').disabled=false;}
};
$('montar-customer-q').addEventListener('input',montarQueueContacts);
$('montar-customer-q').addEventListener('focus',()=>{if($('montar-customer-hits').children.length)$('montar-customer-hits').hidden=false;});
@@ -816,6 +884,62 @@ $('montar-ship-state').addEventListener('change',()=>{MONTAR.requestKey=null;mon
document.addEventListener('click',event=>{
if(!event.target.closest('.montar-customer-search'))$('montar-customer-hits').hidden=true;
});
// ---- Page header (the canvas' M1/M2): folder chip and Ajustes -------------
const montarHead=node('div',undefined,'montar-head');
const montarFolderChip=node('span',undefined,'mchip');montarFolderChip.id='montar-folder-chip';
montarFolderChip.append(node('i'),node('span'));
const montarAjustes=node('button',undefined,'btn ghost montar-ajustes-open');
montarAjustes.type='button';montarAjustes.id='montar-ajustes-open';montarAjustes.hidden=true;
montarAjustes.append(svgIcon(MONTAR_GEAR,'i m'),node('span','Ajustes'));
montarAjustes.onclick=()=>montarOpenAdjustments();
montarHead.append(montarFolderChip,montarAjustes);
document.querySelector('.top .ptitle').after(montarHead);
const montarShowHead=()=>{montarHead.hidden=$('tab-montar').hidden;};
new MutationObserver(montarShowHead).observe($('tab-montar'),{attributes:true,attributeFilter:['hidden']});
montarShowHead();
// ---- Ajustes (the canvas' M3): sizes and the internal customer -------------
// Built with the shared formDialog when the header button is pressed, so no
// dialog stays in the page: the browser tests count open .modal elements.
function montarAdjustmentFields(){
const sizes=node('section',undefined,'montar-ajustes-sec');
const sizesTitle=node('h3');sizesTitle.append('Tamanhos ',node('span','· cada letra com a largura da estampa','hint'));
const grid=node('div',undefined,'montar-sizes');grid.id='montar-sizes';
grid.append(...MONTAR.sizes.map(montarSizeRow));
const add=node('button',undefined,'btn ghost montar-size-add');add.type='button';add.id='montar-size-add';
add.append(svgIcon(IC.plus,'i m'),'Adicionar tamanho');
add.onclick=()=>{MONTAR.dirty=true;grid.append(montarSizeRow(null));};
sizes.append(sizesTitle,grid,add);
const internal=node('section',undefined,'montar-ajustes-sec');
const internalTitle=node('h3');
internalTitle.append('Cliente interno ',node('span','· o cliente fixo dos pedidos Internos; com um campo vazio, Interno fica indisponível','hint'));
const fields=node('div',undefined,'montar-customer-fields montar-interno-fields');
const makeField=(id,label,attrs,value)=>{
const line=node('label',undefined,'fld');line.append(node('span',label));
const input=node('input');input.id=id;Object.assign(input,attrs);input.autocomplete='off';input.value=value||'';
input.addEventListener('input',()=>{MONTAR.internalDirty=true;});
line.append(input);return line;
};
fields.append(
makeField('montar-interno-name','Nome',{maxLength:80,placeholder:'Nexstar · Marketplace'},montarInternalField('name')),
makeField('montar-interno-doc','CPF ou CNPJ',{inputMode:'numeric',maxLength:18,placeholder:'CPF ou CNPJ'},montarInternalField('cnpj')),
makeField('montar-interno-zap','WhatsApp',{inputMode:'numeric',maxLength:15,placeholder:'(16) 99999-9999'},montarInternalField('zap')),
makeField('montar-interno-mail','E-mail',{type:'email',maxLength:254,placeholder:'voce@empresa.com.br'},montarInternalField('mail')));
internal.append(internalTitle,fields);
return [sizes,internal];
}
function montarOpenAdjustments(){
if(!may('manage')||$('montar-sizes'))return;
MONTAR.dirty=false;MONTAR.internalDirty=false;
formDialog('Ajustes do Montar',{
text:'Valem para todas as folhas. Mudam pouco, por isso ficam aqui e não na tela.',
fields:montarAdjustmentFields(),label:'Salvar ajustes',width:720,className:'montar-ajustes-dlg',
onsave:async()=>montarSaveAdjustments()
});
}
const montarUfPlaceholder=node('option','UF');montarUfPlaceholder.value='';
$('montar-ship-state').append(montarUfPlaceholder,...MONTAR_UFS.map(uf=>{
const option=node('option',uf);option.value=uf;return option;