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'; |
| 59 | |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 60 | export default { |
| 61 | name: 'TableRowAction', |
| 62 | props: { |
| 63 | value: { |
| 64 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 65 | required: true, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 66 | }, |
| 67 | enabled: { |
| 68 | type: Boolean, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 69 | default: true, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 70 | }, |
| 71 | title: { |
| 72 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 73 | default: null, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 74 | }, |
| 75 | rowData: { |
| 76 | type: Object, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 77 | default: () => {}, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 78 | }, |
| 79 | exportName: { |
| 80 | type: String, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 81 | default: 'export', |
| 82 | }, |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 83 | downloadLocation: { |
| 84 | type: String, |
| 85 | default: '', |
| 86 | }, |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 87 | btnIconOnly: { |
| 88 | type: Boolean, |
| 89 | default: true, |
| 90 | }, |
Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 91 | downloadInNewTab: { |
| 92 | type: Boolean, |
| 93 | default: false, |
| 94 | }, |
Sandeepa Singh | 450bdb0 | 2021-08-05 15:51:56 +0530 | [diff] [blame] | 95 | showButton: { |
| 96 | type: Boolean, |
| 97 | default: true, |
| 98 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 99 | }, |
| 100 | computed: { |
| 101 | dataForExport() { |
| 102 | return JSON.stringify(omit(this.rowData, 'actions')); |
| 103 | }, |
| 104 | download() { |
| 105 | return `${this.exportName}.json`; |
| 106 | }, |
| 107 | href() { |
| 108 | return `data:text/json;charset=utf-8,${this.dataForExport}`; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 109 | }, |
| 110 | }, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 111 | }; |
| 112 | </script> |