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