From 4d1ff5eb51cd76acaeefc1340a08a0e9b42cbcb9 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 Signed-off-by: Michaela Sieber Signed-off-by: Jonathan Druart --- .../prog/js/vue/components/ToolbarButton.vue | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) 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 2a11bed51b0..68e6ca346a5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ToolbarButton.vue @@ -1,5 +1,13 @@ @@ -17,7 +25,37 @@ 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}`; + }, }, - name: "Toolbar", + name: "ToolbarButton", }; -- 2.34.1