Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function uploadFile(elem) {
- // Pasta na qual será inserido o arquivo
- var folder = parseInt($("#pastaAnexos").val());
- // Nome do campo (pai x filho) que armazena o ID do documento
- var documentIdField = "#anexoId";
- var btnDelete = ".btnDelete";
- // Exibir imagem de carregando
- var loading = FLUIGC.loading(window);
- // ID do input:file
- var rowId = elem.id.split('___')[1];
- $('.file').fileupload({
- dataType: 'json',
- start: function (e, data) {
- loading.show();
- },
- done: function (e, data) {
- var newDocumentId = saveDocument(data.result.files, folder, rowId)[0];
- var newIdfield = documentIdField + "___" + rowId;
- $(newIdfield).val(newDocumentId);
- $(newIdfield).parent().find(btnDelete).show();
- },
- fail: function (e, data) {
- console.log('File upload error:');
- console.error(e);
- console.error(data);
- console.log(data.messages);
- },
- stop: function (e, data) {
- loading.hide();
- }
- });
- };
- function saveDocument(documents, folder, rowId) {
- documentIDs = [];
- for (let i = 0; i < documents.length; i++) {
- var document = documents[i];
- var data = {
- 'description': document.name,
- 'parentId': folder,
- 'attachments': [{
- 'fileName': document.name
- }]
- };
- parent.WCMAPI.Create({
- async: false,
- type: 'POST',
- contentType: 'application/json',
- url: '/api/public/ecm/document/createDocument',
- data: JSON.stringify(data),
- error: function (err) {
- FLUIGC.toast({
- title: 'Falha ao Enviar',
- message: 'Não foi possível enviar o arquivo ' + document.name,
- type: 'danger'
- });
- console.error(err);
- },
- success: function (response) {
- FLUIGC.toast({
- title: 'Sucesso:',
- message: 'Documento ' + document.name + ' publicado',
- type: 'success'
- });
- console.log("File uploaded:");
- console.log(response);
- var newDocumentId = response.content.id;
- documentIDs.push(newDocumentId);
- },
- });
- }
- return documentIDs;
- };
- function openDocument(elem) {
- var documentId = $(elem).parent().find(".anexo-id").val();
- if (!documentId) {
- FLUIGC.toast({
- title: 'Ops...',
- message: 'O anexo ainda não foi carregado.',
- type: 'warning'
- });
- } else {
- fluigViewDocument(documentId);
- }
- }
- function clickDeleteDocument(elem, force) {
- var documentId = $(elem).parent().find(".anexo-id").val();
- if (!documentId) {
- FLUIGC.toast({
- title: 'Ops...',
- message: 'O anexo ainda não foi carregado.',
- type: 'warning'
- });
- } else if (force) {
- deleteAttachment(elem, documentId);
- } else {
- FLUIGC.message.confirm({
- message: 'Quer mesmo remover este anexo?',
- title: 'Remover anexo',
- labelYes: 'Remover',
- labelNo: 'Cancelar'
- }, function(result) {
- if (!result) return;
- deleteAttachment(elem, documentId);
- });
- }
- }
- function deleteAttachment(btnDelete, documentId) {
- deleteDocument(documentId).success(data => {
- if (data.content && data.content == "OK") {
- $(btnDelete).hide();
- $(btnDelete).parent().find(".anexo-id").val("");
- FLUIGC.toast({
- title: 'Sucesso: ',
- message: 'O arquivo de ID <b>' + documentId + '</b> foi removido.',
- type: 'success'
- });
- } else {
- console.error("Erro ao remover arquivo:");
- console.log(data);
- FLUIGC.toast({
- title: 'Erro: ',
- message: 'O arquivo de ID <b>' + documentId + '</b> não pôde ser removido.',
- type: 'danger'
- });
- }
- });
- }
- function fluigViewDocument(documentId) {
- var parentOBJ;
- if (window.opener) {
- parentOBJ = window.opener.parent;
- } else {
- parentOBJ = parent;
- }
- var data = {
- url: "/ecm_documentview/documentView.ftl",
- maximized: true,
- title: "Visualizador de Documentos",
- callBack: function () {
- parentOBJ.ECM.documentView.getDocument(parseInt(documentId), 1000);
- },
- customButtons: []
- };
- parentOBJ.ECM.documentView.panel = parentOBJ.WCMC.panel(data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement