61 lines
2.4 KiB
JavaScript
61 lines
2.4 KiB
JavaScript
function beforeStateEntry(sequenceId) {
|
|
appendDebugPublicacao("beforeStateEntry sequenceId=" + sequenceId);
|
|
|
|
if (sequenceId == 7) {
|
|
anexarDocumentoDoCardSeNecessario();
|
|
publicarDocumento();
|
|
}
|
|
|
|
if (sequenceId == 7) {
|
|
var attachments = hAPI.listAttachments();
|
|
var hasAttachment = attachments && attachments.size() > 0;
|
|
appendDebugPublicacao("validacao anexos: total=" + (attachments ? attachments.size() : 0));
|
|
|
|
if (!hasAttachment) {
|
|
appendDebugPublicacao("validacao anexos: nenhum anexo encontrado apos processamento.");
|
|
throw "\n\nNao identificamos nenhum documento anexado, volte ao formulario e anexe pelo menos um documento para avancar a solicitacao.\n\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
function anexarDocumentoDoCardSeNecessario() {
|
|
try {
|
|
var attachments = hAPI.listAttachments();
|
|
if (attachments && attachments.size() > 0) {
|
|
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: solicitacao ja possui " + attachments.size() + " anexo(s).");
|
|
return;
|
|
}
|
|
|
|
var anexoIdStr = (hAPI.getCardValue("anexo_documento_id") || "") + "";
|
|
anexoIdStr = anexoIdStr.replace(/^\s+|\s+$/g, "");
|
|
if (!anexoIdStr) {
|
|
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: campo anexo_documento_id vazio.");
|
|
return;
|
|
}
|
|
|
|
var anexoId = parseInt(anexoIdStr, 10);
|
|
if (isNaN(anexoId) || anexoId <= 0) {
|
|
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: anexo_documento_id invalido: " + anexoIdStr);
|
|
return;
|
|
}
|
|
|
|
hAPI.attachDocument(anexoId);
|
|
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: hAPI.attachDocument OK documentId=" + anexoId);
|
|
|
|
var attachmentsDepois = hAPI.listAttachments();
|
|
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: total anexos apos attachDocument = " + (attachmentsDepois ? attachmentsDepois.size() : 0));
|
|
} catch (e) {
|
|
appendDebugPublicacao("anexarDocumentoDoCardSeNecessario: ERRO " + e);
|
|
}
|
|
}
|
|
|
|
function appendDebugPublicacao(msg) {
|
|
try {
|
|
var atual = (hAPI.getCardValue("debug_publicacao") || "") + "";
|
|
var prefix = atual ? atual + "\n" : "";
|
|
hAPI.setCardValue("debug_publicacao", prefix + msg);
|
|
} catch (e) {
|
|
log.warn("appendDebugPublicacao falhou: " + e);
|
|
}
|
|
}
|