Bug 38010: Add callbacks to Toolbarbutton
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
7c824a4d0f
commit
1c65c497e0
|
|
@ -1,5 +1,13 @@
|
|||
<template>
|
||||
<router-link :to="to" class="btn btn-default"
|
||||
<a
|
||||
v-if="callback"
|
||||
@click="typeof callback === 'string' ? redirect() : callback"
|
||||
class="btn btn-default"
|
||||
style="cursor: pointer"
|
||||
>
|
||||
<font-awesome-icon v-if="icon" :icon="icon" /> {{ title }}
|
||||
</a>
|
||||
<router-link v-else :to="to" :class="class"
|
||||
><font-awesome-icon v-if="icon" :icon="icon" /> {{ title }}</router-link
|
||||
>
|
||||
</template>
|
||||
|
|
@ -17,7 +25,37 @@ export default {
|
|||
title: {
|
||||
type: String,
|
||||
},
|
||||
callback: {
|
||||
type: [String, Function],
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
name: "Toolbar",
|
||||
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: "ToolbarButton",
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue