From 004f2314592f347bcac17668d9062acfe9e02241 Mon Sep 17 00:00:00 2001
From: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Date: Fri, 24 Feb 2023 17:01:15 +0000
Subject: [PATCH] Bug 32991: Add delete dialog to licenses list

---
 .../js/vue/components/ERM/LicensesList.vue    | 36 +++++++++++++++++--
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue
index 84eb25bf44..90057ae7e6 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesList.vue
@@ -26,6 +26,8 @@ export default {
         const AVStore = inject("AVStore")
         const { get_lib_from_av, map_av_dt_filter } = AVStore
 
+        const { setConfirmationDialog, setMessage } = inject("mainStore")
+
         const table_id = "license_list"
         useDataTable(table_id)
 
@@ -34,6 +36,8 @@ export default {
             get_lib_from_av,
             map_av_dt_filter,
             table_id,
+            setConfirmationDialog,
+            setMessage,
         }
     },
     data: function () {
@@ -64,8 +68,30 @@ export default {
         edit_license: function (license_id) {
             this.$router.push("/cgi-bin/koha/erm/licenses/edit/" + license_id)
         },
-        delete_license: function (license_id) {
-            this.$router.push("/cgi-bin/koha/erm/licenses/delete/" + license_id)
+        delete_license: function (license_id, license_name) {
+            this.setConfirmationDialog(
+                {
+                    title: this.$__(
+                        "Are you sure you want to remove this license?"
+                    ),
+                    message: license_name,
+                    accept_label: this.$__("Yes, delete"),
+                    cancel_label: this.$__("No, do not delete"),
+                },
+                () => {
+                    const client = APIClient.erm
+                    client.licenses.delete(license_id).then(
+                        success => {
+                            this.setMessage(this.$__("License deleted"))
+                            $("#" + this.table_id)
+                                .DataTable()
+                                .ajax.url("/api/v1/erm/licenses")
+                                .draw()
+                        },
+                        error => {}
+                    )
+                }
+            )
         },
         build_datatable: function () {
             let show_license = this.show_license
@@ -203,6 +229,7 @@ export default {
                             function (index, e) {
                                 let tr = $(this).parent().parent()
                                 let license_id = api.row(tr).data().license_id
+                                let license_name = api.row(tr).data().name
                                 let editButton = createVNode(
                                     "a",
                                     {
@@ -227,7 +254,10 @@ export default {
                                         class: "btn btn-default btn-xs",
                                         role: "button",
                                         onClick: () => {
-                                            delete_license(license_id)
+                                            delete_license(
+                                                license_id,
+                                                license_name
+                                            )
                                         },
                                     },
                                     [
-- 
2.30.2