This commit is contained in:
Andrey Cunha
2026-03-21 13:24:57 -03:00
parent 5f7c2f99d1
commit b836b0a5d2
13 changed files with 4099 additions and 2322 deletions
@@ -31,13 +31,28 @@
const isString = item => typeof item === "string";
const normalizeAttachmentDescription = (value) => String(value || "").trim();
const attachmentMatchesDescription = (attachment, filename) => {
const target = normalizeAttachmentDescription(filename);
const description = normalizeAttachmentDescription(attachment && attachment.description);
return !!target && (description === target || description.indexOf(target + " - ") === 0);
};
/**
* Procura o índice do anexo de acordo com sua descrição
*
* @param {string} filename
* @returns {number} -1 se não encontrar
*/
const attachmentFindIndex = (filename) => parent.ECM.attachmentTable.getData().findIndex(attachment => attachment.description === filename);
const attachmentFindIndex = (filename) =>
parent.ECM.attachmentTable.getData().findIndex(attachment => attachmentMatchesDescription(attachment, filename));
const attachmentFindIndexes = (filename) =>
parent.ECM.attachmentTable
.getData()
.map((attachment, index) => attachmentMatchesDescription(attachment, filename) ? index : -1)
.filter(index => index !== -1);
/**
* Configuração padrão
@@ -269,14 +284,10 @@
filename = `${this.#settings.prefixName}-${filename}`;
}
// Evitar conflito de descrição do anexo
if (attachmentFindIndex(filename) !== -1) {
FLUIGC.toast({
title: "Atenção",
message: "Já existe um anexo com essa descrição",
type: "warning",
})
return;
// Evita bloqueio de duplicidade: substitui anexo existente com mesma descrição.
const duplicatedIndexes = attachmentFindIndexes(filename).sort((a, b) => b - a);
if (duplicatedIndexes.length) {
parent.WKFViewAttachment.removeAttach(duplicatedIndexes);
}
parent.$("#ecm-navigation-inputFile-clone")