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 |
| 16 | v-else-if="value === 'download'" |
| 17 | class="align-bottom btn-icon-only py-0 btn-link" |
| 18 | :download="exportName" |
| 19 | :href="downloadLocation" |
| 20 | :title="title" |
| 21 | > |
| 22 | <slot name="icon" /> |
| 23 | <span class="sr-only"> |
| 24 | {{ $t('global.action.download') }} |
| 25 | </span> |
| 26 | </b-link> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 27 | <b-button |
| 28 | v-else |
| 29 | variant="link" |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame^] | 30 | :class="{ 'btn-icon-only': btnIconOnly }" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 31 | :disabled="!enabled" |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame^] | 32 | :title="btnIconOnly ? title : !title" |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 33 | @click="$emit('click-table-action', value)" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 34 | > |
| 35 | <slot name="icon"> |
| 36 | {{ title }} |
| 37 | </slot> |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame^] | 38 | <span v-if="btnIconOnly" class="sr-only">{{ title }}</span> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 39 | </b-button> |
| 40 | </span> |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 41 | </template> |
| 42 | |
| 43 | <script> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 44 | import { omit } from 'lodash'; |
| 45 | |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 46 | export default { |
| 47 | name: 'TableRowAction', |
| 48 | props: { |
| 49 | value: { |
| 50 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 51 | required: true, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 52 | }, |
| 53 | enabled: { |
| 54 | type: Boolean, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 55 | default: true, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 56 | }, |
| 57 | title: { |
| 58 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 59 | default: null, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 60 | }, |
| 61 | rowData: { |
| 62 | type: Object, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 63 | default: () => {}, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 64 | }, |
| 65 | exportName: { |
| 66 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 67 | default: 'export', |
| 68 | }, |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 69 | downloadLocation: { |
| 70 | type: String, |
| 71 | default: '', |
| 72 | }, |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame^] | 73 | btnIconOnly: { |
| 74 | type: Boolean, |
| 75 | default: true, |
| 76 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 77 | }, |
| 78 | computed: { |
| 79 | dataForExport() { |
| 80 | return JSON.stringify(omit(this.rowData, 'actions')); |
| 81 | }, |
| 82 | download() { |
| 83 | return `${this.exportName}.json`; |
| 84 | }, |
| 85 | href() { |
| 86 | return `data:text/json;charset=utf-8,${this.dataForExport}`; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 87 | }, |
| 88 | }, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 89 | }; |
| 90 | </script> |