| Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 1 | <template> |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 2 | <span> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 3 | <b-button |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 4 | v-if="value === 'export'" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 5 | variant="link" |
| 6 | class="align-bottom btn-icon-only py-0" |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 7 | :download="download" |
| 8 | :href="href" |
| 9 | :title="title" |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 10 | > |
| 11 | <slot name="icon"> |
| 12 | {{ $t('global.action.export') }} |
| 13 | </slot> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 14 | <span v-if="btnIconOnly" class="visually-hidden">{{ title }}</span> |
| 15 | </b-button> |
| 16 | <b-button |
| Sandeepa Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 17 | v-else-if=" |
| 18 | value === 'download' && downloadInNewTab && downloadLocation !== '' |
| 19 | " |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 20 | variant="link" |
| 21 | class="align-bottom btn-icon-only py-0" |
| Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 22 | target="_blank" |
| 23 | :href="downloadLocation" |
| 24 | :title="title" |
| 25 | > |
| 26 | <slot name="icon" /> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 27 | <span class="visually-hidden"> |
| Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 28 | {{ $t('global.action.download') }} |
| 29 | </span> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 30 | </b-button> |
| 31 | <b-button |
| Sandeepa Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 32 | v-else-if="value === 'download' && downloadLocation !== ''" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 33 | variant="link" |
| 34 | class="align-bottom btn-icon-only py-0" |
| Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 35 | :download="exportName" |
| 36 | :href="downloadLocation" |
| 37 | :title="title" |
| 38 | > |
| 39 | <slot name="icon" /> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 40 | <span class="visually-hidden"> |
| Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 41 | {{ $t('global.action.download') }} |
| 42 | </span> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 43 | </b-button> |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 44 | <b-button |
| Sandeepa Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 45 | v-else-if="showButton" |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 46 | variant="link" |
| SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 47 | :class="{ 'btn-icon-only': btnIconOnly }" |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 48 | :disabled="!enabled" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 49 | :title="title" |
| Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 50 | @click="$emit('click-table-action', value)" |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 51 | > |
| 52 | <slot name="icon"> |
| 53 | {{ title }} |
| 54 | </slot> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 55 | <span v-if="btnIconOnly" class="visually-hidden">{{ title }}</span> |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 56 | </b-button> |
| 57 | </span> |
| Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 58 | </template> |
| 59 | |
| 60 | <script> |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 61 | import { omit } from 'lodash'; |
| Ed Tanous | 883a0d5 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 62 | import { useI18n } from 'vue-i18n'; |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 63 | |
| Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 64 | export default { |
| 65 | name: 'TableRowAction', |
| 66 | props: { |
| 67 | value: { |
| 68 | type: String, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 69 | required: true, |
| Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 70 | }, |
| 71 | enabled: { |
| 72 | type: Boolean, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 73 | default: true, |
| Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 74 | }, |
| 75 | title: { |
| 76 | type: String, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 77 | default: null, |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 78 | }, |
| 79 | rowData: { |
| 80 | type: Object, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 81 | default: () => {}, |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 82 | }, |
| 83 | exportName: { |
| 84 | type: String, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 85 | default: 'export', |
| 86 | }, |
| Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 87 | downloadLocation: { |
| 88 | type: String, |
| 89 | default: '', |
| 90 | }, |
| SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 91 | btnIconOnly: { |
| 92 | type: Boolean, |
| 93 | default: true, |
| 94 | }, |
| Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 95 | downloadInNewTab: { |
| 96 | type: Boolean, |
| 97 | default: false, |
| 98 | }, |
| Sandeepa Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 99 | showButton: { |
| 100 | type: Boolean, |
| 101 | default: true, |
| 102 | }, |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 103 | }, |
| Hariharan Rangasamy | c5d60f5 | 2025-10-31 12:58:56 +0530 | [diff] [blame] | 104 | emits: ['click-table-action'], |
| Ed Tanous | 883a0d5 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 105 | data() { |
| 106 | return { |
| 107 | $t: useI18n().t, |
| 108 | }; |
| 109 | }, |
| Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 110 | computed: { |
| 111 | dataForExport() { |
| 112 | return JSON.stringify(omit(this.rowData, 'actions')); |
| 113 | }, |
| 114 | download() { |
| 115 | return `${this.exportName}.json`; |
| 116 | }, |
| 117 | href() { |
| 118 | return `data:text/json;charset=utf-8,${this.dataForExport}`; |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 119 | }, |
| 120 | }, |
| Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 121 | }; |
| 122 | </script> |