2 <div v-if="!initialized">{{ $__("Loading") }}</div>
3 <div v-else id="licenses_list">
5 <div v-if="license_count > 0" class="page-section">
6 <table :id="table_id"></table>
8 <div v-else class="dialog message">
9 {{ $__("There are no licenses defined") }}
15 import Toolbar from "./LicensesToolbar.vue"
16 import { inject, createVNode, render } from "vue"
17 import { storeToRefs } from "pinia"
18 import { APIClient } from "../../fetch/api-client.js"
19 import { useDataTable } from "../../composables/datatables"
23 const vendorStore = inject("vendorStore")
24 const { vendors } = storeToRefs(vendorStore)
26 const AVStore = inject("AVStore")
27 const { get_lib_from_av, map_av_dt_filter } = AVStore
29 const { setConfirmationDialog, setMessage } = inject("mainStore")
31 const table_id = "license_list"
32 useDataTable(table_id)
39 setConfirmationDialog,
49 beforeRouteEnter(to, from, next) {
51 vm.getLicenseCount().then(() => vm.build_datatable())
55 async getLicenseCount() {
56 const client = APIClient.erm
57 await client.licenses.count().then(
59 this.license_count = count
60 this.initialized = true
65 show_license: function (license_id) {
66 this.$router.push("/cgi-bin/koha/erm/licenses/" + license_id)
68 edit_license: function (license_id) {
69 this.$router.push("/cgi-bin/koha/erm/licenses/edit/" + license_id)
71 delete_license: function (license_id, license_name) {
72 this.setConfirmationDialog(
75 "Are you sure you want to remove this license?"
77 message: license_name,
78 accept_label: this.$__("Yes, delete"),
79 cancel_label: this.$__("No, do not delete"),
82 const client = APIClient.erm
83 client.licenses.delete(license_id).then(
86 this.$__("License %s deleted").format(
91 $("#" + this.table_id)
93 .ajax.url("/api/v1/erm/licenses")
101 build_datatable: function () {
102 let show_license = this.show_license
103 let edit_license = this.edit_license
104 let delete_license = this.delete_license
105 let get_lib_from_av = this.get_lib_from_av
106 let map_av_dt_filter = this.map_av_dt_filter
107 let default_search = this.$route.query.q
108 let table_id = this.table_id
110 window["vendors"] = this.vendors.map(e => {
112 e["_str"] = e["name"]
115 let vendors_map = this.vendors.reduce((map, e) => {
119 let avs = ["av_license_types", "av_license_statuses"]
120 avs.forEach(function (av_cat) {
121 window[av_cat] = map_av_dt_filter(av_cat)
124 $("#" + table_id).kohaTable(
127 url: "/api/v1/erm/licenses",
130 search: { search: default_search },
134 render: function (data, type, row, meta) {
135 if (type == "display") {
136 return escape_str(data)
145 data: "me.license_id:me.name",
148 render: function (data, type, row, meta) {
149 // Rendering done in drawCallback
158 render: function (data, type, row, meta) {
159 return row.vendor_id != undefined
161 vendors_map[row.vendor_id].name
168 title: __("Description"),
178 render: function (data, type, row, meta) {
192 render: function (data, type, row, meta) {
195 "av_license_statuses",
202 title: __("Started on"),
206 render: function (data, type, row, meta) {
207 return $date(row.started_on)
211 title: __("Ended on"),
215 render: function (data, type, row, meta) {
216 return $date(row.ended_on)
220 title: __("Actions"),
221 data: function (row, type, val, meta) {
222 return '<div class="actions"></div>'
224 className: "actions noExport",
229 drawCallback: function (settings) {
230 var api = new $.fn.dataTable.Api(settings)
233 $(this).find("td .actions"),
234 function (index, e) {
235 let tr = $(this).parent().parent()
236 let license_id = api.row(tr).data().license_id
237 let license_name = api.row(tr).data().name
238 let editButton = createVNode(
241 class: "btn btn-default btn-xs",
244 edit_license(license_id)
249 class: "fa fa-pencil",
250 "aria-hidden": "true",
256 let deleteButton = createVNode(
259 class: "btn btn-default btn-xs",
270 class: "fa fa-trash",
271 "aria-hidden": "true",
277 let n = createVNode("span", {}, [
287 $(this).find("tbody tr td:first-child"),
288 function (index, e) {
289 let tr = $(this).parent()
290 let row = api.row(tr).data()
291 if (!row) return // Happen if the table is empty
297 show_license(row.license_id)
300 `${row.name} (#${row.license_id})`
306 preDrawCallback: function (settings) {
310 .attr("data-filter", "vendors")
314 .attr("data-filter", "av_license_types")
318 .attr("data-filter", "av_license_statuses")
321 license_table_settings,
327 av_license_types: Array,
328 av_license_statuses: Array,
330 components: { Toolbar },
331 name: "LicensesList",