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:
parent
e2fb59d88f
commit
116bc6d386
1 changed files with 57 additions and 89 deletions
|
@ -1,66 +1,73 @@
|
|||
<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 {}
|
||||
},
|
||||
methods: {
|
||||
show_resource: function (resource_id) {
|
||||
this.$router.push(
|
||||
"/cgi-bin/koha/erm/eholdings/local/resources/" + resource_id
|
||||
)
|
||||
},
|
||||
build_datatable: function () {
|
||||
let show_resource = this.show_resource
|
||||
let package_id = this.package_id
|
||||
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
|
||||
|
||||
window["av_title_publication_types"] = map_av_dt_filter(
|
||||
"av_title_publication_types"
|
||||
)
|
||||
|
||||
$("#" + table_id).kohaTable(
|
||||
{
|
||||
ajax: {
|
||||
return {
|
||||
tableOptions: {
|
||||
columns: this.getTableColumns(),
|
||||
url:
|
||||
"/api/v1/erm/eholdings/local/packages/" +
|
||||
package_id +
|
||||
this.package_id +
|
||||
"/resources",
|
||||
options: { embed: "title" },
|
||||
add_filters: true,
|
||||
filters_options: {
|
||||
1: () =>
|
||||
this.map_av_dt_filter("av_title_publication_types"),
|
||||
},
|
||||
embed: ["title"],
|
||||
autoWidth: false,
|
||||
columns: [
|
||||
actions: {
|
||||
0: ["show"],
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
doShow: function (resource, dt, event) {
|
||||
event.preventDefault()
|
||||
this.$router.push(
|
||||
"/cgi-bin/koha/erm/eholdings/local/resources/" +
|
||||
resource.resource_id
|
||||
)
|
||||
},
|
||||
getTableColumns: function () {
|
||||
let get_lib_from_av = this.get_lib_from_av
|
||||
let escape_str = this.escape_str
|
||||
|
||||
return [
|
||||
{
|
||||
title: __("Name"),
|
||||
data: "title.publication_title",
|
||||
searchable: true,
|
||||
orderable: true,
|
||||
render: function (data, type, row, meta) {
|
||||
// Rendering done in drawCallback
|
||||
return ""
|
||||
return (
|
||||
'<a href="/cgi-bin/koha/erm/eholdings/local/resources/' +
|
||||
row.resource_id +
|
||||
'" class="show">' +
|
||||
escape_str(row.title.publication_title) +
|
||||
"</a>"
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -77,52 +84,13 @@ export default {
|
|||
)
|
||||
},
|
||||
},
|
||||
],
|
||||
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)
|
||||
}
|
||||
)
|
||||
},
|
||||
preDrawCallback: function (settings) {
|
||||
$("#" + table_id)
|
||||
.find("thead th")
|
||||
.eq(1)
|
||||
.attr("data-filter", "av_title_publication_types")
|
||||
},
|
||||
},
|
||||
null,
|
||||
1
|
||||
)
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.build_datatable()
|
||||
},
|
||||
props: {
|
||||
package_id: String,
|
||||
},
|
||||
components: { KohaTable },
|
||||
name: "EHoldingsLocalPackageTitlesList",
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue