blob: c8b58da1e56b1e0d498d70e0198780f8079f67b9 [file] [log] [blame]
SurenNewarec2862dc2020-09-11 18:02:42 +05301import StatusIcon from '../Global/StatusIcon';
Surya V603cfbf2024-07-11 15:19:46 +05302import i18n from '@/i18n';
Yoshie Muranakaf92e2962021-02-09 12:41:53 -08003
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -08004const BVToastMixin = {
SurenNewarec2862dc2020-09-11 18:02:42 +05305 components: {
Derick Montague602e98a2020-10-21 16:20:00 -05006 StatusIcon,
SurenNewarec2862dc2020-09-11 18:02:42 +05307 },
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -08008 methods: {
Yoshie Muranakaf92e2962021-02-09 12:41:53 -08009 $_BVToastMixin_createTitle(title, status) {
10 const statusIcon = this.$createElement('StatusIcon', {
11 props: { status },
12 });
SurenNewarec2862dc2020-09-11 18:02:42 +053013 const titleWithIcon = this.$createElement(
14 'strong',
15 { class: 'toast-icon' },
Ed Tanous81323992024-02-27 11:26:24 -080016 [statusIcon, title],
SurenNewarec2862dc2020-09-11 18:02:42 +053017 );
18 return titleWithIcon;
19 },
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080020 $_BVToastMixin_createBody(messageBody) {
21 if (Array.isArray(messageBody)) {
22 return messageBody.map((message) =>
Ed Tanous81323992024-02-27 11:26:24 -080023 this.$createElement('p', { class: 'mb-0' }, message),
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080024 );
25 } else {
26 return [this.$createElement('p', { class: 'mb-0' }, messageBody)];
27 }
28 },
29 $_BVToastMixin_createTimestamp() {
Surya V603cfbf2024-07-11 15:19:46 +053030 const timestamp = this.$filters.formatTime(new Date());
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080031 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 V603cfbf2024-07-11 15:19:46 +053044 i18n.global.t('global.action.refresh'),
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080045 );
46 },
47 $_BVToastMixin_initToast(body, title, variant) {
48 this.$root.$bvToast.toast(body, {
49 title,
50 variant,
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -080051 autoHideDelay: 10000, //auto hide in milliseconds
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080052 noAutoHide: variant !== 'success',
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -080053 isStatus: true,
Derick Montague602e98a2020-10-21 16:20:00 -050054 solid: true,
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -080055 });
56 },
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080057 successToast(
58 message,
59 {
Surya V603cfbf2024-07-11 15:19:46 +053060 title: t = i18n.global.t('global.status.success'),
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080061 timestamp,
62 refreshAction,
Ed Tanous81323992024-02-27 11:26:24 -080063 } = {},
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080064 ) {
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 Muranaka183c2752020-02-12 11:30:49 -080070 },
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080071 errorToast(
72 message,
73 {
Surya V603cfbf2024-07-11 15:19:46 +053074 title: t = i18n.global.t('global.status.error'),
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080075 timestamp,
76 refreshAction,
Ed Tanous81323992024-02-27 11:26:24 -080077 } = {},
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080078 ) {
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 Montague4e90eed2020-03-03 18:11:44 -060084 },
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080085 warningToast(
86 message,
87 {
Surya V603cfbf2024-07-11 15:19:46 +053088 title: t = i18n.global.t('global.status.warning'),
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080089 timestamp,
90 refreshAction,
Ed Tanous81323992024-02-27 11:26:24 -080091 } = {},
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080092 ) {
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 V603cfbf2024-07-11 15:19:46 +0530102 title: t = i18n.global.t('global.status.informational'),
Yoshie Muranakaf92e2962021-02-09 12:41:53 -0800103 timestamp,
104 refreshAction,
Ed Tanous81323992024-02-27 11:26:24 -0800105 } = {},
Yoshie Muranakaf92e2962021-02-09 12:41:53 -0800106 ) {
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 Montague602e98a2020-10-21 16:20:00 -0500112 },
113 },
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800114};
115
116export default BVToastMixin;