From bca39a475dfd3aab0b31709b2c4873398901b00c Mon Sep 17 00:00:00 2001
From: Andrew <saintruler@gmail.com>
Date: Fri, 19 Jul 2019 00:11:33 +0400
Subject: =?UTF-8?q?=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20=D1=83=D0=B4?=
 =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=80=D1=8F=D0=B4=D0=B0?=
 =?UTF-8?q?=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B4=D0=B5=D0=B9?=
 =?UTF-8?q?=D1=81=D1=82=D0=B2=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=20?=
 =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 day9/task5_vue/src/components/Table.vue | 71 +++++++++++++++++----------------
 1 file changed, 36 insertions(+), 35 deletions(-)

(limited to 'day9/task5_vue/src/components/Table.vue')

diff --git a/day9/task5_vue/src/components/Table.vue b/day9/task5_vue/src/components/Table.vue
index 519af25..d9296d9 100644
--- a/day9/task5_vue/src/components/Table.vue
+++ b/day9/task5_vue/src/components/Table.vue
@@ -1,12 +1,5 @@
 <template>
-    <div>
-        <EditFormBox
-                v-bind:form-type="formType"
-                v-bind:cancel-callback="hideEditForm"
-                v-bind:table-row="tableRow"
-                v-if="isFormShown"
-        />
-        <table id="vueTable">
+    <table>
             <thead>
                 <tr>
                     <th v-for="header in tableData.headers">
@@ -26,12 +19,11 @@
                         <button @click="showEditForm(`${row[0]}`)">&#9998</button>
                     </td>
                     <td>
-                        <button @click="showEditForm(`${row[0]}`)">&#10006</button>
+                        <button @click="removeField(`${row[0]}`)">&#10006</button>
                     </td>
                 </tr>
             </tbody>
         </table>
-    </div>
 </template>
 
 <script>
@@ -40,40 +32,36 @@
 
     export default {
         name: "Table",
-        props: ['tableData'],
+        props: ['tableData', 'showFormCallback'],
         components: {EditFormBox},
 
-        data() {
-            return {
-                formType: null,
-                isFormShown: false,
-                tableRow: null
-            }
-        },
-
         methods: {
             showEditForm(serviceId) {
-                this.requestRowById(serviceId)
+                axios
+                    .request({
+                        url: '/api/get/',
+                        method: 'post',
+                        headers: {'Content-Type': 'application/json'},
+                        data: JSON.stringify({'type': 'single_id', 'service_id': serviceId})
+                    })
                     .then(response => {
-                        this.tableRow = response.data;
-                        this.formType = 'update';
-                        this.isFormShown = true;
+                        this.showFormCallback('update', response.data);
                     });
             },
 
-            hideEditForm() {
-                this.formType = null;
-                this.isFormShown = false;
-            },
-
-            requestRowById(serviceId) {
-                return axios.request({
-                    url: '/api/get/',
-                    method: 'post',
-                    headers: {'Content-Type': 'application/json'},
-                    data: JSON.stringify({'type': 'single_id', 'service_id': serviceId})
-                })
+            removeField(serviceId) {
+                this.tableData.content = this.tableData.content.filter(row => row[0].toString() !== serviceId);
+                axios
+                    .request({
+                        url: '/api/delete', method: 'post',
+                        data: {'service_id': serviceId}
+                    })
+                    .then(response => {
+                        if (response.status === 200)
+                            this.tableData = this.tableData.content.filter(row => row[0] !== serviceId);
+                    });
             }
+
         }
     }
 </script>
@@ -103,4 +91,17 @@
     tbody > tr:nth-child(2n) {
         background-color: #f8f6ff;
     }
+
+    button {
+        border: none;
+        border-radius: 2px;
+    }
+
+    button:hover {
+        background-color: #dadada;
+    }
+
+    button:focus {
+        background-color: #d5d5d5;
+    }
 </style>
\ No newline at end of file
-- 
cgit v1.2.3

