adrema/resources/js/mixins/indexHelpers.js

61 lines
1.6 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-06-14 17:10:50 +02:00
return this.toFilterString(this.inner.meta.filter);
2023-03-15 00:08:20 +01:00
},
},
2023-02-25 17:19:17 +01:00
methods: {
2023-06-14 17:10:50 +02:00
toFilterString(data) {
return btoa(encodeURIComponent(JSON.stringify(data)));
},
2023-02-25 17:19:17 +01:00
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,
};
},
},
};