From 6b796a25ed380a66c51c4ca6a5db7e6c88e12004 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 17 Oct 2024 16:15:43 +0000 Subject: [PATCH] Bug 37301: Apply changes to preservation trains Also update edit route from TrainsFormEdit to TrainsFormAddEdit for consistency --- .../components/Preservation/TrainResource.vue | 29 ++++++++ .../components/Preservation/TrainsList.vue | 66 +++++-------------- .../components/Preservation/TrainsShow.vue | 50 +++----------- .../prog/js/vue/routes/preservation.js | 2 +- 4 files changed, 54 insertions(+), 93 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.vue diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.vue new file mode 100644 index 0000000000..6dfbe4cf62 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainResource.vue @@ -0,0 +1,29 @@ + diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsList.vue index 29f5b52e56..efe2660677 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsList.vue @@ -3,8 +3,8 @@
@@ -45,9 +45,9 @@
@@ -66,21 +66,20 @@ import { inject, ref, reactive } from "vue" import { APIClient } from "../../fetch/api-client" import { build_url } from "../../composables/datatables" import KohaTable from "../KohaTable.vue" +import TrainResource from "./TrainResource.vue" export default { + extends: TrainResource, setup() { const AVStore = inject("AVStore") const { get_lib_from_av, map_av_dt_filter } = AVStore - const { setConfirmationDialog, setMessage, setWarning } = - inject("mainStore") const table = ref() const filters = reactive({ status: "" }) return { + ...TrainResource.setup(), get_lib_from_av, map_av_dt_filter, - setConfirmationDialog, - setMessage, - setWarning, + escape_str, table, filters, } @@ -136,44 +135,6 @@ export default { error => {} ) }, - doShow: function (train, dt, event) { - event.preventDefault() - this.$router.push({ - name: "TrainsShow", - params: { train_id: train.train_id }, - }) - }, - doEdit: function (train, dt, event) { - this.$router.push({ - name: "TrainsFormEdit", - params: { train_id: train.train_id }, - }) - }, - doDelete: function (train, dt, event) { - this.setConfirmationDialog( - { - title: this.$__( - "Are you sure you want to remove this train?" - ), - message: train.name, - accept_label: this.$__("Yes, delete"), - cancel_label: this.$__("No, do not delete"), - }, - () => { - const client = APIClient.preservation - client.trains.delete(train.train_id).then( - success => { - this.setMessage( - this.$__("Train %s deleted").format(train.name), - true - ) - dt.draw() - }, - error => {} - ) - } - ) - }, doAddItems: function (train, dt, event) { if (train.closed_on != null) { this.setWarning(this.$__("Cannot add items to a closed train")) @@ -185,7 +146,7 @@ export default { } }, table_url() { - let url = "/api/v1/preservation/trains" + let url = this.getResourceTableUrl() let q if (this.filters.status == "closed") { q = { @@ -231,7 +192,10 @@ export default { searchable: true, orderable: true, render: function (data, type, row, meta) { - return `${row.name} (#${row.train_id})` + return ( + '' + + escape_str(`${row.name} (#${row.train_id})`) + ) }, }, { @@ -274,7 +238,7 @@ export default { }, }, components: { flatPickr, Toolbar, ToolbarButton, KohaTable }, - name: "trainsList", + name: "TrainsList", emits: ["select-train", "close"], } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue index 9b3496b09d..a0612ff2ac 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsShow.vue @@ -92,17 +92,13 @@ {{ $__("Add items") }} + - {{ $__("Delete") }} {} ) }, - deleteTrain: function (train) { - this.setConfirmationDialog( - { - title: this.$__( - "Are you sure you want to remove this train?" - ), - message: train.name, - accept_label: this.$__("Yes, delete"), - cancel_label: this.$__("No, do not delete"), - }, - () => { - const client = APIClient.preservation - client.trains.delete(train.train_id).then( - success => { - this.setMessage( - this.$__("Train %s deleted").format(train.name), - true - ) - this.$router.push({ name: "TrainsList" }) - }, - error => {} - ) - } - ) - }, async updateTrainDate(attribute) { let train = JSON.parse(JSON.stringify(this.train)) let train_id = train.train_id diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/routes/preservation.js b/koha-tmpl/intranet-tmpl/prog/js/vue/routes/preservation.js index ac9df94e8f..592c1c4416 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/routes/preservation.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/routes/preservation.js @@ -89,7 +89,7 @@ export const routes = [ }, { path: "edit/:train_id", - name: "TrainsFormEdit", + name: "TrainsFormAddEdit", component: markRaw(TrainsFormAdd), title: $__("Edit train"), }, -- 2.39.5