Bug 38201: Use getToolbarButtons for "show"
Currently it's only used for the "list" view, and so its name was
confusing.
Now it can also be used for the "show" view, and allow addition of
custom buttons.
TODO:
1. I had to pass the resource from BaseResource as ResourceList could
not access the resource[idAttr] value easily.
Ideally we shouldn't need to pass functions
getToolbarButtons().list()
getToolbarButtons().show(resource)
But only the array of buttons defs:
getToolbarButtons().list
getToolbarButtons().show
2. There is duplication of code when the default is overwritten. We
could fallback to the default when none passed, or pass a string
instead of the full button's def:
return {
list: () => {
return [
"add",
{
to: { name: "EHoldingsLocalTitlesFormImport" },
icon: "plus",
title: __("Import from list"),
},
{
to: { name: "EHoldingsLocalTitlesKBARTImport" },
icon: "plus",
title: __("Import from KBART file"),
},
],
},
show: resource => {
return ["edit", "delete"]
}
}
But that is much more work and not a blocker for now IMO
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
e4e1bdc313
commit
6dbd7e1e75
|
|
@ -68,7 +68,6 @@ export default {
|
|||
resourceListFiltersRequired:
|
||||
props.resourceListFiltersRequired || null,
|
||||
formGroupsDisplayMode: props.formGroupsDisplayMode || null,
|
||||
getToolbarButtons: props.getToolbarButtons || (() => []),
|
||||
appendToShow: props.appendToShow || [],
|
||||
nameAttr: props.nameAttr || null,
|
||||
idAttr: props.idAttr || null,
|
||||
|
|
@ -116,6 +115,7 @@ export default {
|
|||
getResourceShowURL: this.getResourceShowURL,
|
||||
hasAdditionalFields: this.hasAdditionalFields,
|
||||
getFieldGroupings: this.getFieldGroupings,
|
||||
getToolbarButtons: this.getToolbarButtons,
|
||||
resourceAttrs: this.resourceAttrs,
|
||||
listComponent: this.listComponent,
|
||||
resourceNamePlural: this.resourceNamePlural,
|
||||
|
|
@ -350,6 +350,41 @@ export default {
|
|||
getTableFilters() {
|
||||
return [];
|
||||
},
|
||||
/**
|
||||
* Gets the list of buttons to add to the toolbar, for each view: list, show, edit
|
||||
* It can be overridden at the resource level if other buttons are required
|
||||
*
|
||||
* @return {Object} keys must be "list", "show" or "edit", values are functions.
|
||||
*/
|
||||
getToolbarButtons() {
|
||||
return {
|
||||
list: () => {
|
||||
return [
|
||||
{
|
||||
action: "add",
|
||||
onClick: () => this.goToResourceAdd(),
|
||||
title: __("New %s").format(
|
||||
this.i18n.displayNameLowerCase
|
||||
),
|
||||
},
|
||||
];
|
||||
},
|
||||
show: resource => {
|
||||
return [
|
||||
{
|
||||
action: "edit",
|
||||
onClick: () => this.goToResourceEdit(resource),
|
||||
title: __("Edit"),
|
||||
},
|
||||
{
|
||||
action: "delete",
|
||||
onClick: () => this.doResourceDelete(resource),
|
||||
title: __("Delete"),
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
},
|
||||
/**
|
||||
* This method takes a component name (e.g. 'Form' or 'Show') and an optional resource object
|
||||
* and returns an array of grouped objects that determine which fields should be grouped together
|
||||
|
|
|
|||
|
|
@ -18,18 +18,44 @@ export default {
|
|||
const { vendors } = storeToRefs(vendorStore);
|
||||
|
||||
function getToolbarButtons() {
|
||||
return [
|
||||
{
|
||||
to: { name: "EHoldingsLocalTitlesFormImport" },
|
||||
icon: "plus",
|
||||
title: __("Import from list"),
|
||||
return {
|
||||
list: () => {
|
||||
return [
|
||||
{
|
||||
action: "add",
|
||||
onClick: () => this.goToResourceAdd(),
|
||||
title: __("New %s").format(
|
||||
this.i18n.displayNameLowerCase
|
||||
),
|
||||
},
|
||||
{
|
||||
to: { name: "EHoldingsLocalTitlesFormImport" },
|
||||
icon: "plus",
|
||||
title: __("Import from list"),
|
||||
},
|
||||
{
|
||||
to: { name: "EHoldingsLocalTitlesKBARTImport" },
|
||||
icon: "plus",
|
||||
title: __("Import from KBART file"),
|
||||
},
|
||||
];
|
||||
},
|
||||
{
|
||||
to: { name: "EHoldingsLocalTitlesKBARTImport" },
|
||||
icon: "plus",
|
||||
title: __("Import from KBART file"),
|
||||
|
||||
show: resource => {
|
||||
return [
|
||||
{
|
||||
action: "edit",
|
||||
onClick: () => this.goToResourceEdit(resource),
|
||||
title: __("Edit"),
|
||||
},
|
||||
{
|
||||
action: "delete",
|
||||
onClick: () => this.doResourceDelete(resource),
|
||||
title: __("Delete"),
|
||||
},
|
||||
];
|
||||
},
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<template>
|
||||
<a v-if="action === 'add'" @click="$emit('go-to-add-resource')" class="btn btn-default"
|
||||
<a v-if="action === 'add'" class="btn btn-default"
|
||||
><font-awesome-icon icon="plus" /> {{ title }}</a
|
||||
>
|
||||
<a v-if="action === 'delete'" @click="$emit('delete-resource')" class="btn btn-default"
|
||||
><font-awesome-icon icon="trash" /> {{ $__("Delete") }}</a
|
||||
<a v-if="action === 'delete'" class="btn btn-default"
|
||||
><font-awesome-icon icon="trash" /> {{ title }}</a
|
||||
>
|
||||
<a v-if="action === 'edit'" @click="$emit('go-to-edit-resource')" class="btn btn-default"
|
||||
><font-awesome-icon icon="pencil" /> {{ $__("Edit") }}</a
|
||||
<a v-if="action === 'edit'" class="btn btn-default"
|
||||
><font-awesome-icon icon="pencil" /> {{ title }}</a
|
||||
>
|
||||
<a
|
||||
v-if="callback"
|
||||
|
|
|
|||
|
|
@ -1,19 +1,7 @@
|
|||
<template>
|
||||
<div v-if="!initialized">{{ $__("Loading") }}</div>
|
||||
<div v-else :id="`${resourceNamePlural}_list`">
|
||||
<Toolbar v-if="!embedded">
|
||||
<ToolbarButton
|
||||
action="add"
|
||||
@go-to-add-resource="goToResourceAdd"
|
||||
:title="i18n.newLabel"
|
||||
/>
|
||||
<ToolbarButton
|
||||
v-for="(button, i) in getToolbarButtons()"
|
||||
v-bind:key="i"
|
||||
:to="button.to"
|
||||
:icon="button.icon"
|
||||
:title="button.title"
|
||||
/>
|
||||
<Toolbar v-if="!embedded" :buttons="getToolbarButtons().list()">
|
||||
</Toolbar>
|
||||
<template v-if="resourceCount > 0">
|
||||
<slot name="filters" :table="table" />
|
||||
|
|
@ -38,7 +26,6 @@
|
|||
|
||||
<script>
|
||||
import Toolbar from "./Toolbar.vue";
|
||||
import ToolbarButton from "./ToolbarButton.vue";
|
||||
import { ref, inject } from "vue";
|
||||
import { APIClient } from "../fetch/api-client.js";
|
||||
import KohaTable from "./KohaTable.vue";
|
||||
|
|
@ -74,10 +61,7 @@ export default {
|
|||
resourceAttrs: Array,
|
||||
nameAttr: String,
|
||||
idAttr: String,
|
||||
getToolbarButtons: {
|
||||
type: Function,
|
||||
default: () => [],
|
||||
},
|
||||
getToolbarButtons: Function,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
|
@ -280,7 +264,7 @@ export default {
|
|||
return this.tableOptions;
|
||||
},
|
||||
},
|
||||
components: { Toolbar, ToolbarButton, KohaTable },
|
||||
components: { Toolbar, KohaTable },
|
||||
name: "ResourcesList",
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,7 @@
|
|||
<template>
|
||||
<div v-if="!initialized">{{ $__("Loading") }}</div>
|
||||
<div v-else :id="`${resourceNamePlural}_show`">
|
||||
<Toolbar>
|
||||
<ToolbarButton
|
||||
action="edit"
|
||||
@go-to-edit-resource="goToResourceEdit(resource)"
|
||||
/>
|
||||
<ToolbarButton
|
||||
action="delete"
|
||||
@delete-resource="doResourceDelete(resource)"
|
||||
/>
|
||||
</Toolbar>
|
||||
<Toolbar :buttons="getToolbarButtons().show(resource)"></Toolbar>
|
||||
|
||||
<h2>
|
||||
{{ i18n.displayName + " #" + resource[idAttr] }}
|
||||
|
|
@ -53,7 +44,6 @@
|
|||
|
||||
<script>
|
||||
import Toolbar from "./Toolbar.vue";
|
||||
import ToolbarButton from "./ToolbarButton.vue";
|
||||
import ShowElement from "./ShowElement.vue";
|
||||
|
||||
export default {
|
||||
|
|
@ -74,6 +64,7 @@ export default {
|
|||
resourceNamePlural: String,
|
||||
getFieldGroupings: Function,
|
||||
appendToShow: Array,
|
||||
getToolbarButtons: Function,
|
||||
},
|
||||
created() {
|
||||
this.getResource(this.$route.params[this.idAttr]);
|
||||
|
|
@ -92,7 +83,7 @@ export default {
|
|||
);
|
||||
},
|
||||
},
|
||||
components: { Toolbar, ToolbarButton, ShowElement },
|
||||
components: { Toolbar, ShowElement },
|
||||
name: "ResourceShow",
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -4,12 +4,27 @@
|
|||
:class="sticky ? 'btn-toolbar sticky' : 'btn-toolbar'"
|
||||
ref="toolbar"
|
||||
>
|
||||
<slot />
|
||||
<template v-for="(button, i) in buttons">
|
||||
<ToolbarButton
|
||||
:action="button.action"
|
||||
@click="button.onClick"
|
||||
:title="button.title"
|
||||
:to="button.to"
|
||||
:icon="button.icon"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ToolbarButton from "./ToolbarButton.vue";
|
||||
export default {
|
||||
props: {
|
||||
buttons: {
|
||||
type: Array,
|
||||
},
|
||||
},
|
||||
components: { ToolbarButton },
|
||||
name: "Toolbar",
|
||||
props: {
|
||||
sticky: {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
<template>
|
||||
<Link
|
||||
v-bind="$props"
|
||||
@go-to-add-resource="$emit('go-to-add-resource')"
|
||||
@delete-resource="$emit('delete-resource')"
|
||||
@go-to-edit-resource="$emit('go-to-edit-resource')"
|
||||
/>
|
||||
</template>
|
||||
|
||||
|
|
@ -35,7 +32,6 @@ export default {
|
|||
required: false,
|
||||
},
|
||||
},
|
||||
emits: ["go-to-add-resource", "delete-resource", "go-to-edit-resource"],
|
||||
name: "Toolbar",
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue