Skip to content

Commit 4ca261d

Browse files
Rossi-Lucianoclaude
andcommitted
Adiciona botão Reprocessar na interface Wagtail
Insere botão na barra de ações do cabeçalho nas views de edição de ProcessedDocx e MarkupXML, com mensagem de confirmação contextual. Usa MutationObserver como fallback para injeção no DOM quando o cabeçalho ainda não está renderizado. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d104670 commit 4ca261d

1 file changed

Lines changed: 69 additions & 1 deletion

File tree

markup_doc/static/js/xref-button.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,76 @@ function get_zip() {
523523

524524
// También en DOMContentLoaded por si basta
525525
document.addEventListener("DOMContentLoaded", tryAttach);
526-
526+
527527
// Llama una vez por si ya está listo
528528
tryAttach();
529529
})();
530530

531+
532+
// Botão Reprocessar — aparece nas views de edição de ProcessedDocx e MarkupXML
533+
(function () {
534+
var path = window.location.pathname;
535+
var isProcessedDocx = path.indexOf('processeddocx/edit/') !== -1;
536+
var isMarkupXml = path.indexOf('markupxml/edit/') !== -1;
537+
538+
if (!isProcessedDocx && !isMarkupXml) return;
539+
540+
var match = path.match(/\/edit\/(\d+)\//);
541+
if (!match) return;
542+
var pk = match[1];
543+
544+
function makeBtn() {
545+
var btn = document.createElement('button');
546+
btn.type = 'button';
547+
btn.id = 'reprocess-btn';
548+
btn.textContent = 'Reprocessar';
549+
btn.style.cssText = [
550+
'padding:4px 12px',
551+
'cursor:pointer',
552+
'background:#e9a000',
553+
'color:white',
554+
'font-weight:bold',
555+
'border:none',
556+
'border-radius:4px',
557+
'margin-left:8px',
558+
'font-size:14px',
559+
].join(';');
560+
btn.addEventListener('mouseover', function () { btn.style.background = '#c98000'; });
561+
btn.addEventListener('mouseout', function () { btn.style.background = '#e9a000'; });
562+
btn.addEventListener('click', function () {
563+
var msg = isMarkupXml
564+
? 'Isso irá descartar as edições manuais e reprocessar o DOCX original. Continuar?'
565+
: 'Reprocessar este documento?';
566+
if (confirm(msg)) {
567+
window.location.href = '/admin/reprocess/' + pk + '/';
568+
}
569+
});
570+
return btn;
571+
}
572+
573+
function tryInsert() {
574+
if (document.getElementById('reprocess-btn')) return true;
575+
// Tenta área de ações do cabeçalho Wagtail (v5/v6)
576+
var actionArea = document.querySelector('.w-slim-header__action-buttons')
577+
|| document.querySelector('[data-controller="w-slim-header"] .w-slim-header__title-wrapper');
578+
if (actionArea) {
579+
actionArea.appendChild(makeBtn());
580+
return true;
581+
}
582+
// Fallback: insere após o primeiro botão submit (salvar)
583+
var saveBtn = document.querySelector('button[type="submit"]');
584+
if (saveBtn && saveBtn.parentNode) {
585+
saveBtn.parentNode.insertBefore(makeBtn(), saveBtn.nextSibling);
586+
return true;
587+
}
588+
return false;
589+
}
590+
591+
if (!tryInsert()) {
592+
var obs = new MutationObserver(function () {
593+
if (tryInsert()) obs.disconnect();
594+
});
595+
obs.observe(document.documentElement, { childList: true, subtree: true });
596+
}
597+
})();
598+

0 commit comments

Comments
 (0)