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