2 <div v-if="!this.initialized">{{ $t("Loading") }}</div>
3 <div v-else-if="this.licenses" id="licenses_list">
5 <table v-if="licenses.length" id="license_list"></table>
6 <div v-else-if="this.initialized" class="dialog message">
7 {{ $t("There are no licenses defined") }}
13 import Toolbar from "./LicensesToolbar.vue"
14 import { createVNode, render } from 'vue'
15 import { useAVStore } from "../../stores/authorised_values"
16 import { storeToRefs } from "pinia"
17 import { fetchLicenses } from "../../fetch"
21 const AVStore = useAVStore()
25 } = storeToRefs(AVStore)
33 let show_license = this.show_license
34 let edit_license = this.edit_license
35 let delete_license = this.delete_license
36 let default_search = this.$route.query.q
38 window['av_license_types'] = this.av_license_types.map(e => {
39 e['_id'] = e['authorised_value']
43 let av_license_types_map = this.av_license_types.reduce((map, e) => {
44 map[e.authorised_value] = e
47 window['av_license_statuses'] = this.av_license_statuses.map(e => {
48 e['_id'] = e['authorised_value']
52 let av_license_statuses_map = this.av_license_statuses.reduce((map, e) => {
53 map[e.authorised_value] = e
57 $('#license_list').kohaTable({
59 "url": "/api/v1/erm/licenses",
61 "order": [[0, "asc"]],
62 "search": { search: default_search },
65 "render": function (data, type, row, meta) {
66 if (type == 'display') {
67 return escape_str(data)
75 "data": "me.license_id:me.name",
78 "render": function (data, type, row, meta) {
79 // Rendering done in drawCallback
84 "title": __("Description"),
85 "data": "description",
94 "render": function (data, type, row, meta) {
95 return escape_str(av_license_types_map[row.type].lib)
99 "title": __("Status"),
103 "render": function (data, type, row, meta) {
104 return escape_str(av_license_statuses_map[row.status].lib)
108 "title": __("Started on"),
109 "data": "started_on",
112 "render": function (data, type, row, meta) {
113 return $date(row.started_on)
117 "title": __("Ended on"),
121 "render": function (data, type, row, meta) {
122 return $date(row.ended_on)
126 "title": __("Actions"),
127 "data": function (row, type, val, meta) {
128 return '<div class="actions"></div>'
130 "className": "actions noExport",
135 drawCallback: function (settings) {
137 var api = new $.fn.dataTable.Api(settings)
139 $.each($(this).find("td .actions"), function (index, e) {
140 let license_id = api.row(index).data().license_id
141 let editButton = createVNode("a", {
142 class: "btn btn-default btn-xs", role: "button", onClick: () => {
143 edit_license(license_id)
146 [createVNode("i", { class: "fa fa-pencil", 'aria-hidden': "true" }), __("Edit")])
148 let deleteButton = createVNode("a", {
149 class: "btn btn-default btn-xs", role: "button", onClick: () => {
150 delete_license(license_id)
153 [createVNode("i", { class: "fa fa-trash", 'aria-hidden': "true" }), __("Delete")])
155 let n = createVNode('span', {}, [editButton, " ", deleteButton])
159 $.each($(this).find("tbody tr td:first-child"), function (index, e) {
160 let row = api.row(index).data()
161 if (!row) return // Happen if the table is empty
162 let n = createVNode("a", {
165 show_license(row.license_id)
168 `${row.name} (#${row.license_id})`
173 preDrawCallback: function (settings) {
174 var table_id = settings.nTable.id
175 $("#" + table_id).find("thead th").eq(2).attr('data-filter', 'av_license_types')
176 $("#" + table_id).find("thead th").eq(3).attr('data-filter', 'av_license_statuses')
179 }, license_table_settings, 1)
192 beforeRouteEnter(to, from, next) {
198 async getLicenses() {
199 const licenses = await fetchLicenses()
200 this.licenses = licenses
201 this.initialized = true
203 show_license: function (license_id) {
204 this.$router.push("/cgi-bin/koha/erm/licenses/" + license_id)
206 edit_license: function (license_id) {
207 this.$router.push("/cgi-bin/koha/erm/licenses/edit/" + license_id)
209 delete_license: function (license_id) {
210 this.$router.push("/cgi-bin/koha/erm/licenses/delete/" + license_id)
214 av_license_types: Array,
215 av_license_statuses: Array,
217 components: { Toolbar },
218 name: "LicensesList",