2026-03-18 10:17:16 -03:00

2 lines
5.7 KiB
JavaScript

!function(t){"use strict";const e="fluigFormAttachment",n="BtnDeleteFile",i="BtnUploadFile",a="BtnViewerFile",s=[".7z",".zip",".rar",".gz",".tar",".tbz2",".tgz",".bz2",".lz",".lz4",".txz",".xz",".z",".zst",".zstd",".war",".ear",".jar",".apk",".arj",".ace",".cab"],o=t=>"string"==typeof t,r=t=>parent.ECM.attachmentTable.getData().findIndex(e=>e.description===t),c={showActionButton:!0,filename:"Anexo",prefixName:!1,accept:"*"};class h{#t;#e;#n;#i;constructor(s,o){s.id||"input"!==s.nodeName.toLowerCase()||(s.id=FLUIGC.utilities.randomUUID()),this.#t=t.extend({},c,o),this.#e=t(s),this.#i=this.#e.val()||this.#e.text().trim(),this.#e.prop("readonly",!0).on("change",()=>{this.#i=this.#e.val(),this.#a()}).wrap(`<div class="${e}Component"></div>`).after(`<div class="${e}Component_buttons">${this.#s()}</div>`),this.#n=this.#e.closest(`.${e}Component`),this.#n.on("click",`.${e}${n}`,()=>this.#o()).on("click",`.${e}${i}`,()=>this.#r()).on("click",`.${e}${a}`,()=>this.#c())}isValid(){return!this.#i.length||this.hasAttachment()}hasAttachment(){const t=this.#i||this.#e.val()||this.#e.text().trim();return t.length>0&&-1!==r(t)}deleteAttachment(){const t=parent.ECM.attachmentTable.getData().findIndex(t=>t.description===this.#i);setTimeout(()=>this.#e.val("").trigger("change"),500),-1!==t&&parent.WKFViewAttachment.removeAttach([t])}showActionButton(){this.#t.showActionButton=!0,this.#e.trigger("change")}hideActionButton(){this.#t.showActionButton=!1,this.#e.trigger("change")}filename(t,e){if(void 0===t)return this.#e.data("filename")||this.#t.filename;this.#t.filename=t,this.#e.data("filename",t),void 0!==e&&this.prefixName(e)}prefixName(t){if(void 0===t)return this.#t.prefixName;this.#t.prefixName=t}#s(){const t=0!==this.#i.length,s=this.#h();return`<button type="button" class="${e}BtnAction ${e}${n} btn btn-danger btn-sm ${s&&t?"":"hide"}" title="Remover Anexo"><i class="flaticon flaticon-trash icon-sm"></i></button><button type="button" class="${e}BtnAction ${e}${i} btn btn-success btn-sm ${s&&!t?"":"hide"}" title="Enviar Anexo"><i class="flaticon flaticon-upload icon-sm"></i></button><button type="button" class="${e}${a} btn btn-info btn-sm ${t?"":"hide"}" title="Visualizar Anexo"><i class="flaticon flaticon-view icon-sm"></i></button>`}#h(){const t=this.#e.get(0);return this.#t.showActionButton&&parent.ECM.workflowView.userPermissions.indexOf("P")>=0&&location.href.includes("ManagerMode")&&!location.href.includes("token")&&"input"===t.nodeName.toLowerCase()&&!t.disabled}#a(){const t=0!==this.#i.length;this.#h()?t?(this.#n.find(`.${e}${i}`).addClass("hide"),this.#n.find(`.${e}${n}`).removeClass("hide")):(this.#n.find(`.${e}${n}`).addClass("hide"),this.#n.find(`.${e}${i}`).removeClass("hide")):this.#n.find(`.${e}BtnAction`).addClass("hide"),t?this.#n.find(`.${e}${a}`).removeClass("hide"):this.#n.find(`.${e}${a}`).addClass("hide")}#o(){this.#h()&&FLUIGC.message.confirm({message:`Deseja remover o anexo <b>${this.#i}</b>?`,title:"Confirmação",labelYes:"Sim, quero remover",labelNo:"Não, quero cancelar"},t=>{t&&this.deleteAttachment()})}#r(){if(!this.#h())return;let t=this.#e.data("filename")||this.#t.filename;!0===this.#t.prefixName?t=FLUIGC.utilities.randomUUID().substring(0,9)+t:!1!==this.#t.prefixName&&o(this.#t.prefixName)&&(t=`${this.#t.prefixName}-${t}`),-1===r(t)?parent.$("#ecm-navigation-inputFile-clone").attr({"data-on-camera":"true","data-file-name-camera":t,"data-inputid":this.#e.attr("id"),"data-filename":t,multiple:!1,accept:this.#e.data("accept")||this.#t.accept}).trigger("click"):FLUIGC.toast({title:"Atenção",message:"Já existe um anexo com essa descrição",type:"warning"})}#c(){const t=parent.ECM.attachmentTable.getData().findIndex(t=>t.description===this.#i);if(-1===t)return void FLUIGC.toast({title:"Atenção",message:"Anexo não encontrado",type:"warning"});const e=parent.ECM.attachmentTable.getRow(t),n=String(e.physicalFileName||e.fileName||e.name||"").toLowerCase(),i=s.some(t=>n.endsWith(t));e.documentId&&!i?parent.WKFViewAttachment.openAttachmentView(parent.WCMAPI.userCode,e.documentId,e.version):parent.WKFViewAttachment.downloadAttach([t])}}if(t.fn[e]=function(n){if(!parent.WKFViewAttachment||!parent.ECM||!parent.ECM.attachmentTable)return console.error(`Plugin ${e} executado fora de um processo.`),this;if(o(n)){const i=n,a=Array.prototype.slice.call(arguments,1);let s;return this.each(function(){let n=t.data(this,e);if(n||(n=new h(this,{}),t.data(this,e,n)),n[i])return s=n[i](...a),void 0===s&&void 0}),void 0!==s?s:this}return this.each(function(){t.data(this,e)||t.data(this,e,new h(this,n))})},!parent.WKFViewAttachment||!parent.ECM||!parent.ECM.attachmentTable)return;const l=FLUIGC.loading(window,{title:"Aguarde",textMessage:"Enviando arquivo"});t(()=>{t("#tab-attachments",parent.document).hide(),parent.$("#ecm_navigation_fileupload").on(`fileuploadadd.${e}`,function(t,e){const n=e.files[0];parent.ECM.maxUploadSize>0&&n.size>=1024*parent.ECM.maxUploadSize*1024||parent.ECM.newAttachmentsDocs.length&&-1!==parent.ECM.newAttachmentsDocs.findIndex(t=>t.name===n.name)||l.show()}).on(`fileuploadfail.${e}`,()=>l.hide()).on(`fileuploaddone.${e}`,function(){l.hide();const e=parent.document.getElementById("ecm-navigation-inputFile-clone"),n=e.getAttribute("data-filename");-1!==r(n)&&t(`#${e.getAttribute("data-inputid")}`).val(n).trigger("change")}),parent.$(document).on(`fileuploadstop.${e}`,()=>l.hide())}),t("head").append(`<style>\n.${e}Component { display: flex; align-items: center; flex-wrap: nowrap; }\n.${e}Component input { border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }\n.${e}Component_buttons { display: flex; align-items: center; justify-content: flex-end; }\n.${e}Component_buttons .btn { outline: none !important; outline-offset: unset !important; border-radius: 0 !important; height: 32px; }\n</style>`)}(jQuery);