adrema/resources/js/mixins/indexHelpers.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-02-25 17:19:17 +01:00
export default {
data: function () {
return {
inner: {...this.data},
};
},
props: {
data: {},
},
2023-03-15 00:08:20 +01:00
computed: {
filterString() {
2023-03-22 23:37:36 +01:00
return btoa(encodeURIComponent(JSON.stringify(this.inner.meta.filter)));
2023-03-15 00:08:20 +01:00
},
},
2023-02-25 17:19:17 +01:00
methods: {
reload(resetPage = true) {
var _self = this;
var data = {
2023-03-15 00:08:20 +01:00
filter: this.filterString,
2023-02-25 17:19:17 +01:00
page: 1,
};
data['page'] = resetPage ? 1 : this.inner.meta.current_page;
this.$inertia.visit(window.location.pathname, {
data,
preserveState: true,
onSuccess(page) {
_self.inner = page.props.data;
},
});
},
can(permission) {
return this.inner.meta.can[permission];
},
getFilter(value) {
return this.inner.meta.filter[value];
},
setFilter(key, value) {
this.inner.meta.filter[key] = value;
this.reload();
},
requestCallback(successMessage, failureMessage) {
return {
onSuccess: () => {
this.$success(successMessage);
this.reload(false);
},
onFailure: () => {
this.$error(failureMessage);
this.reload(false);
},
preserveState: true,
};
},
},
};