opnform/resources/js/base.js

84 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-09-20 19:59:52 +00:00
/**
* Base mixin for all Vue components
*/
import debounce from 'debounce'
export default {
2022-12-22 10:54:01 +00:00
computed: {
$crisp () {
return window.$crisp
}
},
2022-09-20 19:59:52 +00:00
methods: {
/**
* Creates a debounced function that delays invoking a callback.
*/
debouncer: debounce((callback) => callback(), 500),
/**
* Show an error message.
*/
2022-12-22 10:54:01 +00:00
alertError (message, autoClose = 10000) {
this.$notify(
{
title: 'Error',
text: message,
2022-12-22 10:54:01 +00:00
type: 'error'
}, autoClose)
2022-09-20 19:59:52 +00:00
},
/**
* Show a success message.
*/
2022-12-22 10:54:01 +00:00
alertSuccess (message, autoClose = 10000) {
this.$notify(
{
title: 'Success',
text: message,
2022-12-22 10:54:01 +00:00
type: 'success'
}, autoClose)
2022-09-20 19:59:52 +00:00
},
/**
* Show a warning message.
*/
2022-12-22 10:54:01 +00:00
alertWarning (message, autoClose = 10000) {
this.$notify(
{
title: 'Warning',
text: message,
2022-12-22 10:54:01 +00:00
type: 'warning'
}, autoClose)
2022-09-20 19:59:52 +00:00
},
/**
* Show confirmation message.
*/
2022-12-22 10:54:01 +00:00
alertConfirm (message, success, failure = ()=>{}, autoClose = 10000) {
this.$notify(
{
title: 'Confirm',
text: message,
type: 'confirm',
2022-12-22 10:54:01 +00:00
success,
failure
}, autoClose)
2022-09-20 19:59:52 +00:00
},
/**
* Show confirmation message.
*/
closeAlert () {
this.$root.alert = {
type: null,
autoClose: 0,
message: '',
confirmationProceed: null,
confirmationCancel: null
}
}
}
}