59 lines
2.2 KiB
HTML
59 lines
2.2 KiB
HTML
{{define "justificativa_block.html"}}
|
|
<p class="eli-nps-sub" style="margin-top:16px;">Quer nos contar o motivo?</p>
|
|
|
|
<form
|
|
hx-patch="/api/e-li.nps/{{.Produto}}/{{.ID}}"
|
|
hx-target="#eli-nps-modal-body"
|
|
hx-swap="innerHTML"
|
|
hx-ext="json-enc"
|
|
>
|
|
<textarea
|
|
class="eli-nps-textarea"
|
|
name="justificativa"
|
|
id="eli-nps-justificativa"
|
|
>{{if .Reg.Justificativa}}{{.Reg.Justificativa}}{{end}}</textarea>
|
|
|
|
<div class="eli-nps-actions">
|
|
<button class="eli-nps-primary" type="button" onclick="window.__eliNpsSubmitJust('{{.Produto}}','{{.ID}}')">Enviar</button>
|
|
<button class="eli-nps-secondary" type="button" onclick="window.__eliNpsFinalizar('{{.Produto}}','{{.ID}}')">Finalizar</button>
|
|
</div>
|
|
</form>
|
|
|
|
<script>
|
|
// Funções auxiliares usadas pelo iframe.
|
|
// Elas notificarão o widget pai (janela que contém o iframe) para fechar o modal.
|
|
window.__eliNpsSubmitJust = async function(produto, id){
|
|
const v = document.getElementById('eli-nps-justificativa')?.value || '';
|
|
|
|
// Regra do produto: ao clicar em "Enviar" após escolher a nota,
|
|
// consideramos a resposta como finalizada e fechamos o modal.
|
|
const res = await fetch(`/api/e-li.nps/${produto}/${id}`, {
|
|
method: 'PATCH',
|
|
headers: {'Content-Type':'application/json','HX-Request':'true'},
|
|
body: JSON.stringify({justificativa: v, finalizar:true})
|
|
});
|
|
if(!res.ok){ return; }
|
|
|
|
// Close parent widget modal (iframe).
|
|
try{ parent.postMessage({type:'eli-nps:done', id:id, produto:produto}, '*'); }catch(e){}
|
|
}
|
|
|
|
window.__eliNpsFinalizar = async function(produto, id){
|
|
const v = document.getElementById('eli-nps-justificativa')?.value || '';
|
|
|
|
const res = await fetch(`/api/e-li.nps/${produto}/${id}`, {
|
|
method: 'PATCH',
|
|
headers: {'Content-Type':'application/json','HX-Request':'true'},
|
|
body: JSON.stringify({justificativa: v, finalizar:true})
|
|
});
|
|
if(!res.ok){ return; }
|
|
|
|
const html = await res.text();
|
|
document.getElementById('eli-nps-modal-body').innerHTML = html;
|
|
|
|
// notify parent widget to close
|
|
try{ parent.postMessage({type:'eli-nps:done', id:id, produto:produto}, '*'); }catch(e){}
|
|
}
|
|
</script>
|
|
{{end}}
|
|
|