Bug 29234: Further clean Z3950 Tests
[srvgit] / koha-tmpl / intranet-tmpl / prog / js / vue / components / ERM / EHoldingsLocalPackageTitlesList.vue
1 <template>
2     <div id="title_list_result">
3         <table :id="table_id"></table>
4     </div>
5 </template>
6
7 <script>
8 import { inject, createVNode, render } from "vue"
9 import { useDataTable } from "../../composables/datatables"
10
11 export default {
12     setup() {
13         const AVStore = inject("AVStore")
14         const { get_lib_from_av, map_av_dt_filter } = AVStore
15
16         const table_id = "title_list"
17         useDataTable(table_id)
18
19         return {
20             get_lib_from_av,
21             map_av_dt_filter,
22             table_id,
23         }
24     },
25     data() {
26         return {}
27     },
28     methods: {
29         show_resource: function (resource_id) {
30             this.$router.push(
31                 "/cgi-bin/koha/erm/eholdings/local/resources/" + resource_id
32             )
33         },
34         build_datatable: function () {
35             let show_resource = this.show_resource
36             let package_id = this.package_id
37             let get_lib_from_av = this.get_lib_from_av
38             let map_av_dt_filter = this.map_av_dt_filter
39             let table_id = this.table_id
40
41             window["av_title_publication_types"] = map_av_dt_filter(
42                 "av_title_publication_types"
43             )
44
45             $("#" + table_id).kohaTable(
46                 {
47                     ajax: {
48                         url:
49                             "/api/v1/erm/eholdings/local/packages/" +
50                             package_id +
51                             "/resources",
52                     },
53                     embed: ["title"],
54                     autoWidth: false,
55                     columns: [
56                         {
57                             title: __("Name"),
58                             data: "title.publication_title",
59                             searchable: true,
60                             orderable: true,
61                             render: function (data, type, row, meta) {
62                                 // Rendering done in drawCallback
63                                 return ""
64                             },
65                         },
66                         {
67                             title: __("Publication type"),
68                             data: "title.publication_type",
69                             searchable: true,
70                             orderable: true,
71                             render: function (data, type, row, meta) {
72                                 return escape_str(
73                                     get_lib_from_av(
74                                         "av_title_publication_types",
75                                         row.title.publication_type
76                                     )
77                                 )
78                             },
79                         },
80                     ],
81                     drawCallback: function (settings) {
82                         var api = new $.fn.dataTable.Api(settings)
83
84                         $.each(
85                             $(this).find("tbody tr td:first-child"),
86                             function (index, e) {
87                                 let tr = $(this).parent()
88                                 let row = api.row(tr).data()
89                                 if (!row) return // Happen if the table is empty
90                                 let n = createVNode(
91                                     "a",
92                                     {
93                                         role: "button",
94                                         href:
95                                             "/cgi-bin/koha/erm/eholdings/local/resources/" +
96                                             row.resource_id,
97                                         onClick: e => {
98                                             e.preventDefault()
99                                             show_resource(row.resource_id)
100                                         },
101                                     },
102                                     `${row.title.publication_title}`
103                                 )
104                                 render(n, e)
105                             }
106                         )
107                     },
108                     preDrawCallback: function (settings) {
109                         $("#" + table_id)
110                             .find("thead th")
111                             .eq(1)
112                             .attr("data-filter", "av_title_publication_types")
113                     },
114                 },
115                 null,
116                 1
117             )
118         },
119     },
120     mounted() {
121         this.build_datatable()
122     },
123     props: {
124         package_id: String,
125     },
126     name: "EHoldingsLocalPackageTitlesList",
127 }
128 </script>
129
130 <style scoped>
131 #title_list {
132     display: table;
133 }
134 </style>