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 window['av_license_types'] = this.av_license_types.map(e => {
37 e['_id'] = e['authorised_value']
41 let av_license_types_map = this.av_license_types.reduce((map, e) => {
42 map[e.authorised_value] = e
45 window['av_license_statuses'] = this.av_license_statuses.map(e => {
46 e['_id'] = e['authorised_value']
50 let av_license_statuses_map = this.av_license_statuses.reduce((map, e) => {
51 map[e.authorised_value] = e
55 $('#license_list').kohaTable({
57 "url": licenses_table_url,
59 "order": [[0, "asc"]],
62 "render": function (data, type, row, meta) {
63 if (type == 'display') {
64 return escape_str(data)
72 "data": "me.license_id:me.name",
75 "render": function (data, type, row, meta) {
76 // Rendering done in drawCallback
81 "title": __("Description"),
82 "data": "description",
91 "render": function (data, type, row, meta) {
92 return escape_str(av_license_types_map[row.type].lib)
96 "title": __("Status"),
100 "render": function (data, type, row, meta) {
101 return escape_str(av_license_statuses_map[row.status].lib)
105 "title": __("Started on"),
106 "data": "started_on",
109 "render": function (data, type, row, meta) {
110 return $date(row.started_on)
114 "title": __("Ended on"),
118 "render": function (data, type, row, meta) {
119 return $date(row.ended_on)
123 "title": __("Actions"),
124 "data": function (row, type, val, meta) {
125 return '<div class="actions"></div>'
127 "className": "actions noExport",
132 drawCallback: function (settings) {
134 var api = new $.fn.dataTable.Api(settings)
136 $.each($(this).find("td .actions"), function (index, e) {
137 let license_id = api.row(index).data().license_id
138 let editButton = createVNode("a", {
139 class: "btn btn-default btn-xs", role: "button", onClick: () => {
140 edit_license(license_id)
143 [createVNode("i", { class: "fa fa-pencil", 'aria-hidden': "true" }), __("Edit")])
145 let deleteButton = createVNode("a", {
146 class: "btn btn-default btn-xs", role: "button", onClick: () => {
147 delete_license(license_id)
150 [createVNode("i", { class: "fa fa-trash", 'aria-hidden': "true" }), __("Delete")])
152 let n = createVNode('span', {}, [editButton, " ", deleteButton])
156 $.each($(this).find("tbody tr td:first-child"), function (index, e) {
157 let row = api.row(index).data()
158 if (!row) return // Happen if the table is empty
159 let n = createVNode("a", {
162 show_license(row.license_id)
165 `${row.name} (#${row.license_id})`
170 preDrawCallback: function (settings) {
171 var table_id = settings.nTable.id
172 $("#" + table_id).find("thead th").eq(2).attr('data-filter', 'av_license_types')
173 $("#" + table_id).find("thead th").eq(3).attr('data-filter', 'av_license_statuses')
176 }, license_table_settings, 1)
189 beforeRouteEnter(to, from, next) {
195 async getLicenses() {
196 const licenses = await fetchLicenses()
197 this.licenses = licenses
198 this.initialized = true
200 show_license: function (license_id) {
201 this.$router.push("/cgi-bin/koha/erm/licenses/" + license_id)
203 edit_license: function (license_id) {
204 this.$router.push("/cgi-bin/koha/erm/licenses/edit/" + license_id)
206 delete_license: function (license_id) {
207 this.$router.push("/cgi-bin/koha/erm/licenses/delete/" + license_id)
211 av_license_types: Array,
212 av_license_statuses: Array,
214 components: { Toolbar },
215 name: "LicensesList",