att
This commit is contained in:
+27
-24
@@ -1,4 +1,4 @@
|
||||
<div id="MyWidget_${instanceId}" class="super-widget wcm-widget-class fluig-style-guide"
|
||||
<div id="MyWidget_${instanceId}" class="super-widget wcm-widget-class fluig-style-guide"
|
||||
data-params="MyWidget.instance()">
|
||||
|
||||
<link rel="stylesheet" href="/style-guide/css/fluig-style-guide.min.css">
|
||||
@@ -102,6 +102,32 @@ data-params="MyWidget.instance()">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="form-group col-md-12 alertaCampo">
|
||||
|
||||
<label>Anexar documento <strong class="text-danger">*</strong></label>
|
||||
|
||||
<p class="text-muted">
|
||||
Selecione o arquivo ou use a camera do celular para capturar o documento.
|
||||
</p>
|
||||
|
||||
<button type="button" class="btn btn-primary btn-anexo" id="anexaDocumento">
|
||||
<i class="flaticon flaticon-paperclip"></i>
|
||||
Anexar documento
|
||||
</button>
|
||||
|
||||
<input type="file"
|
||||
id="arquivoLocal"
|
||||
style="display:none"
|
||||
accept="image/*,.pdf">
|
||||
|
||||
<div id="arquivoLocalNome" class="arquivo-nome"></div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="form-group col-md-6 alertaCampo">
|
||||
@@ -131,29 +157,6 @@ data-params="MyWidget.instance()">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="form-group col-md-12">
|
||||
|
||||
<label>Anexar documento <strong class="text-danger">*</strong></label>
|
||||
|
||||
<p class="text-muted">
|
||||
Utilize o botão abaixo para anexar o documento.
|
||||
</p>
|
||||
|
||||
<button type="button" class="btn btn-primary btn-anexo" id="anexaDocumento">
|
||||
<i class="flaticon flaticon-paperclip"></i>
|
||||
Anexar documento
|
||||
</button>
|
||||
|
||||
<input type="file" id="arquivoLocal" style="display:none">
|
||||
|
||||
<div id="arquivoLocalNome" class="arquivo-nome"></div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-card">
|
||||
|
||||
+95
-147
@@ -1,9 +1,10 @@
|
||||
if (typeof window !== "undefined") {
|
||||
if (typeof window !== "undefined") {
|
||||
window.WCMAPI = window.WCMAPI || {};
|
||||
if (typeof window.WCMAPI.isMobileAppMode !== "function") {
|
||||
window.WCMAPI.isMobileAppMode = function () { return false; };
|
||||
}
|
||||
}
|
||||
|
||||
function showCamera(param) {
|
||||
if (typeof JSInterface !== "undefined" && JSInterface && typeof JSInterface.showCamera === "function") {
|
||||
JSInterface.showCamera(param);
|
||||
@@ -16,7 +17,6 @@ var MyWidget = SuperWidget.extend({
|
||||
init: function () {
|
||||
this.root = $("#MyWidget_" + this.instanceId);
|
||||
this.anexoInfo = null;
|
||||
this.gedParentFolderId = 10;
|
||||
this.isSending = false;
|
||||
this.bindEvents();
|
||||
this.setupInitialValues();
|
||||
@@ -29,11 +29,11 @@ var MyWidget = SuperWidget.extend({
|
||||
self.enviarDocumento();
|
||||
});
|
||||
|
||||
this.root.find("#anexaDocumento").off("click").on("click", function () {
|
||||
this.root.find("#anexaDocumento_" + this.instanceId + ", #anexaDocumento").off("click").on("click", function () {
|
||||
self.handleAnexo();
|
||||
});
|
||||
|
||||
this.root.find("#arquivoLocal").off("change").on("change", function () {
|
||||
this.root.find("#arquivoLocal_" + this.instanceId + ", #arquivoLocal").off("change").on("change", function () {
|
||||
self.onArquivoSelecionado(this);
|
||||
});
|
||||
|
||||
@@ -57,6 +57,7 @@ var MyWidget = SuperWidget.extend({
|
||||
this.root.find("#tipo_cadastro").val("cpf").trigger("change");
|
||||
this.root.find("#emitido_por").val("fornecedor");
|
||||
this.root.find("#tipo_documento").val("danfe");
|
||||
this.root.find("#arquivoLocalNome").text("");
|
||||
this.clearStatus();
|
||||
},
|
||||
|
||||
@@ -78,48 +79,10 @@ var MyWidget = SuperWidget.extend({
|
||||
|
||||
this.root.find("#arquivoLocalNome").text("Arquivo selecionado: " + file.name + " (" + this.formatFileSize(file.size || 0) + ")");
|
||||
this.clearStatus();
|
||||
|
||||
console.log("[portalfornecedor] anexo preparado para envio:", {
|
||||
fileName: this.anexoInfo.fileName,
|
||||
mimeType: this.anexoInfo.mimeType,
|
||||
fileSize: this.anexoInfo.fileSize
|
||||
});
|
||||
},
|
||||
|
||||
handleAnexo: function () {
|
||||
if (showCamera("anexo_documento")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.openAttachmentTab()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.root.find("#arquivoLocal").trigger("click");
|
||||
},
|
||||
|
||||
openAttachmentTab: function () {
|
||||
try {
|
||||
var parentDoc = window.parent && window.parent.document ? window.parent.document : document;
|
||||
var selectors = [
|
||||
"#tab-attachments",
|
||||
"a[href*='attachments']",
|
||||
"a[aria-controls*='attachments']",
|
||||
"[data-tab*='attachments']"
|
||||
];
|
||||
|
||||
for (var i = 0; i < selectors.length; i++) {
|
||||
var el = parentDoc.querySelector(selectors[i]);
|
||||
if (el) {
|
||||
el.click();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return false;
|
||||
this.root.find("#arquivoLocal_" + this.instanceId + ", #arquivoLocal").trigger("click");
|
||||
},
|
||||
|
||||
toggleTipoCadastro: function (tipo) {
|
||||
@@ -188,61 +151,44 @@ var MyWidget = SuperWidget.extend({
|
||||
|
||||
this.setLoading(true, "Enviando documento, aguarde...");
|
||||
|
||||
this.uploadAnexoToECM(this.anexoInfo.file)
|
||||
.done(function (docData) {
|
||||
var payloadProcesso = {
|
||||
targetState: 0,
|
||||
subProcessTargetState: 0,
|
||||
comment: "Solicitacao criada via widget",
|
||||
formFields: {
|
||||
data_abertura: self.value("#data_abertura"),
|
||||
emitido_por: self.value("#emitido_por"),
|
||||
entidade_responsavel: self.value("#entidade_responsavel"),
|
||||
tipo_cadastro: tipoCadastro,
|
||||
emailSolicitante: self.value("#emailSolicitante"),
|
||||
cpf: cpfField || documentoPessoa,
|
||||
tipo_documento: self.value("#tipo_documento"),
|
||||
numero_documento: numeroDocumento,
|
||||
valor: valor,
|
||||
justificativa: self.value("#justificativa"),
|
||||
anexo_documento_id: String(docData.documentId || ""),
|
||||
anexo_documento_nome: self.anexoInfo.fileName,
|
||||
anexo_documento_mime: self.anexoInfo.mimeType
|
||||
}
|
||||
};
|
||||
var payloadProcesso = {
|
||||
targetState: 5,
|
||||
comment: "Envio via portal fornecedor",
|
||||
formFields: {
|
||||
data_abertura: self.value("#data_abertura"),
|
||||
emitido_por: self.value("#emitido_por"),
|
||||
entidade_responsavel: self.value("#entidade_responsavel"),
|
||||
tipo_cadastro: tipoCadastro,
|
||||
emailSolicitante: self.value("#emailSolicitante"),
|
||||
cpf: cpfField || documentoPessoa,
|
||||
tipo_documento: self.value("#tipo_documento"),
|
||||
numero_documento: numeroDocumento,
|
||||
valor: valor,
|
||||
justificativa: self.value("#justificativa")
|
||||
}
|
||||
};
|
||||
|
||||
window.__portalfornecedor_lastProcessPayload = payloadProcesso;
|
||||
console.log("[portalfornecedor] payload direto processo:", payloadProcesso);
|
||||
window.__portalfornecedor_lastProcessPayload = payloadProcesso;
|
||||
console.log("[portalfornecedor] payload endpoint:", payloadProcesso);
|
||||
|
||||
self.enviarDiretoProcesso(payloadProcesso)
|
||||
.done(function (response) {
|
||||
console.log("[portalfornecedor] response processo direto:", response);
|
||||
self.setLoading(false);
|
||||
self.renderSuccessState(response);
|
||||
})
|
||||
.fail(function (xhrDireto) {
|
||||
self.setLoading(false);
|
||||
console.warn("[portalfornecedor] falha no envio direto:", xhrDireto);
|
||||
console.error("[portalfornecedor] detalhe erro processo direto:", {
|
||||
status: xhrDireto.status,
|
||||
statusText: xhrDireto.statusText,
|
||||
responseText: xhrDireto.responseText
|
||||
});
|
||||
self.setStatus("error", "Falha ao iniciar processo. Veja o console para detalhes.");
|
||||
FLUIGC.toast({
|
||||
title: "Erro",
|
||||
message: "Falha ao iniciar processo. Veja o console para detalhes.",
|
||||
type: "danger"
|
||||
});
|
||||
});
|
||||
})
|
||||
.fail(function (uploadErr) {
|
||||
this.enviarViaEndpoint(payloadProcesso, this.anexoInfo.file)
|
||||
.done(function (response) {
|
||||
console.log("[portalfornecedor] response endpoint:", response);
|
||||
self.setLoading(false);
|
||||
console.error("[portalfornecedor] falha upload documento ECM:", uploadErr);
|
||||
self.setStatus("error", "Falha ao enviar anexo para o GED.");
|
||||
self.renderSuccessState(response);
|
||||
})
|
||||
.fail(function (xhr) {
|
||||
self.setLoading(false);
|
||||
console.warn("[portalfornecedor] falha no envio via endpoint:", xhr);
|
||||
console.error("[portalfornecedor] detalhe erro endpoint:", {
|
||||
status: xhr.status,
|
||||
statusText: xhr.statusText,
|
||||
responseText: xhr.responseText
|
||||
});
|
||||
self.setStatus("error", self.extractEndpointErrorMessage(xhr));
|
||||
FLUIGC.toast({
|
||||
title: "Erro",
|
||||
message: "Falha ao enviar anexo para o GED.",
|
||||
message: "Falha ao enviar pelo endpoint do portal.",
|
||||
type: "danger"
|
||||
});
|
||||
});
|
||||
@@ -270,67 +216,68 @@ var MyWidget = SuperWidget.extend({
|
||||
return "";
|
||||
},
|
||||
|
||||
enviarDiretoProcesso: function (payloadProcesso) {
|
||||
enviarViaEndpoint: function (payloadProcesso, file) {
|
||||
return $.ajax({
|
||||
url: "/process-management/api/v2/processes/FlowEssentials_LancamentodeDocumento/start",
|
||||
url: this.getPublicEndpointUrl(),
|
||||
type: "POST",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(payloadProcesso)
|
||||
data: this.buildMultipartData(payloadProcesso, file),
|
||||
processData: false,
|
||||
contentType: false
|
||||
});
|
||||
},
|
||||
|
||||
uploadAnexoToECM: function (file) {
|
||||
var self = this;
|
||||
var dfd = $.Deferred();
|
||||
var fileName = file.name;
|
||||
var uploadUrl = "/api/public/2.0/contentfiles/upload/?fileName=" + encodeURIComponent(fileName);
|
||||
getPublicEndpointUrl: function () {
|
||||
if (window.portalfornecedorConfig && window.portalfornecedorConfig.publicEndpointUrl) {
|
||||
return window.portalfornecedorConfig.publicEndpointUrl;
|
||||
}
|
||||
|
||||
fetch(uploadUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/octet-stream"
|
||||
},
|
||||
body: file
|
||||
})
|
||||
.then(function (resp) {
|
||||
if (!resp.ok) throw new Error("Falha no upload binario");
|
||||
return resp.text();
|
||||
})
|
||||
.then(function () {
|
||||
var companyId = (window.WCMAPI && WCMAPI.organizationId) ? String(WCMAPI.organizationId) : "1";
|
||||
var createPayload = {
|
||||
companyId: companyId,
|
||||
description: fileName,
|
||||
parentId: self.gedParentFolderId,
|
||||
immutable: true,
|
||||
isPrivate: false,
|
||||
downloadEnabled: true,
|
||||
attachments: [{ fileName: fileName }]
|
||||
};
|
||||
return "https://api.grupoginseng.com.br/v2/api/public/portalfornecedor/enviar";
|
||||
},
|
||||
|
||||
return fetch("/api/public/ecm/document/createDocument", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json;charset=utf-8"
|
||||
},
|
||||
body: JSON.stringify(createPayload)
|
||||
});
|
||||
})
|
||||
.then(function (resp) {
|
||||
if (!resp.ok) throw new Error("Falha ao criar documento no GED");
|
||||
return resp.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
var content = data && data.content ? data.content : {};
|
||||
var documentId = content.id || content.documentId;
|
||||
if (!documentId) throw new Error("GED nao retornou documentId");
|
||||
dfd.resolve({ documentId: documentId, raw: data });
|
||||
})
|
||||
.catch(function (err) {
|
||||
dfd.reject(err);
|
||||
});
|
||||
buildMultipartData: function (payloadProcesso, file) {
|
||||
var formData = new FormData();
|
||||
var formFields = payloadProcesso && payloadProcesso.formFields ? payloadProcesso.formFields : {};
|
||||
var keys = Object.keys(formFields);
|
||||
|
||||
return dfd.promise();
|
||||
formData.append("targetState", String(payloadProcesso.targetState || 5));
|
||||
formData.append("comment", payloadProcesso.comment || "");
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
formData.append(key, formFields[key] == null ? "" : String(formFields[key]));
|
||||
}
|
||||
|
||||
if (file) {
|
||||
formData.append("arquivo", file, file.name || "anexo");
|
||||
}
|
||||
|
||||
return formData;
|
||||
},
|
||||
|
||||
extractEndpointErrorMessage: function (xhr) {
|
||||
if (!xhr || !xhr.responseText) {
|
||||
return "Falha ao enviar pelo endpoint do portal. Veja o console para detalhes.";
|
||||
}
|
||||
|
||||
try {
|
||||
var payload = JSON.parse(xhr.responseText);
|
||||
if (payload && payload.message) {
|
||||
return String(payload.message);
|
||||
}
|
||||
if (payload && payload.detail && typeof payload.detail === "string") {
|
||||
return String(payload.detail);
|
||||
}
|
||||
if (payload && payload.detail && payload.detail.message) {
|
||||
return String(payload.detail.message);
|
||||
}
|
||||
if (payload && payload.detailedMessage) {
|
||||
return String(payload.detailedMessage);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return xhr.responseText;
|
||||
},
|
||||
|
||||
setLoading: function (isLoading, message) {
|
||||
@@ -379,6 +326,8 @@ var MyWidget = SuperWidget.extend({
|
||||
this.clearFieldError("#cpf");
|
||||
}
|
||||
|
||||
if (!this.anexoInfo || !this.anexoInfo.file) ok = this.markRequired("#arquivoLocal") && ok;
|
||||
|
||||
return ok;
|
||||
},
|
||||
|
||||
@@ -457,4 +406,3 @@ var MyWidget = SuperWidget.extend({
|
||||
return (b / 1048576).toFixed(2) + " MB";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user