SurenNeware | c2862dc | 2020-09-11 18:02:42 +0530 | [diff] [blame] | 1 | import StatusIcon from '../Global/StatusIcon'; |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 2 | import i18n from '@/i18n'; |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 3 | |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 4 | const BVToastMixin = { |
SurenNeware | c2862dc | 2020-09-11 18:02:42 +0530 | [diff] [blame] | 5 | components: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 6 | StatusIcon, |
SurenNeware | c2862dc | 2020-09-11 18:02:42 +0530 | [diff] [blame] | 7 | }, |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 8 | methods: { |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 9 | $_BVToastMixin_createTitle(title, status) { |
| 10 | const statusIcon = this.$createElement('StatusIcon', { |
| 11 | props: { status }, |
| 12 | }); |
SurenNeware | c2862dc | 2020-09-11 18:02:42 +0530 | [diff] [blame] | 13 | const titleWithIcon = this.$createElement( |
| 14 | 'strong', |
| 15 | { class: 'toast-icon' }, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 16 | [statusIcon, title], |
SurenNeware | c2862dc | 2020-09-11 18:02:42 +0530 | [diff] [blame] | 17 | ); |
| 18 | return titleWithIcon; |
| 19 | }, |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 20 | $_BVToastMixin_createBody(messageBody) { |
| 21 | if (Array.isArray(messageBody)) { |
| 22 | return messageBody.map((message) => |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 23 | this.$createElement('p', { class: 'mb-0' }, message), |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 24 | ); |
| 25 | } else { |
| 26 | return [this.$createElement('p', { class: 'mb-0' }, messageBody)]; |
| 27 | } |
| 28 | }, |
| 29 | $_BVToastMixin_createTimestamp() { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 30 | const timestamp = this.$filters.formatTime(new Date()); |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 31 | return this.$createElement('p', { class: 'mt-3 mb-0' }, timestamp); |
| 32 | }, |
| 33 | $_BVToastMixin_createRefreshAction() { |
| 34 | return this.$createElement( |
| 35 | 'BLink', |
| 36 | { |
| 37 | class: 'd-inline-block mt-3', |
| 38 | on: { |
| 39 | click: () => { |
| 40 | this.$root.$emit('refresh-application'); |
| 41 | }, |
| 42 | }, |
| 43 | }, |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 44 | i18n.global.t('global.action.refresh'), |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 45 | ); |
| 46 | }, |
| 47 | $_BVToastMixin_initToast(body, title, variant) { |
| 48 | this.$root.$bvToast.toast(body, { |
| 49 | title, |
| 50 | variant, |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 51 | autoHideDelay: 10000, //auto hide in milliseconds |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 52 | noAutoHide: variant !== 'success', |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 53 | isStatus: true, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 54 | solid: true, |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 55 | }); |
| 56 | }, |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 57 | successToast( |
| 58 | message, |
| 59 | { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 60 | title: t = i18n.global.t('global.status.success'), |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 61 | timestamp, |
| 62 | refreshAction, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 63 | } = {}, |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 64 | ) { |
| 65 | const body = this.$_BVToastMixin_createBody(message); |
| 66 | const title = this.$_BVToastMixin_createTitle(t, 'success'); |
| 67 | if (refreshAction) body.push(this.$_BVToastMixin_createRefreshAction()); |
| 68 | if (timestamp) body.push(this.$_BVToastMixin_createTimestamp()); |
| 69 | this.$_BVToastMixin_initToast(body, title, 'success'); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 70 | }, |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 71 | errorToast( |
| 72 | message, |
| 73 | { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 74 | title: t = i18n.global.t('global.status.error'), |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 75 | timestamp, |
| 76 | refreshAction, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 77 | } = {}, |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 78 | ) { |
| 79 | const body = this.$_BVToastMixin_createBody(message); |
| 80 | const title = this.$_BVToastMixin_createTitle(t, 'danger'); |
| 81 | if (refreshAction) body.push(this.$_BVToastMixin_createRefreshAction()); |
| 82 | if (timestamp) body.push(this.$_BVToastMixin_createTimestamp()); |
| 83 | this.$_BVToastMixin_initToast(body, title, 'danger'); |
Derick Montague | 4e90eed | 2020-03-03 18:11:44 -0600 | [diff] [blame] | 84 | }, |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 85 | warningToast( |
| 86 | message, |
| 87 | { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 88 | title: t = i18n.global.t('global.status.warning'), |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 89 | timestamp, |
| 90 | refreshAction, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 91 | } = {}, |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 92 | ) { |
| 93 | const body = this.$_BVToastMixin_createBody(message); |
| 94 | const title = this.$_BVToastMixin_createTitle(t, 'warning'); |
| 95 | if (refreshAction) body.push(this.$_BVToastMixin_createRefreshAction()); |
| 96 | if (timestamp) body.push(this.$_BVToastMixin_createTimestamp()); |
| 97 | this.$_BVToastMixin_initToast(body, title, 'warning'); |
| 98 | }, |
| 99 | infoToast( |
| 100 | message, |
| 101 | { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 102 | title: t = i18n.global.t('global.status.informational'), |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 103 | timestamp, |
| 104 | refreshAction, |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 105 | } = {}, |
Yoshie Muranaka | f92e296 | 2021-02-09 12:41:53 -0800 | [diff] [blame] | 106 | ) { |
| 107 | const body = this.$_BVToastMixin_createBody(message); |
| 108 | const title = this.$_BVToastMixin_createTitle(t, 'info'); |
| 109 | if (refreshAction) body.push(this.$_BVToastMixin_createRefreshAction()); |
| 110 | if (timestamp) body.push(this.$_BVToastMixin_createTimestamp()); |
| 111 | this.$_BVToastMixin_initToast(body, title, 'info'); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 112 | }, |
| 113 | }, |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | export default BVToastMixin; |