From 809f90d394fdef8142fdf8f4a6e825dc14a132d4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 7 Mar 2023 15:37:10 +0100 Subject: [PATCH] Bug 33066: Remove build_datatable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Pedro Amorim Signed-off-by: Agustín Moyano Signed-off-by: Tomas Cohen Arazi --- .../js/vue/components/ERM/AgreementsList.vue | 299 ------------------ 1 file changed, 299 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue index e5ae48e057..e7fc10d20e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue @@ -208,305 +208,6 @@ export default { } this.$refs.table.redraw(this.table_url()) }, - build_datatable: function () { - let show_agreement = this.show_agreement - let edit_agreement = this.edit_agreement - let delete_agreement = this.delete_agreement - let select_agreement = this.select_agreement - let get_lib_from_av = this.get_lib_from_av - let map_av_dt_filter = this.map_av_dt_filter - let datatable_url = this.datatable_url - let default_search = this.$route.query.q - let actions = this.before_route_entered ? "edit_delete" : "select" - let filters = this.filters - let table_id = this.table_id - let logged_in_user = this.logged_in_user - - window["vendors"] = this.vendors.map(e => { - e["_id"] = e["id"] - e["_str"] = e["name"] - return e - }) - let vendors_map = this.vendors.reduce((map, e) => { - map[e.id] = e - return map - }, {}) - let avs = [ - "av_agreement_statuses", - "av_agreement_closure_reasons", - "av_agreement_renewal_priorities", - ] - avs.forEach(function (av_cat) { - window[av_cat] = map_av_dt_filter(av_cat) - }) - - window["av_agreement_is_perpetual"] = [ - { _id: 0, _str: _("No") }, - { _id: 1, _str: _("Yes") }, - ] - - let additional_filters = { - "user_roles.user_id": function () { - return filters.by_mine ? logged_in_user.borrowernumber : "" - }, - } - const table = $("#" + table_id).kohaTable( - { - ajax: { - url: datatable_url, - }, - embed: ["user_roles"], - order: [[0, "asc"]], - autoWidth: false, - search: { search: default_search }, - columnDefs: [ - { - targets: [0, 2], - render: function (data, type, row, meta) { - if (type == "display") { - return escape_str(data) - } - return data - }, - }, - ], - columns: [ - { - title: __("Name"), - data: "me.agreement_id:me.name", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - // Rendering done in drawCallback - return "" - }, - }, - { - title: __("Vendor"), - data: "vendor_id", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - return row.vendor_id != undefined - ? escape_str( - vendors_map[row.vendor_id].name - ) - : "" - }, - }, - { - title: __("Description"), - data: "description", - searchable: true, - orderable: true, - }, - { - title: __("Status"), - data: "status", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - return escape_str( - get_lib_from_av( - "av_agreement_statuses", - row.status - ) - ) - }, - }, - { - title: __("Closure reason"), - data: "closure_reason", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - return escape_str( - get_lib_from_av( - "av_agreement_closure_reasons", - row.closure_reason - ) - ) - }, - }, - { - title: __("Is perpetual"), - data: "is_perpetual", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - return escape_str( - row.is_perpetual ? _("Yes") : _("No") - ) - }, - }, - { - title: __("Renewal priority"), - data: "renewal_priority", - searchable: true, - orderable: true, - render: function (data, type, row, meta) { - return escape_str( - get_lib_from_av( - "av_agreement_renewal_priorities", - row.renewal_priority - ) - ) - }, - }, - { - title: __("Actions"), - data: function (row, type, val, meta) { - return '
' - }, - className: "actions noExport", - searchable: false, - orderable: false, - }, - ], - drawCallback: function (settings) { - var api = new $.fn.dataTable.Api(settings) - - if (actions == "edit_delete") { - $.each( - $(this).find("td .actions"), - function (index, e) { - let tr = $(this).parent().parent() - let agreement_id = api - .row(tr) - .data().agreement_id - let agreement_name = api.row(tr).data().name - let editButton = createVNode( - "a", - { - class: "btn btn-default btn-xs", - role: "button", - onClick: () => { - edit_agreement(agreement_id) - }, - }, - [ - createVNode("i", { - class: "fa fa-pencil", - "aria-hidden": "true", - }), - __("Edit"), - ] - ) - - let deleteButton = createVNode( - "a", - { - class: "btn btn-default btn-xs", - role: "button", - onClick: () => { - delete_agreement( - agreement_id, - agreement_name - ) - }, - }, - [ - createVNode("i", { - class: "fa fa-trash", - "aria-hidden": "true", - }), - __("Delete"), - ] - ) - - let n = createVNode("span", {}, [ - editButton, - " ", - deleteButton, - ]) - render(n, e) - } - ) - } else { - $.each( - $(this).find("td .actions"), - function (index, e) { - let tr = $(this).parent().parent() - let agreement_id = api - .row(tr) - .data().agreement_id - let selectButton = createVNode( - "a", - { - class: "btn btn-default btn-xs", - role: "button", - onClick: () => { - select_agreement(agreement_id) - }, - }, - [ - createVNode("i", { - class: "fa fa-check", - "aria-hidden": "true", - }), - __("Select"), - ] - ) - - let n = createVNode("span", {}, [ - selectButton, - ]) - render(n, e) - } - ) - } - - $.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", - onClick: () => { - show_agreement(row.agreement_id) - }, - }, - `${row.name} (#${row.agreement_id})` - ) - render(n, e) - } - ) - }, - preDrawCallback: function (settings) { - $("#" + table_id) - .find("thead th") - .eq(1) - .attr("data-filter", "vendors") - $("#" + table_id) - .find("thead th") - .eq(3) - .attr("data-filter", "av_agreement_statuses") - $("#" + table_id) - .find("thead th") - .eq(4) - .attr("data-filter", "av_agreement_closure_reasons") - $("#" + table_id) - .find("thead th") - .eq(5) - .attr("data-filter", "av_agreement_is_perpetual") - $("#" + table_id) - .find("thead th") - .eq(6) - .attr( - "data-filter", - "av_agreement_renewal_priorities" - ) - }, - }, - agreement_table_settings, - 1, - additional_filters - ) - }, getTableColumns: function () { let get_lib_from_av = this.get_lib_from_av let escape_str = this.escape_str -- 2.39.5