@kingscode/vuetify-resource
Version:
An easy way to create a resource list with the vuetify data table with default create update and delete dialogs/actions and potential your own actions
2 lines • 27 kB
JavaScript
(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t(require("vuetify/lib")):"function"===typeof define&&define.amd?define(["vuetify/lib"],t):"object"===typeof exports?exports["vuetify-resource"]=t(require("vuetify/lib")):e["vuetify-resource"]=t(e["vuetify/lib"])})("undefined"!==typeof self?self:this,(function(e){return function(e){var t={};function a(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,a),n.l=!0,n.exports}return a.m=e,a.c=t,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)a.d(r,n,function(t){return e[t]}.bind(null,n));return r},a.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s="fb15")}({"0457":function(e,t,a){var r=a("83bc");r.__esModule&&(r=r.default),"string"===typeof r&&(r=[[e.i,r,""]]),r.locals&&(e.exports=r.locals);var n=a("499e").default;n("5ebb045f",r,!0,{sourceMap:!1,shadowMode:!1})},"24fb":function(e,t,a){"use strict";function r(e,t){var a=e[1]||"",r=e[3];if(!r)return a;if(t&&"function"===typeof btoa){var i=n(r),o=r.sources.map((function(e){return"/*# sourceURL=".concat(r.sourceRoot||"").concat(e," */")}));return[a].concat(o).concat([i]).join("\n")}return[a].join("\n")}function n(e){var t=btoa(unescape(encodeURIComponent(JSON.stringify(e)))),a="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(t);return"/*# ".concat(a," */")}e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var a=r(t,e);return t[2]?"@media ".concat(t[2]," {").concat(a,"}"):a})).join("")},t.i=function(e,a,r){"string"===typeof e&&(e=[[null,e,""]]);var n={};if(r)for(var i=0;i<this.length;i++){var o=this[i][0];null!=o&&(n[o]=!0)}for(var s=0;s<e.length;s++){var l=[].concat(e[s]);r&&n[l[0]]||(a&&(l[2]?l[2]="".concat(a," and ").concat(l[2]):l[2]=a),t.push(l))}},t}},"2aa1":function(e,t,a){var r=a("5f61");r.__esModule&&(r=r.default),"string"===typeof r&&(r=[[e.i,r,""]]),r.locals&&(e.exports=r.locals);var n=a("499e").default;n("84dd6d98",r,!0,{sourceMap:!1,shadowMode:!1})},"30cb":function(e,t,a){"use strict";a("0457")},4875:function(t,a){t.exports=e},"499e":function(e,t,a){"use strict";function r(e,t){for(var a=[],r={},n=0;n<t.length;n++){var i=t[n],o=i[0],s=i[1],l=i[2],c=i[3],d={id:e+":"+n,css:s,media:l,sourceMap:c};r[o]?r[o].parts.push(d):a.push(r[o]={id:o,parts:[d]})}return a}a.r(t),a.d(t,"default",(function(){return h}));var n="undefined"!==typeof document;if("undefined"!==typeof DEBUG&&DEBUG&&!n)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var i={},o=n&&(document.head||document.getElementsByTagName("head")[0]),s=null,l=0,c=!1,d=function(){},u=null,p="data-vue-ssr-id",f="undefined"!==typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());function h(e,t,a,n){c=a,u=n||{};var o=r(e,t);return v(o),function(t){for(var a=[],n=0;n<o.length;n++){var s=o[n],l=i[s.id];l.refs--,a.push(l)}t?(o=r(e,t),v(o)):o=[];for(n=0;n<a.length;n++){l=a[n];if(0===l.refs){for(var c=0;c<l.parts.length;c++)l.parts[c]();delete i[l.id]}}}}function v(e){for(var t=0;t<e.length;t++){var a=e[t],r=i[a.id];if(r){r.refs++;for(var n=0;n<r.parts.length;n++)r.parts[n](a.parts[n]);for(;n<a.parts.length;n++)r.parts.push(g(a.parts[n]));r.parts.length>a.parts.length&&(r.parts.length=a.parts.length)}else{var o=[];for(n=0;n<a.parts.length;n++)o.push(g(a.parts[n]));i[a.id]={id:a.id,refs:1,parts:o}}}}function y(){var e=document.createElement("style");return e.type="text/css",o.appendChild(e),e}function g(e){var t,a,r=document.querySelector("style["+p+'~="'+e.id+'"]');if(r){if(c)return d;r.parentNode.removeChild(r)}if(f){var n=l++;r=s||(s=y()),t=m.bind(null,r,n,!1),a=m.bind(null,r,n,!0)}else r=y(),t=_.bind(null,r),a=function(){r.parentNode.removeChild(r)};return t(e),function(r){if(r){if(r.css===e.css&&r.media===e.media&&r.sourceMap===e.sourceMap)return;t(e=r)}else a()}}var b=function(){var e=[];return function(t,a){return e[t]=a,e.filter(Boolean).join("\n")}}();function m(e,t,a,r){var n=a?"":r.css;if(e.styleSheet)e.styleSheet.cssText=b(t,n);else{var i=document.createTextNode(n),o=e.childNodes;o[t]&&e.removeChild(o[t]),o.length?e.insertBefore(i,o[t]):e.appendChild(i)}}function _(e,t){var a=t.css,r=t.media,n=t.sourceMap;if(r&&e.setAttribute("media",r),u.ssrId&&e.setAttribute(p,t.id),n&&(a+="\n/*# sourceURL="+n.sources[0]+" */",a+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(n))))+" */"),e.styleSheet)e.styleSheet.cssText=a;else{while(e.firstChild)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(a))}}},"5f61":function(e,t,a){var r=a("24fb");t=r(!1),t.push([e.i,".indicator-overlay-wrapper .overlay[data-v-553eb051]{position:absolute;top:0;bottom:0;left:0;right:0;background:#000;opacity:.4;z-index:99;pointer-events:bounding-box}.indicator-overlay-wrapper .indicator-wrapper[data-v-553eb051]{position:absolute;left:50%;top:50%;margin-left:-35px;margin-top:-35px;z-index:100}",""]),e.exports=t},7526:function(e,t,a){"use strict";a("2aa1")},"83bc":function(e,t,a){var r=a("24fb");t=r(!1),t.push([e.i,".vuetify-resource{position:relative}.vuetify-resource .v-speed-dial{position:absolute;right:5px;top:-35px;z-index:2}.vuetify-resource.with-search .v-speed-dial{right:5px;top:15px}.vuetify-resource .has-checkboxes th:first-child:not(.column){width:40px}.vuetify-resource.row-click tr{cursor:pointer}@media only screen and (max-width:599px){.vuetify-resource.with-search .v-speed-dial{top:65px}.v-speed-dial{right:0}.vuetify-resource{margin-right:0}.datatable__actions__select,.vuetify-resource th{display:none}.vuetify-resource .has-checkboxes th:nth-child(2),.vuetify-resource th.crud-actions,.vuetify-resource th:first-child{display:table-cell}.vuetify-resource td{display:none}.vuetify-resource .has-checkboxes td:nth-child(2),.vuetify-resource td.crud-actions,.vuetify-resource td:first-child{display:table-cell}.vuetify-resource .v-data-footer__select{display:none}}",""]),e.exports=t},fb15:function(e,t,a){"use strict";if(a.r(t),"undefined"!==typeof window){var r=window.document.currentScript,n=r&&r.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);n&&(a.p=n[1])}var i=function(){var e=this,t=e._self._c;return t("div",{class:e.resourceHtmlClass},[t("v-dialog",{attrs:{fullscreen:"","hide-overlay":"",scrollable:"",transition:"dialog-bottom-transition"},model:{value:e.dialog.create,callback:function(t){e.$set(e.dialog,"create",t)},expression:"dialog.create"}},[e.dialog.create?t("v-card",{staticClass:"dialog-create-card"},[t("v-toolbar",{staticClass:"primary",staticStyle:{flex:"0 0 auto"},attrs:{dark:""}},[t("v-btn",{attrs:{dark:"",icon:""},nativeOn:{click:function(t){e.dialog.create=!1}}},[t("v-icon",[e._v("$vuetify.icons.close")])],1),t("v-toolbar-title",[e._v(e._s(e.meta.name))]),t("v-spacer"),t("v-toolbar-items",[e._t("createToolbar",(function(){return[t("v-btn",{attrs:{dark:"",text:""},on:{click:function(t){return e.createHandler()}}},[e._v(e._s(e.lang("save")))])]}))],2)],1),t("v-card-text",[e._t("createContent",(function(){return[t("activity-overlay",{model:{value:e.activity.isCreating,callback:function(t){e.$set(e.activity,"isCreating",t)},expression:"activity.isCreating"}})]}))],2)],1):e._e()],1),t("v-dialog",{attrs:{overlay:!1,fullscreen:"",scrollable:"",transition:"dialog-bottom-transition"},model:{value:e.dialog.update,callback:function(t){e.$set(e.dialog,"update",t)},expression:"dialog.update"}},[e.dialog.update?t("v-card",{staticClass:"dialog-update-card"},[t("v-toolbar",{staticClass:"primary",staticStyle:{flex:"0 0 auto"},attrs:{dark:""}},[t("v-btn",{staticClass:"close-button",attrs:{dark:"",icon:""},nativeOn:{click:function(t){return e.cancelUpdate.apply(null,arguments)}}},[t("v-icon",[e._v("$vuetify.icons.close")])],1),t("v-toolbar-title",[e._v(e._s(e.meta.name))]),t("v-spacer"),t("v-toolbar-items",[e._t("updateToolbar",(function(){return[t("v-btn",{staticClass:"save-button",attrs:{dark:"",text:""},on:{click:function(t){return e.updateHandler()}}},[e._v(e._s(e.lang("save")))])]}))],2)],1),t("v-card-text",[e._t("updateContent"),t("activity-overlay",{model:{value:e.activity.isUpdating,callback:function(t){e.$set(e.activity,"isUpdating",t)},expression:"activity.isUpdating"}})],2)],1):e._e()],1),t("v-snackbar",{attrs:{color:e.snackbar.color,timeout:2e3},model:{value:e.snackbar.active,callback:function(t){e.$set(e.snackbar,"active",t)},expression:"snackbar.active"}},[e._v(" "+e._s(e.snackbar.text)+" "),t("v-btn",{attrs:{dark:"",text:""},nativeOn:{click:function(t){e.snackbar.active=!1}}},[e._v(e._s(e.lang("close")))])],1),t("v-layout",[t("v-fab-transition",[e.speedDialNotEmpty?t("v-speed-dial",{attrs:{direction:e.speedDialDirection,"open-on-hover":!0,right:!0,top:!0,transition:"slide-y-reverse-transition"},scopedSlots:e._u([{key:"activator",fn:function(){return[t("v-btn",{attrs:{color:"accent",dark:"",fab:"",hover:""},model:{value:e.fab,callback:function(t){e.fab=t},expression:"fab"}},[e.fab?t("v-icon",[e._v("$vuetify.icons.close")]):t("v-icon",[e._v("$vuetify.icons.menu")])],1)]},proxy:!0}],null,!1,3403256918),model:{value:e.fab,callback:function(t){e.fab=t},expression:"fab"}},[t("v-tooltip",{attrs:{left:""},scopedSlots:e._u([{key:"activator",fn:function({on:a}){return[e.canUpdateResources(e.selected)&&1===e.selected.length?t("v-btn",e._g({staticClass:"edit-button",attrs:{slot:"activator",color:e.speedDialColors.edit,dark:"",fab:"",small:""},on:{click:function(t){return e.openUpdateHandler()}},slot:"activator"},a),[t("v-icon",[e._v(e._s(e.crudIcons.edit))])],1):e._e()]}}],null,!1,1122925069)},[t("span",[e._v(e._s(e.lang("update")))])]),t("v-tooltip",{attrs:{left:""},scopedSlots:e._u([{key:"activator",fn:function({on:a}){return[!0===e.canAdd?t("v-btn",e._g({staticClass:"add-button",attrs:{slot:"activator",color:e.speedDialColors.create,dark:"",fab:"",small:""},on:{click:function(t){return e.openCreateHandler()}},slot:"activator"},a),[t("v-icon",[e._v(e._s(e.crudIcons.create))])],1):e._e()]}}],null,!1,221424312)},[t("span",[e._v(e._s(e.lang("create")))])]),t("v-tooltip",{attrs:{left:""},scopedSlots:e._u([{key:"activator",fn:function({on:a}){return[e.canDeleteResources(e.selected)&&e.selected.length>=1?t("v-btn",e._g({staticClass:"delete-button",attrs:{slot:"activator",color:e.speedDialColors.delete,dark:"",fab:"",small:""},on:{click:function(t){return e.showDeleteConfirmation()}},slot:"activator"},a),[t("v-icon",[e._v(e._s(e.crudIcons.delete))])],1):e._e()]}}],null,!1,1392921430)},[t("span",[e._v(e._s(e.lang("delete")))])]),e._t("speedDialAfter",null,{resources:e.selected})],2):e._e()],1),t("v-flex",[e.canSearch?t("v-layout",{staticClass:"ma-0",attrs:{row:""}},[t("v-flex",{attrs:{"mb-3":"",sm4:"",xs10:""}},[t("v-text-field",{attrs:{"append-icon":e.$vuetify.icons.search,label:e.lang("search"),"hide-details":""},model:{value:e.search,callback:function(t){e.search=t},expression:"search"}})],1),t("v-flex",{attrs:{"mb-3":"",sm8:"",xs2:""}},[e._t("afterSearchBar")],2)],1):e._e(),t("v-data-table",e._g(e._b({staticClass:"elevation-1",class:{"has-checkboxes":e.useCheckboxes},attrs:{"footer-props":{itemsPerPageOptions:e.rowsPerPageItems},headers:e.headers,items:e.items,loading:e.loading,"mobile-breakpoint":0,options:e.pagination,"server-items-length":e.totalItems,"show-select":e.useCheckboxes,"item-key":"id"},on:{"update:options":function(t){e.pagination=t},input:e.onSelectedChange},scopedSlots:e._u([{key:"item",fn:function({item:a,isSelected:r,select:n}){return[t("tr",{class:a.itemClass,on:{click:function(t){return e.handleRowClick(a[e.resourceKeyName])}}},[e.useCheckboxes?t("td",[t("v-checkbox",{staticClass:"ma-0",attrs:{"input-value":r,"hide-details":"",primary:""},on:{click:function(e){return e.stopPropagation(),n(!r)}}})],1):e._e(),e._l(e.tableContent,(function(r){return t("td",[t(e.getColumnType(r.columnType),{tag:"component",attrs:{content:e.formatValue(r,a[r.value]),item:a,"table-column":r}})],1)})),t("td",{staticClass:"crud-actions text-right"},[e.canUpdate?t("v-tooltip",{attrs:{left:""},scopedSlots:e._u([{key:"activator",fn:function({on:r}){return[t("v-btn",e._g({staticClass:"edit-button",attrs:{color:e.crudColors.edit,disabled:!e.canUpdateResources([a]),icon:"",text:""},on:{click:function(t){return t.stopPropagation(),e.openUpdateHandler(a[e.resourceKeyName])}}},r),[t("v-icon",{attrs:{size:e.crudIconSize}},[e._v(e._s(e.crudIcons.edit))])],1)]}}],null,!0)},[t("span",[e._v(e._s(e.lang("update")))])]):e._e(),e.canDelete?t("v-tooltip",{attrs:{left:""},scopedSlots:e._u([{key:"activator",fn:function({on:r}){return[t("v-btn",e._g({staticClass:"delete-button",attrs:{color:e.crudColors.delete,disabled:!e.canDeleteResources([a]),icon:"",text:""},on:{click:function(t){return t.stopPropagation(),e.showDeleteConfirmation([a[e.resourceKeyName]])}}},r),[t("v-icon",{attrs:{size:e.crudIconSize}},[e._v(e._s(e.crudIcons.delete))])],1)]}}],null,!0)},[t("span",[e._v(e._s(e.lang("delete")))])]):e._e(),e._t("crudActionsAfter",null,{resource:a})],2)],2)]}},{key:"footer.page-text",fn:function({pageStart:t,pageStop:a,itemsLength:r}){return[e._v(" "+e._s(e.lang("from"))+" "+e._s(t)+" "+e._s(e.lang("till"))+" "+e._s(a)+" "+e._s(e.lang("of"))+" "+e._s(r)+" ")]}},e._l(e.$scopedSlots,(function(t,a){return{key:a,fn:function(t){return[e._t(a,null,null,t)]}}}))],null,!0),model:{value:e.selected,callback:function(t){e.selected=t},expression:"selected"}},"v-data-table",e.$attrs,!1),e.$listeners),[t("template",{slot:"no-data"},[e._v(" "+e._s(e.lang("no-data"))+" ")]),t("template",{slot:"loading"},[e._v(" "+e._s(e.lang("loading"))+" ")]),t("template",{slot:"no-results"},[e._v(" "+e._s(e.lang("no-results"))+" ")])],2)],1)],1),t("delete-confirmation",{ref:"deleteConfirmation",attrs:{callback:e.deleteHandler,texts:e.texts}})],1)},o=[],s=function(){var e=this,t=e._self._c;return e.value?t("div",{staticClass:"indicator-overlay-wrapper"},[t("div",{staticClass:"overlay"}),t("div",{staticClass:"indicator-wrapper"},[t("v-progress-circular",{attrs:{size:70,width:7,color:"white",indeterminate:""}})],1)]):e._e()},l=[],c=a("4875"),d={components:{VProgressCircular:c["VProgressCircular"]},name:"activity-overlay",props:{value:{default:!1,required:!0,type:Boolean}}},u=d;a("7526");function p(e,t,a,r,n,i,o,s){var l,c="function"===typeof e?e.options:e;if(t&&(c.render=t,c.staticRenderFns=a,c._compiled=!0),r&&(c.functional=!0),i&&(c._scopeId="data-v-"+i),o?(l=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"===typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),n&&n.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(o)},c._ssrRegister=l):n&&(l=s?function(){n.call(this,(c.functional?this.parent:this).$root.$options.shadowRoot)}:n),l)if(c.functional){c._injectStyles=l;var d=c.render;c.render=function(e,t){return l.call(t),d(e,t)}}else{var u=c.beforeCreate;c.beforeCreate=u?[].concat(u,l):[l]}return{exports:e,options:c}}var f=p(u,s,l,!1,null,"553eb051",null),h=f.exports,v=function(){var e=this,t=e._self._c;return t("div",{staticClass:"column type-text"},["undefined"!==typeof e.tableColumn.tooltip?t("v-tooltip",{attrs:{right:""},scopedSlots:e._u([{key:"activator",fn:function({on:a}){return[t("span",e._g({},a),[e._v(e._s(e.content))])]}}],null,!1,1535186038)},[t("span",{domProps:{innerHTML:e._s(e.item[e.tableColumn.tooltip])}})]):t("span",[e._v(e._s(e.content))])],1)},y=[],g={name:"TextType",props:["content","item","tableColumn"],components:{VTooltip:c["VTooltip"]},data(){return{}}},b=g,m=p(b,v,y,!1,null,null,null),_=m.exports,C=function(){var e=this,t=e._self._c;return t("div",{staticClass:"column type-checkbox"},[e.isTrue()?t("v-icon",[e._v("$vuetify.icons.checkboxOn")]):e._e()],1)},k=[],x={name:"CheckboxType",components:{VIcon:c["VIcon"]},props:["content"],methods:{isTrue(){return!(!this.content&&"true"!==this.content&&"1"!==this.content)}}},S=x,w=p(S,C,k,!1,null,null,null),D=w.exports,V=function(){var e=this,t=e._self._c;return t("v-dialog",{attrs:{persistent:"","max-width":"290"},model:{value:e.dialog,callback:function(t){e.dialog=t},expression:"dialog"}},[t("v-card",[t("v-card-title",{staticClass:"headline"},[e._v(e._s(e.lang("delete-confirmation-title")))]),t("v-card-text",[e._v(e._s(e.lang("delete-confirmation-content")))]),t("v-card-actions",[t("v-spacer"),t("v-btn",{attrs:{color:"grey",text:""},on:{click:function(t){e.dialog=!1}}},[e._v(e._s(e.lang("cancel")))]),t("v-btn",{staticClass:"confirm-delete-button",attrs:{color:"priamry darken-1",text:""},on:{click:e.handleDelete}},[e._v(" "+e._s(e.lang("delete"))+" ")])],1)],1)],1)},I=[],T={save:"Save",close:"Close",from:"from",till:"till",of:"of",create:"Create",update:"Update",delete:"Delete",cancel:"Cancel","no-data":"There is nothing found","no-results":"There is nothing found for this filter","snackbar-saved":"It's successfully saved!","snackbar-save-error":"Something went wrong, please try again later","snackbar-get-error":"Something went wrong, please try again later","snackbar-deleted":"It's successfully deleted!","snackbar-delete-error":"Something went wrong, please try again later",search:"Search",loading:"Loading..","delete-confirmation-title":"Are you sure?","delete-confirmation-content":"Are you sure you want to delete these item(s)?"},U={methods:{lang(e){return"undefined"===typeof this.texts||"undefined"===typeof this.texts[e]?T[e]:this.texts[e]}}},B={props:["callback","texts"],name:"delete-confirmation",components:{VCard:c["VCard"],VBtn:c["VBtn"],VSpacer:c["VSpacer"],VCardActions:c["VCardActions"],VCardTitle:c["VCardTitle"],VCardText:c["VCardText"],VDialog:c["VDialog"]},mixins:[U],data(){return{ids:[],dialog:!1}},methods:{handleDelete(){this.callback(this.ids),this.dialog=!1}}},R=B,$=p(R,V,I,!1,null,"6361e78c",null),K=$.exports;let q={style:{edit:{},drop:{},create:{}}};var O={use(e){e&&e.style&&(q.style.edit=e.style.edit||{},q.style.drop=e.style.delete||{},q.style.create=e.style.create||{},q.style.default=e.style.default||null)},name:"vuetify-resource",components:{DeleteConfirmation:K,ActivityOverlay:h,VDialog:c["VDialog"],VCard:c["VCard"],VToolbar:c["VToolbar"],VBtn:c["VBtn"],VIcon:c["VIcon"],VFlex:c["VFlex"],VTextField:c["VTextField"],VSnackbar:c["VSnackbar"],VLayout:c["VLayout"],VFabTransition:c["VFabTransition"],VSpeedDial:c["VSpeedDial"],VDataTable:c["VDataTable"],VSpacer:c["VSpacer"],VTooltip:c["VTooltip"],VCheckbox:c["VCheckbox"],VCardText:c["VCardText"],VToolbarItems:c["VToolbarItems"],VToolbarTitle:c["VToolbarTitle"]},mixins:[U],data(){return{fab:!1,search:"",totalItems:0,items:[],loading:!0,pagination:{itemsPerPage:this.rowsPerPage||10},selected:[],headers:[],dialog:{create:!1,update:!1},snackbar:{text:"",active:!1,color:"success"},activity:{isUpdating:!1,isDeleting:!1,isCreating:!1},lastOpenedHash:null}},computed:{resourceHtmlClass(){return{"vuetify-resource":!0,"with-search":this.canSearch,"row-click":this.hasClickableRows}},speedDialNotEmpty(){return!!this.showSpeedDial&&(!!(this.canAdd||this.canUpdate||this.canDelete)||"undefined"!==typeof this.$scopedSlots.speedDialAfter)},colors(){const{style:{edit:e,create:t,drop:a}}=q,r=q.style.default;return{edit:e.color||"green",delete:a.color||"red",create:t.color||"indigo",default:r&&null!=r.color?r.color:null,onlyCrudActions:r&&!r.onlySpeedDial,onlySpeedDial:r&&!r.onlyCrudActions}},crudColors(){return{edit:this.colors.onlyCrudActions&&this.colors.default?this.colors.default:this.colors.edit,delete:this.colors.onlyCrudActions&&this.colors.default?this.colors.default:this.colors.delete,create:this.colors.onlyCrudActions&&this.colors.default?this.colors.default:this.colors.create}},speedDialColors(){return{edit:this.colors.onlySpeedDial&&this.colors.default?this.colors.default:this.colors.edit,delete:this.colors.onlySpeedDial&&this.colors.default?this.colors.default:this.colors.delete,create:this.colors.onlySpeedDial&&this.colors.default?this.colors.default:this.colors.create}},crudIcons(){return{edit:q.style.edit.icon||"$vuetify.icons.edit",delete:q.style.drop.icon||"$vuetify.icons.delete",create:q.style.create.icon||"$vuetify.icons.add"}},crudIconSize:()=>q.style.default?q.style.default.size:null,hasClickableRows(){return"row-click"in this.$listeners}},props:{getDataCallback:{required:!0,type:Function},getItemCallback:{required:!1,type:Function},beforeCreateCallback:{required:!1,type:Function},createCallback:{required:!1,type:Function},beforeUpdateCallback:{required:!1,type:Function},updateCallback:{required:!1,type:Function},deleteCallback:{required:!1,type:Function},useResourceKeyInUrl:{required:!1,type:Boolean,default:!0},resourceKeyName:{required:!1,type:String,default:"id"},shouldGetItemByCallback:{required:!1,type:Boolean,default:!0},tableContent:{required:!0,type:Array},canUpdate:{required:!1,type:Boolean,default:!0},canUpdateResourceKey:{required:!1,type:String,default:""},canAdd:{required:!1,type:Boolean,default:!0},canDelete:{required:!1,type:Boolean,default:!0},canDeleteResourceKey:{required:!1,type:String,default:""},canSearch:{required:!1,type:Boolean,default:!1},useCheckboxes:{required:!1,type:Boolean,default:!0},showSpeedDial:{required:!1,type:Boolean,default:!0},speedDialDirection:{required:!1,type:String,default:"left"},searchQuery:{type:String},texts:{required:!1,type:Object},meta:{required:!1,type:Object,default:function(){return{name:"Resource",namePlural:"Resources"}}},rowsPerPageItems:{required:!1,type:Array,default:()=>[10,25,100]},rowsPerPage:{required:!1,type:Number,default:10},defaultSortBy:{required:!1,type:String},defaultSortDesc:{required:!1,type:Boolean}},watch:{pagination:{handler(){this.getDataHandler()},deep:!0},selected:{handler(){this.$emit("selected",this.selected)},deep:!0},$route:{handler(){this.handleUrlChange()},deep:!0},search:{handler(){clearTimeout(this.searchTimeout),this.searchTimeout=setTimeout(()=>{this.pagination.page=1,this.getDataHandler()},400)},deep:!0},searchQuery(){this.search=this.searchQuery}},created(){this.headers=JSON.parse(JSON.stringify(this.tableContent)),this.headers.push({text:"",value:"crud-actions",sortable:!1,class:"crud-actions"})},mounted(){this.defaultSortBy&&(this.pagination.sortBy=[this.defaultSortBy],this.pagination.sortDesc=this.defaultSortDesc?[this.defaultSortDesc]:[!1])},methods:{getDataHandler(){this.loading=!0,this.getDataCallback(this.pagination,this.search).then(e=>{this.clearSelected(),this.items=e.items,this.totalItems=e.total,this.loading=!1,this.handleUrlChange()}).catch(()=>{this.activity.isCreating=!1,this.showSnackbar(this.lang("snackbar-get-error"),"error")})},openCreateHandler(){this.beforeCreateCallback(this.selected),this.dialog.create=!0},createHandler(){this.activity.isCreating||(this.activity.isCreating=!0,this.createCallback().then(()=>{this.activity.isCreating=!1,this.dialog.create=!1,this.showSnackbar(this.lang("snackbar-saved")),this.getDataHandler()}).catch(()=>{this.activity.isCreating=!1,this.showSnackbar(this.lang("snackbar-save-error"),"error")}))},openUpdateHandler(e){"undefined"===typeof e&&(e=this.selected[0][this.resourceKeyName]),this.setIndentificationKey(e),this.getItemByIdentificationKey(e,e=>{if(!1===e)return this.showSnackbar(this.lang("snackbar-get-error"),"error"),!1;this.lastOpenedHash=this.getIndentificationKey(),this.selected=[e],this.onSelectedChange(),this.beforeUpdateCallback([JSON.parse(JSON.stringify(e))]),this.dialog.update=!0})},updateHandler(){this.activity.isUpdating||(this.activity.isUpdating=!0,this.updateCallback(this.selected).then(()=>{this.activity.isUpdating=!1,history.pushState("",document.title,window.location.pathname+window.location.search),this.dialog.update=!1,this.showSnackbar(this.lang("snackbar-saved")),this.getDataHandler()}).catch(()=>{this.activity.isUpdating=!1,this.showSnackbar(this.lang("snackbar-save-error"),"error")}))},showDeleteConfirmation(e){"undefined"===typeof e&&(e=this.selected.map(e=>e[this.resourceKeyName])),this.$refs.deleteConfirmation.ids=e,this.$refs.deleteConfirmation.dialog=!0},deleteHandler(e){this.activity.isDeleting||(this.activity.isDeleting=!0,this.deleteCallback(e).then(()=>{this.activity.isDeleting=!1,this.showSnackbar(this.lang("snackbar-deleted")),this.getDataHandler()}).catch(()=>{this.activity.isDeleting=!1,this.showSnackbar(this.lang("snackbar-delete-error"),"error")}))},showSnackbar(e,t="success"){this.snackbar.text=e,this.snackbar.active=!0,this.snackbar.color=t},clearSelected(){this.selected=[]},setIndentificationKey(e){this.useResourceKeyInUrl&&(window.location.hash="#"+e)},getIndentificationKey(){return window.location.hash.substring(1)},getItemByIdentificationKey(e,t){this.shouldGetItemByCallback?this.getItemFromCallbackByIdentificationKey(e,t):this.getItemFromItemsByIdentificationKey(e,t)},getItemFromCallbackByIdentificationKey(e,t){this.getItemCallback(e).then(e=>{t(e.item)}).catch(e=>{console.error(e)})},getItemFromItemsByIdentificationKey(e,t){let a=!1;this.items.forEach(t=>{t[this.resourceKeyName]!==e||(a=t)}),t(a)},handleUrlChange(){this.useResourceKeyInUrl&&""!==this.getIndentificationKey()&&this.getItemByIdentificationKey(this.getIndentificationKey(),e=>{if(!1===e)return this.showSnackbar("Het is niet gelukt om een item te vinden.","error"),!1;this.lastOpenedHash!==this.getIndentificationKey()&&(this.lastOpenedHash=this.getIndentificationKey(),this.selected=[e],this.onSelectedChange(),this.beforeUpdateCallback(this.selected),this.dialog.update=!0)})},getColumnType(e){if("object"===typeof e)return e;if("string"===typeof e)switch(e.toLowerCase()){case"checkbox":return D;default:case"text":return _}return _},onSelectedChange(){this.$emit("input",this.selected)},canDeleteResources(e){let t=this.canDelete;return""!==this.canDeleteResourceKey&&e.forEach(e=>{!1!==e[this.canDeleteResourceKey]||(t=!1)}),t},canUpdateResources(e){let t=this.canUpdate;return""!==this.canUpdateResourceKey&&e.forEach(e=>{!1!==e[this.canUpdateResourceKey]||(t=!1)}),t},cancelUpdate(){history.pushState("",document.title,window.location.pathname+window.location.search),this.dialog.update=!1},handleRowClick(e){this.$emit("row-click",e)},formatValue(e,t){return"undefined"!==typeof e.formatter?e.formatter(t):t},reload(){this.pagination.page=1,this.getDataHandler()}}},H=O,N=(a("30cb"),p(H,i,o,!1,null,null,null)),P=N.exports;t["default"]=P}})["default"]}));
//# sourceMappingURL=vuetify-resource.umd.min.js.map