att
This commit is contained in:
+20
-9
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user