"use strict";(self["webpackChunkcarabi_x2"]=self["webpackChunkcarabi_x2"]||[]).push([[7918],{3334:function(t,a,e){e.r(a),e.d(a,{default:function(){return g}});var s=function(){var t=this,a=t._self._c;return a("Modal",{ref:"modal",attrs:{title:t.field.DOCPROP_NAME,fullHeight:!1,large:!1,autoOpen:!0,closable:!t.saving},on:{opened:t.opened,closing:t.closing}},[t.loading?t._e():[a("div",{staticClass:"uk-card uk-card-default uk-padding uk-placeholder uk-text-center"},[a("div",{staticStyle:{"text-align":"center"}},[a("img",{attrs:{src:t.attach?t.icons.iconFileFull:t.icons.iconFileEmpty,width:"64",height:"64","uk-svg":""}})]),a("span",{staticClass:"uk-text-middle",domProps:{textContent:t._s(t.attach?t.attach.DOC_NAME:"Файл не загружен")}}),t.readonly?a("div",{staticClass:"uk-text-center uk-text-muted"},[t._v(" только для чтения ")]):t._e()]),a("div",{directives:[{name:"show",rawName:"v-show",value:t.saving,expression:"saving"}],staticClass:"uk-padding-small"},[a("progress",{staticClass:"uk-progress",staticStyle:{margin:"0"},attrs:{max:"100"},domProps:{value:t.progress}})]),t.attach||!t.readonly?a("div",{directives:[{name:"show",rawName:"v-show",value:!t.saving,expression:"!saving"}],staticClass:"uk-padding-small"},[a("div",{staticClass:"uk-text-center"},[t.attach||t.readonly?t._e():a("div",{ref:"upload",attrs:{"uk-form-custom":""}},[a("input",{ref:"uploadInput",attrs:{type:"file"},on:{change:function(a){return t.upload(a)}}}),a("button",{staticClass:"uk-button uk-button-success uk-border-rounded uk-margin-right",attrs:{type:"button",tabindex:"-1"}},[a("i",{staticClass:"fas fa-cloud-upload-alt"}),t._v(" Загрузить ")])]),t.attach&&!t.readonly?a("button",{staticClass:"uk-button uk-button-danger uk-border-rounded uk-margin-right",attrs:{type:"button"},on:{click:function(a){return t.deleteVal()}}},[a("i",{staticClass:"fas fa-trash-alt"}),t._v(" Удалить ")]):t._e(),t.attach&&!t.readonly?a("div",{ref:"upload",attrs:{"uk-form-custom":""}},[a("input",{ref:"uploadInput",attrs:{type:"file"},on:{change:function(a){return t.upload(a)}}}),a("button",{staticClass:"uk-button uk-button-success uk-border-rounded uk-margin-right",attrs:{type:"button",tabindex:"-1"}},[a("i",{staticClass:"fas fa-cloud-upload-alt"}),t._v(" Заменить ")])]):t._e(),t.attach?a("button",{staticClass:"uk-button uk-button-primary uk-border-rounded",attrs:{type:"button"},on:{click:function(a){return t.downloadVal()}}},[a("i",{staticClass:"fas fa-download"}),t._v(" Скачать ")]):t._e()])]):t._e()]],2)},i=[],n=e.p+"img/file.1f40a98e.svg",l=e.p+"img/file-alt.f13d4243.svg",o=e(3216),r=e(2643),u={name:"mediaModal",components:{Modal:()=>e.e(8362).then(e.bind(e,2215))},data(){return{loading:!0,saving:!1,changed:!1,attach:null,progress:0}},props:{field:Object,value:{type:String,default:null}},computed:{intValue(){let t=parseInt(this.value);return isNaN(t)?null:t},readonly(){return!this.field||!!this.field.DOCPROP_READONY},icons:()=>({iconFileEmpty:n,iconFileFull:l})},created(){},async mounted(){await this.load()},methods:{async load(){this.loading=!0;let t=await o.FH.fileStorage.getAttachList(this.field.DOCUMENT_ID);this.attach=t.find((t=>t.DOCUMENT_ID===this.intValue)),this.loading=!1},opened(){},closing(){this.changed||this.$emit("close")},async upload(t){const a=t.target.files[0];if(a){this.saving=!0,this.progress=0;try{this.attach&&await o.FH.fileStorage.deleteFiles([this.attach.DOCUMENT_ID],this.field.DOCUMENT_ID,"document");let t=await o.FH.fileStorage.uploadAttach(this.field.DOCUMENT_ID,a,((t,a)=>{this.progress=Math.floor(100*t/a)}));this.saving=!1,this.changed=!0,await this.$nextTick(),this.$emit("change",{value:t,display:a.name}),this.$refs.modal.close()}catch(e){this.saving=!1,(0,r.Qg)(e),await this.load()}}},async deleteVal(){if(this.attach){this.saving=!0,this.progress=0;try{await o.FH.fileStorage.deleteFiles([this.attach.DOCUMENT_ID],this.field.DOCUMENT_ID,"document"),this.saving=!1,this.changed=!0,await this.$nextTick(),this.$emit("change",{value:0,display:""}),this.$refs.modal.close()}catch(t){this.saving=!1,(0,r.Qg)(t),await this.load()}}},async downloadVal(){let t=await o.FH.fileStorage.getAttachUrl(this.intValue);window.open(t,"_blank")},close(){this.$refs.modal.close()}}},d=u,c=e(1656),h=(0,c.A)(d,s,i,!1,null,null,null),g=h.exports}}]);
//# sourceMappingURL=FieldMediaModal.a52f16a2.js.map