"use strict";(self["webpackChunkcarabi_x2"]=self["webpackChunkcarabi_x2"]||[]).push([[8589],{8869:function(t,e,s){s.r(e),s.d(e,{default:function(){return u}});var i=function(){var t=this,e=t._self._c;return t.loading?t._e():e("Modal",{ref:"modal",attrs:{title:t.field.DOCPROP_NAME,fullHeight:!1,large:!1,autoOpen:!0},on:{opened:t.opened,closed:t.closed}},[e("div",{staticClass:"uk-padding-small"},[e("div",{},[e("input",{directives:[{name:"model",rawName:"v-model",value:t.context,expression:"context"}],ref:"context",staticClass:"uk-input",attrs:{type:"text",placeholder:"Поиск"},domProps:{value:t.context},on:{keydown:t.keydown,input:function(e){e.target.composing||(t.context=e.target.value)}}})])]),e("div",{ref:"options",staticClass:"cb-container uk-padding-small"},[e("ul",{staticClass:"cb-select"},t._l(t.options,(function(s,i){return e("li",{key:s.VALUE_ID,class:{"cb-active":t.curIndex==i,"cb-selected":s.selected},on:{click:function(e){return t.selectOpt(s)}}},[s.selected?t._e():e("i",{staticClass:"far fa-square"}),s.selected?e("i",{staticClass:"far fa-check-square"}):t._e(),t._v(" "+t._s(s.VALUE)),s.NAME?[t._v(" - "+t._s(s.NAME))]:t._e()],2)})),0)]),e("div",{staticClass:"uk-padding-small",staticStyle:{"padding-top":"0"}},[e("div",{staticClass:"uk-text-small uk-text-muted uk-margin-small-bottom"},[t._v(' "ESC" - отмена, "ENTER" - выбрать, "CTRL+ENTER" - сохранить и выйти ')]),e("div",{staticClass:"flex-row"},[e("div",{staticClass:"uk-text-left"},[t.multiple?e("button",{staticClass:"uk-button uk-margin-small-left",attrs:{disabled:t.saving},on:{click:t.selectAll}},[t._v(" Выбрать все ")]):t._e()]),e("div",{staticClass:"uk-text-right flex-grow"},[e("button",{staticClass:"uk-modal-close uk-button",attrs:{disabled:t.saving}},[e("i",{staticClass:"uk-icon-close"}),t._v(" Отмена ")]),e("button",{staticClass:"uk-button uk-button-primary uk-margin-small-left",attrs:{disabled:t.saving},on:{click:t.save}},[e("i",{staticClass:"uk-icon-floppy-o"}),t._v(" Применить ")])])])])])},l=[],a=s(3216),n={name:"fieldDictionary",components:{Modal:()=>s.e(8362).then(s.bind(s,2215))},data(){return{context:"",fullOptions:[],curIndex:0,loading:!0,saving:!1}},props:{field:Object,value:{type:[String,Array],default:null}},computed:{multiple(){return!!this.field.DOCPROP_MULTI},lowerContext(){return this.context.trim().toLowerCase()},options(){return this.lowerContext.length?this.fullOptions.filter((t=>-1!==t.context.indexOf(this.lowerContext))):this.fullOptions}},watch:{lowerContext(){this.curIndex=0},async curIndex(){await this.$nextTick();let t=this.$refs.options.querySelector(".cb-active");if(t){let e=t.offsetTop-t.offsetParent.scrollTop,s=e+t.offsetHeight,i=t.offsetParent.clientHeight;e<0&&(t.offsetParent.scrollTop+=e),s>i&&(t.offsetParent.scrollTop+=s-i)}}},async mounted(){await this.load()},methods:{opened(){this.$refs.context.focus()},closed(){this.saving?this.$emit("change",{value:this.newValues,display:this.newDisplay}):this.$emit("close")},keydown(t){"ArrowDown"===t.key&&(t.preventDefault(),this.curIndex+1<this.options.length&&this.curIndex++),"ArrowUp"===t.key&&(t.preventDefault(),this.curIndex>0&&this.curIndex--),"Enter"===t.key&&(t.preventDefault(),t.ctrlKey?this.save():this.selectOpt(this.options[this.curIndex]))},async load(){if(this.loading=!0,this.newValues=[],this.multiple){if(!Array.isArray(this.value))throw new Error("Dictionary: Multiple value is not array");for(let t in this.value)this.newValues.push(parseInt(this.value[t]))}else this.value&&(this.newValues=[parseInt(this.value)]);await this.loadOptions(),console.log("values",this.newValues),this.rawOptions.forEach((t=>{let e=this.newValues.find((e=>e===t.CODE));t.selected=!!e})),this.fullOptions=this.rawOptions,this.loading=!1},async loadOptions(){if(11===this.field.DOCPROP_KIND){let t=await a.vd.select("CARD_POPUP_TABLE_SELECT_CS",{document_id:this.field.DOCUMENT_ID,docprop_id:this.field.DOCPROP_ID},1e4);this.rawOptions=t.map((t=>({CODE:t.ID,NAME:null,PARENT:0,VALUE:t.VALUE,VALUE_ID:t.ID})))}else this.rawOptions=await a.vd.select("CARD_POPUP_VOCAB_CS",{VOCAB_NAME:this.field.DOCPROP_OBJECT},1e4);this.rawOptions.forEach((t=>{t.VALUE||(t.VALUE="(Безымянный)"),t.context=t.VALUE.toLowerCase(),t.NAME&&(t.context+=" - "+t.NAME.toLowerCase())}))},selectOpt(t){this.multiple||this.fullOptions.forEach((t=>{t.selected=!1})),t.selected=!t.selected,this.$refs.context.focus(),this.multiple||this.save()},async save(){this.saving=!0;let t=this.fullOptions.filter((t=>t.selected));this.newValues=t.map((t=>t.CODE)),this.newDisplay=t.map((t=>t.VALUE)).join(", "),this.multiple||(this.newValues.length>0?this.newValues=this.newValues[0].toString():this.newValues=""),console.log("set value",this.newValues,this.newDisplay),this.$refs.modal.close()},async selectAll(){for(let t of this.fullOptions)t.selected=this.options.includes(t);await this.save()}}},o=n,c=s(1656),r=(0,c.A)(o,i,l,!1,null,null,null),u=r.exports}}]);
//# sourceMappingURL=FieldDictionary.91df87ce.js.map