blob: 212971300824f654d14968499862f9efd361f722 [file] [log] [blame]
Yoshie Muranaka0e893f02020-02-18 13:39:45 -08001<template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -07002 <span>
3 <b-link
4 v-if="value === 'export'"
Dixsie Wolmers30f11f82020-11-10 16:07:56 -06005 class="align-bottom btn-icon-only py-0 btn-link"
Yoshie Muranakabe3af332020-05-11 08:23:04 -07006 :download="download"
7 :href="href"
8 :title="title"
Yoshie Muranakabe3af332020-05-11 08:23:04 -07009 >
10 <slot name="icon">
11 {{ $t('global.action.export') }}
12 </slot>
SurenNeware6e2cb972020-12-24 20:58:16 +053013 <span v-if="btnIconOnly" class="sr-only">{{ title }}</span>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070014 </b-link>
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080015 <b-link
Sandeepa Singh450bdb02021-08-05 15:51:56 +053016 v-else-if="
17 value === 'download' && downloadInNewTab && downloadLocation !== ''
18 "
Sandeepa Singh06d53862021-05-24 13:51:09 +053019 class="align-bottom btn-icon-only py-0 btn-link"
20 target="_blank"
21 :href="downloadLocation"
22 :title="title"
23 >
24 <slot name="icon" />
25 <span class="sr-only">
26 {{ $t('global.action.download') }}
27 </span>
28 </b-link>
29 <b-link
Sandeepa Singh450bdb02021-08-05 15:51:56 +053030 v-else-if="value === 'download' && downloadLocation !== ''"
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080031 class="align-bottom btn-icon-only py-0 btn-link"
32 :download="exportName"
33 :href="downloadLocation"
34 :title="title"
35 >
36 <slot name="icon" />
37 <span class="sr-only">
38 {{ $t('global.action.download') }}
39 </span>
40 </b-link>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070041 <b-button
Sandeepa Singh450bdb02021-08-05 15:51:56 +053042 v-else-if="showButton"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070043 variant="link"
SurenNeware6e2cb972020-12-24 20:58:16 +053044 :class="{ 'btn-icon-only': btnIconOnly }"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070045 :disabled="!enabled"
SurenNeware6e2cb972020-12-24 20:58:16 +053046 :title="btnIconOnly ? title : !title"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053047 @click="$emit('click-table-action', value)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070048 >
49 <slot name="icon">
50 {{ title }}
51 </slot>
SurenNeware6e2cb972020-12-24 20:58:16 +053052 <span v-if="btnIconOnly" class="sr-only">{{ title }}</span>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070053 </b-button>
54 </span>
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080055</template>
56
57<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070058import { omit } from 'lodash';
Ed Tanous883a0d52024-03-23 14:56:34 -070059import { useI18n } from 'vue-i18n';
Yoshie Muranakabe3af332020-05-11 08:23:04 -070060
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080061export default {
62 name: 'TableRowAction',
63 props: {
64 value: {
65 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050066 required: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080067 },
68 enabled: {
69 type: Boolean,
Derick Montague602e98a2020-10-21 16:20:00 -050070 default: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080071 },
72 title: {
73 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050074 default: null,
Yoshie Muranakabe3af332020-05-11 08:23:04 -070075 },
76 rowData: {
77 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -050078 default: () => {},
Yoshie Muranakabe3af332020-05-11 08:23:04 -070079 },
80 exportName: {
81 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050082 default: 'export',
83 },
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080084 downloadLocation: {
85 type: String,
86 default: '',
87 },
SurenNeware6e2cb972020-12-24 20:58:16 +053088 btnIconOnly: {
89 type: Boolean,
90 default: true,
91 },
Sandeepa Singh06d53862021-05-24 13:51:09 +053092 downloadInNewTab: {
93 type: Boolean,
94 default: false,
95 },
Sandeepa Singh450bdb02021-08-05 15:51:56 +053096 showButton: {
97 type: Boolean,
98 default: true,
99 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700100 },
Ed Tanous883a0d52024-03-23 14:56:34 -0700101 data() {
102 return {
103 $t: useI18n().t,
104 };
105 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700106 computed: {
107 dataForExport() {
108 return JSON.stringify(omit(this.rowData, 'actions'));
109 },
110 download() {
111 return `${this.exportName}.json`;
112 },
113 href() {
114 return `data:text/json;charset=utf-8,${this.dataForExport}`;
Derick Montague602e98a2020-10-21 16:20:00 -0500115 },
116 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800117};
118</script>