public/js/atk-vue-tree-item-selector.min.js

Summary

Maintainability
A
0 mins
Test Coverage
"use strict";(self.webpackChunkatk=self.webpackChunkatk||[]).push([[507],{42973:(t,e,i)=>{i.r(e),i.d(e,{default:()=>o});i(70501),i(23552),i(22625),i(70540),i(37322),i(30259),i(27935),i(39589),i(52854),i(52860),i(30041),i(1096),i(19906),i(32253),i(68768),i(62699),i(76621),i(2503),i(63548),i(35107),i(19407),i(35374),i(66049),i(76777),i(77719),i(10005),i(30572),i(10511);var n=i(21145),s=i.n(n);const o={name:"AtkTreeItemSelector",template:'\n        <div class="item" :style="itemMargin">\n            <i :class="toggleIcon" v-show="!isRoot" @click="onToggleShow" />\n            <i :class="getIcon" v-show="!isRoot" @click="onToggleSelect" />\n            <div class="content">\n                <div :style="itemCursor" @click="onToggleSelect">{{title}}</div>\n                <div v-if="isParent" class="list" v-show="open || isRoot">\n                    <AtkTreeItemSelector\n                        v-for="item in item.nodes" :key="item.id"\n                        :item="item"\n                        :values="values"\n                    ></AtkTreeItemSelector>\n                </div>\n            </div>\n        </div>',props:{item:Object,values:Array},inject:["getRootData"],data:function(){return{open:!1,isRoot:"atk-root"===this.item.id,isInitialized:!1,id:this.item.id,nodes:this.item.nodes,icons:{single:{on:"circle",off:"circle outline",indeterminate:"dot circle outline"},multiple:{on:"check square outline",off:"square outline",indeterminate:"minus square outline"}}}},created:function(){this.getInitData()},mounted:function(){},computed:{itemMargin:function(){return{marginLeft:this.item.nodes&&this.item.nodes.length>0?this.open?"-13px":"-10px":null}},itemCursor:function(){return{cursor:this.isParent&&"single"===this.getRootData().options.mode?"default":"pointer"}},title:function(){return this.item.name},isParent:function(){return this.nodes&&this.nodes.length>0},toggleIcon:function(){return this.isParent?(this.open?"caret down":"caret right")+" icon":null},state:function(){let t="off";return this.isParent?t=this.hasAllFill(this.nodes)?"on":this.hasSomeFill(this.nodes)?"indeterminate":"off":this.isSelected(this.id)&&(t="on"),t},getIcon:function(){return this.icons[this.getRootData().options.mode][this.state]+" icon"}},methods:{isSelected:function(t){return this.values.includes(t)},getInitData:function(){this.getRootData().item.isInitialized||(this.getRootData().values=this.getValues(),this.getRootData().item.isInitialized=!0)},getValues:function(){const t=JSON.parse(this.getInputElement().value);let e=[];return Array.isArray(t)?e=t:e.push(t),e},hasAllFill:function(t){let e=!0;for(const i of t)if(i.nodes&&i.nodes.length>0){if(!this.hasAllFill(i.nodes)){e=!1;break}}else if(!this.values.includes(i.id)){e=!1;break}return e},hasSomeFill:function(t){let e=!1;for(const i of t){if(i.nodes&&i.nodes.length>0&&this.hasSomeFill(i.nodes)){e=!0;break}if(this.values.includes(i.id)){e=!0;break}}return e},onToggleShow:function(){this.isParent&&(this.open=!this.open)},onToggleSelect:function(){const{options:t}=this.getRootData();switch(t.mode){case"single":this.handleSingleSelect();break;case"multiple":this.handleMultipleSelect()}},mergeArrays:function(){let t=[];for(var e=arguments.length,i=new Array(e),n=0;n<e;n++)i[n]=arguments[n];for(const e of i)t=[...t,...e];return[...new Set(t)]},collectAllChildren:function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(const i of t)i.nodes&&i.nodes.length>0?e=[...e,...this.collectAllChildren(i.nodes,e)]:e.push(i.id);return e},remove:function(t,e){return t.filter((t=>t!==e))},handleSingleSelect:function(){"off"!==this.state||this.isParent||(this.getRootData().values=[this.item.id],this.setInput(this.item.id),this.getRootData().options.url&&this.postValue()),this.isParent&&(this.open=!this.open)},handleMultipleSelect:function(){let t;if(this.isParent){const e=this.collectAllChildren(this.nodes);if("off"===this.state||"indeterminate"===this.state)t=this.mergeArrays(this.values,e);else{let i=this.values;for(const t of e)i=this.remove(i,t);t=i}}else"on"===this.state?t=this.remove(this.values,this.item.id):"off"===this.state&&(t=this.values,t.push(this.item.id));this.getRootData().values=[...t],this.setInput(JSON.stringify(t)),this.getRootData().options.url&&this.postValue()},setInput:function(t){this.getInputElement().value=t},getInputElement:function(){return document.getElementsByName(this.getRootData().field)[0]},postValue:function(){s()(this.$el).parents("."+this.getRootData().options.loader).api({on:"now",url:this.getRootData().options.url,method:"POST",data:{data:JSON.stringify(this.getRootData().values)}})}}}}}]);
//# sourceMappingURL=atk-vue-tree-item-selector.min.js.map