From 3f4094d08b873e17464a51c817ea7d41177f848d Mon Sep 17 00:00:00 2001
From: "Andrey V.Kosteltsev" <AKosteltsev@IBS.RU>
Date: Mon, 4 Jul 2022 23:11:28 +0300
Subject: IBS: _ibs UI Theme

---
 src/components/_ibs/Global/TableRowAction.vue | 112 ++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
 create mode 100644 src/components/_ibs/Global/TableRowAction.vue

(limited to 'src/components/_ibs/Global/TableRowAction.vue')

diff --git a/src/components/_ibs/Global/TableRowAction.vue b/src/components/_ibs/Global/TableRowAction.vue
new file mode 100644
index 00000000..549f1b52
--- /dev/null
+++ b/src/components/_ibs/Global/TableRowAction.vue
@@ -0,0 +1,112 @@
+<template>
+  <span>
+    <b-link
+      v-if="value === 'export'"
+      class="align-bottom btn-icon-only py-0 btn-link"
+      :download="download"
+      :href="href"
+      :title="title"
+    >
+      <slot name="icon">
+        {{ $t('global.action.export') }}
+      </slot>
+      <span v-if="btnIconOnly" class="sr-only">{{ title }}</span>
+    </b-link>
+    <b-link
+      v-else-if="
+        value === 'download' && downloadInNewTab && downloadLocation !== ''
+      "
+      class="align-bottom btn-icon-only py-0 btn-link"
+      target="_blank"
+      :href="downloadLocation"
+      :title="title"
+    >
+      <slot name="icon" />
+      <span class="sr-only">
+        {{ $t('global.action.download') }}
+      </span>
+    </b-link>
+    <b-link
+      v-else-if="value === 'download' && downloadLocation !== ''"
+      class="align-bottom btn-icon-only py-0 btn-link"
+      :download="exportName"
+      :href="downloadLocation"
+      :title="title"
+    >
+      <slot name="icon" />
+      <span class="sr-only">
+        {{ $t('global.action.download') }}
+      </span>
+    </b-link>
+    <b-button
+      v-else-if="showButton"
+      variant="link"
+      :class="{ 'btn-icon-only': btnIconOnly }"
+      :disabled="!enabled"
+      :title="btnIconOnly ? title : !title"
+      @click="$emit('click-table-action', value)"
+    >
+      <slot name="icon">
+        {{ title }}
+      </slot>
+      <span v-if="btnIconOnly" class="sr-only">{{ title }}</span>
+    </b-button>
+  </span>
+</template>
+
+<script>
+import { omit } from 'lodash';
+
+export default {
+  name: 'TableRowAction',
+  props: {
+    value: {
+      type: String,
+      required: true,
+    },
+    enabled: {
+      type: Boolean,
+      default: true,
+    },
+    title: {
+      type: String,
+      default: null,
+    },
+    rowData: {
+      type: Object,
+      default: () => {},
+    },
+    exportName: {
+      type: String,
+      default: 'export',
+    },
+    downloadLocation: {
+      type: String,
+      default: '',
+    },
+    btnIconOnly: {
+      type: Boolean,
+      default: true,
+    },
+    downloadInNewTab: {
+      type: Boolean,
+      default: false,
+    },
+    showButton: {
+      type: Boolean,
+      default: true,
+    },
+  },
+  computed: {
+    dataForExport() {
+      return JSON.stringify(omit(this.rowData, 'actions'));
+    },
+    download() {
+      return `${this.exportName}.json`;
+    },
+    href() {
+      return `data:text/json;charset=utf-8,${this.dataForExport}`;
+    },
+  },
+};
+</script>
-- 
cgit v1.2.3

