blob: 4ee757fa46346e8dff05b79a19c347b8b8bb1910 [file] [log] [blame]
SurenNewarec2862dc2020-09-11 18:02:42 +05301import StatusIcon from '../Global/StatusIcon';
Yoshie Muranakaf92e2962021-02-09 12:41:53 -08002
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -08003const BVToastMixin = {
SurenNewarec2862dc2020-09-11 18:02:42 +05304 components: {
Derick Montague602e98a2020-10-21 16:20:00 -05005 StatusIcon,
SurenNewarec2862dc2020-09-11 18:02:42 +05306 },
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -08007 methods: {
Yoshie Muranakaf92e2962021-02-09 12:41:53 -08008 $_BVToastMixin_createTitle(title, status) {
9 const statusIcon = this.$createElement('StatusIcon', {
10 props: { status },
11 });
SurenNewarec2862dc2020-09-11 18:02:42 +053012 const titleWithIcon = this.$createElement(
13 'strong',
14 { class: 'toast-icon' },
Ed Tanous81323992024-02-27 11:26:24 -080015 [statusIcon, title],
SurenNewarec2862dc2020-09-11 18:02:42 +053016 );
17 return titleWithIcon;
18 },
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080019 $_BVToastMixin_createBody(messageBody) {
20 if (Array.isArray(messageBody)) {
21 return messageBody.map((message) =>
Ed Tanous81323992024-02-27 11:26:24 -080022 this.$createElement('p', { class: 'mb-0' }, message),
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080023 );
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 Tanous81323992024-02-27 11:26:24 -080043 this.$t('global.action.refresh'),
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080044 );
45 },
46 $_BVToastMixin_initToast(body, title, variant) {
47 this.$root.$bvToast.toast(body, {
48 title,
49 variant,
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -080050 autoHideDelay: 10000, //auto hide in milliseconds
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080051 noAutoHide: variant !== 'success',
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -080052 isStatus: true,
Derick Montague602e98a2020-10-21 16:20:00 -050053 solid: true,
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -080054 });
55 },
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080056 successToast(
57 message,
58 {
59 title: t = this.$t('global.status.success'),
60 timestamp,
61 refreshAction,
Ed Tanous81323992024-02-27 11:26:24 -080062 } = {},
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080063 ) {
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 Muranaka183c2752020-02-12 11:30:49 -080069 },
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080070 errorToast(
71 message,
72 {
73 title: t = this.$t('global.status.error'),
74 timestamp,
75 refreshAction,
Ed Tanous81323992024-02-27 11:26:24 -080076 } = {},
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080077 ) {
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 Montague4e90eed2020-03-03 18:11:44 -060083 },
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080084 warningToast(
85 message,
86 {
87 title: t = this.$t('global.status.warning'),
88 timestamp,
89 refreshAction,
Ed Tanous81323992024-02-27 11:26:24 -080090 } = {},
Yoshie Muranakaf92e2962021-02-09 12:41:53 -080091 ) {
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 Tanous81323992024-02-27 11:26:24 -0800104 } = {},
Yoshie Muranakaf92e2962021-02-09 12:41:53 -0800105 ) {
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 Montague602e98a2020-10-21 16:20:00 -0500111 },
112 },
Yoshie Muranaka0fc91e72020-02-05 11:23:06 -0800113};
114
115export default BVToastMixin;