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> |
| 3 | <b-link |
| 4 | v-if="value === 'export'" |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 5 | class="align-bottom btn-icon-only py-0 btn-link" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 6 | :download="download" |
| 7 | :href="href" |
| 8 | :title="title" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 9 | > |
| 10 | <slot name="icon"> |
| 11 | {{ $t('global.action.export') }} |
| 12 | </slot> |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 13 | <span v-if="btnIconOnly" class="sr-only">{{ title }}</span> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 14 | </b-link> |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 15 | <b-link |
Sandeepa Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 16 | v-else-if=" |
| 17 | value === 'download' && downloadInNewTab && downloadLocation !== '' |
| 18 | " |
Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 19 | 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 Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 30 | v-else-if="value === 'download' && downloadLocation !== ''" |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 31 | 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 Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 41 | <b-button |
Sandeepa Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 42 | v-else-if="showButton" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 43 | variant="link" |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 44 | :class="{ 'btn-icon-only': btnIconOnly }" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 45 | :disabled="!enabled" |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 46 | :title="btnIconOnly ? title : !title" |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 47 | @click="$emit('click-table-action', value)" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 48 | > |
| 49 | <slot name="icon"> |
| 50 | {{ title }} |
| 51 | </slot> |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 52 | <span v-if="btnIconOnly" class="sr-only">{{ title }}</span> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 53 | </b-button> |
| 54 | </span> |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 55 | </template> |
| 56 | |
| 57 | <script> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 58 | import { omit } from 'lodash'; |
Ed Tanous | 883a0d5 | 2024-03-23 14:56:34 -0700 | [diff] [blame^] | 59 | import { useI18n } from 'vue-i18n'; |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 60 | |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 61 | export default { |
| 62 | name: 'TableRowAction', |
| 63 | props: { |
| 64 | value: { |
| 65 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 66 | required: true, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 67 | }, |
| 68 | enabled: { |
| 69 | type: Boolean, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 70 | default: true, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 71 | }, |
| 72 | title: { |
| 73 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 74 | default: null, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 75 | }, |
| 76 | rowData: { |
| 77 | type: Object, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 78 | default: () => {}, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 79 | }, |
| 80 | exportName: { |
| 81 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 82 | default: 'export', |
| 83 | }, |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 84 | downloadLocation: { |
| 85 | type: String, |
| 86 | default: '', |
| 87 | }, |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 88 | btnIconOnly: { |
| 89 | type: Boolean, |
| 90 | default: true, |
| 91 | }, |
Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 92 | downloadInNewTab: { |
| 93 | type: Boolean, |
| 94 | default: false, |
| 95 | }, |
Sandeepa Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 96 | showButton: { |
| 97 | type: Boolean, |
| 98 | default: true, |
| 99 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 100 | }, |
Ed Tanous | 883a0d5 | 2024-03-23 14:56:34 -0700 | [diff] [blame^] | 101 | data() { |
| 102 | return { |
| 103 | $t: useI18n().t, |
| 104 | }; |
| 105 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 106 | 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 115 | }, |
| 116 | }, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 117 | }; |
| 118 | </script> |