Bug 33066: Use KohaTable for EHoldingsLocalPackageTitlesList

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>

Signed-off-by: Agustín Moyano <agustinmoyano@theke.io>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-03-08 14:20:50 +01:00 committed by Tomas Cohen Arazi
parent e2fb59d88f
commit 116bc6d386
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -1,128 +1,96 @@
<template>
<div id="title_list_result">
<table :id="table_id"></table>
<KohaTable ref="table" v-bind="tableOptions" @show="doShow"></KohaTable>
</div>
</template>
<script>
import { inject, createVNode, render } from "vue"
import { inject, ref } from "vue"
import { useDataTable } from "../../composables/datatables"
import KohaTable from "../KohaTable.vue"
export default {
setup() {
const AVStore = inject("AVStore")
const { get_lib_from_av, map_av_dt_filter } = AVStore
const table_id = "title_list"
useDataTable(table_id)
const table = ref()
return {
get_lib_from_av,
map_av_dt_filter,
table_id,
escape_str,
table,
}
},
data() {
return {}
return {
tableOptions: {
columns: this.getTableColumns(),
url:
"/api/v1/erm/eholdings/local/packages/" +
this.package_id +
"/resources",
options: { embed: "title" },
add_filters: true,
filters_options: {
1: () =>
this.map_av_dt_filter("av_title_publication_types"),
},
actions: {
0: ["show"],
},
},
}
},
methods: {
show_resource: function (resource_id) {
doShow: function (resource, dt, event) {
event.preventDefault()
this.$router.push(
"/cgi-bin/koha/erm/eholdings/local/resources/" + resource_id
"/cgi-bin/koha/erm/eholdings/local/resources/" +
resource.resource_id
)
},
build_datatable: function () {
let show_resource = this.show_resource
let package_id = this.package_id
getTableColumns: function () {
let get_lib_from_av = this.get_lib_from_av
let map_av_dt_filter = this.map_av_dt_filter
let table_id = this.table_id
let escape_str = this.escape_str
window["av_title_publication_types"] = map_av_dt_filter(
"av_title_publication_types"
)
$("#" + table_id).kohaTable(
return [
{
ajax: {
url:
"/api/v1/erm/eholdings/local/packages/" +
package_id +
"/resources",
},
embed: ["title"],
autoWidth: false,
columns: [
{
title: __("Name"),
data: "title.publication_title",
searchable: true,
orderable: true,
render: function (data, type, row, meta) {
// Rendering done in drawCallback
return ""
},
},
{
title: __("Publication type"),
data: "title.publication_type",
searchable: true,
orderable: true,
render: function (data, type, row, meta) {
return escape_str(
get_lib_from_av(
"av_title_publication_types",
row.title.publication_type
)
)
},
},
],
drawCallback: function (settings) {
var api = new $.fn.dataTable.Api(settings)
$.each(
$(this).find("tbody tr td:first-child"),
function (index, e) {
let tr = $(this).parent()
let row = api.row(tr).data()
if (!row) return // Happen if the table is empty
let n = createVNode(
"a",
{
role: "button",
href:
"/cgi-bin/koha/erm/eholdings/local/resources/" +
row.resource_id,
onClick: e => {
e.preventDefault()
show_resource(row.resource_id)
},
},
`${row.title.publication_title}`
)
render(n, e)
}
title: __("Name"),
data: "title.publication_title",
searchable: true,
orderable: true,
render: function (data, type, row, meta) {
return (
'<a href="/cgi-bin/koha/erm/eholdings/local/resources/' +
row.resource_id +
'" class="show">' +
escape_str(row.title.publication_title) +
"</a>"
)
},
preDrawCallback: function (settings) {
$("#" + table_id)
.find("thead th")
.eq(1)
.attr("data-filter", "av_title_publication_types")
},
{
title: __("Publication type"),
data: "title.publication_type",
searchable: true,
orderable: true,
render: function (data, type, row, meta) {
return escape_str(
get_lib_from_av(
"av_title_publication_types",
row.title.publication_type
)
)
},
},
null,
1
)
]
},
},
mounted() {
this.build_datatable()
},
props: {
package_id: String,
},
components: { KohaTable },
name: "EHoldingsLocalPackageTitlesList",
}
</script>