From 6f9ceac8542430cb5ace1eb14328cda2386d56d1 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 20 Nov 2024 10:12:19 +0000 Subject: [PATCH] Bug 38010: Add callbacks to Toolbarbutton --- .../prog/js/vue/components/ToolbarButton.vue | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue index 6e19b31b86e..76577e32c29 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue @@ -17,6 +17,14 @@ :class="class" > {{ $__("Edit") }} + + {{ title }} + {{ title }} @@ -43,6 +51,36 @@ export default { title: { type: String, }, + callback: { + type: [String, Function], + required: false, + }, + }, + methods: { + redirect() { + if (typeof this.to === "string") + window.location.href = this.formatUrl(this.to) + if (typeof this.to === "object") { + let url = this.to.path + if (this.to.hasOwnProperty("query")) { + url += + "?" + + Object.keys(this.to.query) + .map( + queryParam => + `${queryParam}=${this.to.query[queryParam]}` + ) + .join("&") + } + window.open(this.formatUrl(url, this.to.internal), "_blank") + } + }, + formatUrl(url) { + if (url.includes("http://") || url.includes("https://")) return url + if (url.includes("cgi-bin/koha")) + return `//${window.location.host}/${url}` + return `//${url}` + }, }, emits: ["go-to-add-resource", "go-to-edit-resource", "delete-resource"], name: "Toolbar", -- 2.39.3 (Apple Git-146)