View | Details | Raw Unified | Return to bug 33066
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue (-176 / +132 lines)
Lines 57-70 Link Here
57
                >
57
                >
58
            </div>
58
            </div>
59
            <div id="title_list_result" class="page-section">
59
            <div id="title_list_result" class="page-section">
60
                <table :id="table_id"></table>
60
                <KohaTable
61
                    v-if="show_table"
62
                    ref="table"
63
                    v-bind="tableOptions"
64
                    @show="doShow"
65
                ></KohaTable>
61
            </div>
66
            </div>
62
        </div>
67
        </div>
63
    </div>
68
    </div>
64
</template>
69
</template>
65
70
66
<script>
71
<script>
67
import { inject, createVNode, render } from "vue"
72
import { inject, ref, reactive } from "vue"
68
import { storeToRefs } from "pinia"
73
import { storeToRefs } from "pinia"
69
import { APIClient } from "../../fetch/api-client.js"
74
import { APIClient } from "../../fetch/api-client.js"
70
import {
75
import {
Lines 72-77 import { Link Here
72
    build_url_params,
77
    build_url_params,
73
    build_url,
78
    build_url,
74
} from "../../composables/datatables"
79
} from "../../composables/datatables"
80
import KohaTable from "../KohaTable.vue"
75
81
76
export default {
82
export default {
77
    setup() {
83
    setup() {
Lines 82-109 export default { Link Here
82
        const { av_title_publication_types } = storeToRefs(AVStore)
88
        const { av_title_publication_types } = storeToRefs(AVStore)
83
        const { get_lib_from_av } = AVStore
89
        const { get_lib_from_av } = AVStore
84
90
85
        const table_id = "title_list"
91
        const table = ref()
86
        useDataTable(table_id)
92
        const filters = reactive({
93
            publication_title: "",
94
            publication_type: "",
95
            selection_type: "",
96
        })
87
97
88
        return {
98
        return {
89
            vendors,
99
            vendors,
90
            av_title_publication_types,
100
            av_title_publication_types,
91
            get_lib_from_av,
101
            get_lib_from_av,
102
            escape_str,
92
            erm_providers,
103
            erm_providers,
93
            table_id,
104
            table,
94
        }
105
        }
95
    },
106
    },
96
    data: function () {
107
    data: function () {
108
        this.filters = {
109
            publication_title: this.$route.query.publication_title || "",
110
            publication_type: this.$route.query.publication_type || "",
111
            selection_type: this.$route.query.selection_type || "",
112
        }
113
        let filters = this.filters
114
97
        return {
115
        return {
98
            titles: [],
116
            titles: [],
99
            initialized: true,
117
            initialized: true,
100
            filters: {
118
            tableOptions: {
101
                publication_title: this.$route.query.publication_title || "",
119
                columns: this.getTableColumns(),
102
                publication_type: this.$route.query.publication_type || "",
120
                url: "/api/v1/erm/eholdings/ebsco/titles",
103
                selection_type: this.$route.query.selection_type || "",
121
                options: {
122
                    ordering: false,
123
                    dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>',
124
                    aLengthMenu: [
125
                        [10, 20, 50, 100],
126
                        [10, 20, 50, 100],
127
                    ],
128
                },
129
                filters_options: {
130
                    1: () =>
131
                        this.map_av_dt_filter("av_title_publication_types"),
132
                },
133
                actions: { 0: ["show"] },
134
                default_filters: {
135
                    publication_title: function () {
136
                        return filters.publication_title || ""
137
                    },
138
                    publication_type: function () {
139
                        return filters.publication_type || ""
140
                    },
141
                    selection_type: function () {
142
                        return filters.selection_type || ""
143
                    },
144
                },
104
            },
145
            },
105
            cannot_search: false,
146
            cannot_search: false,
106
            show_table: false,
147
            show_table: build_url_params(filters).length ? true : false,
107
            local_title_count: null,
148
            local_title_count: null,
108
        }
149
        }
109
    },
150
    },
Lines 115-129 export default { Link Here
115
            )
156
            )
116
        },
157
        },
117
    },
158
    },
118
    beforeRouteEnter(to, from, next) {
119
        next(vm => {
120
            vm.build_datatable()
121
        })
122
    },
123
    methods: {
159
    methods: {
124
        show_title: function (title_id) {
160
        doShow: function (title, dt, event) {
161
            event.preventDefault()
125
            this.$router.push(
162
            this.$router.push(
126
                "/cgi-bin/koha/erm/eholdings/ebsco/titles/" + title_id
163
                "/cgi-bin/koha/erm/eholdings/ebsco/titles/" + title.title_id
127
            )
164
            )
128
        },
165
        },
129
        filter_table: async function () {
166
        filter_table: async function () {
Lines 136-148 export default { Link Here
136
                this.$router.push(new_route)
173
                this.$router.push(new_route)
137
                this.show_table = true
174
                this.show_table = true
138
                this.local_title_count = null
175
                this.local_title_count = null
139
                $("#" + this.table_id)
176
140
                    .DataTable()
177
                if (this.$refs.table) {
141
                    .draw()
178
                    this.$refs.table.redraw(
179
                        "/api/v1/erm/eholdings/ebsco/titles"
180
                    )
181
                }
142
                if (this.erm_providers.includes("local")) {
182
                if (this.erm_providers.includes("local")) {
143
                    const client = APIClient.erm
183
                    const client = APIClient.erm
144
184
145
                    const q = filters
185
                    const q = this.filters
146
                        ? {
186
                        ? {
147
                              ...(this.filters.publication_title
187
                              ...(this.filters.publication_title
148
                                  ? {
188
                                  ? {
Lines 172-341 export default { Link Here
172
                this.cannot_search = true
212
                this.cannot_search = true
173
            }
213
            }
174
        },
214
        },
175
        build_datatable: function () {
215
        getTableColumns: function () {
176
            let show_title = this.show_title
177
            let get_lib_from_av = this.get_lib_from_av
216
            let get_lib_from_av = this.get_lib_from_av
178
            if (!this.show_table) {
217
            let escape_str = this.escape_str
179
                this.show_table = build_url_params(this.filters).length
218
            return [
180
                    ? true
219
                {
181
                    : false
220
                    title: __("Title"),
182
            }
221
                    data: "me.publication_title",
183
            let filters = this.filters
222
                    searchable: false,
184
            let table_id = this.table_id
223
                    orderable: false,
185
224
                    render: function (data, type, row, meta) {
186
            window["vendors"] = this.vendors.map(e => {
225
                        let node =
187
                e["_id"] = e["id"]
226
                            '<a href="/cgi-bin/koha/erm/eholdings/ebsco/titles/' +
188
                e["_str"] = e["name"]
227
                            row.title_id +
189
                return e
228
                            '" class="show">' +
190
            })
229
                            escape_str(
191
            let vendors_map = this.vendors.reduce((map, e) => {
230
                                `${row.publication_title} (#${row.title_id})`
192
                map[e.id] = e
231
                            ) +
193
                return map
232
                            "</a>"
194
            }, {})
233
                        if (row.is_selected) {
195
            window["av_title_publication_types"] =
234
                            node +=
196
                this.av_title_publication_types.map(e => {
235
                                " " +
197
                    e["_id"] = e["value"]
236
                                '<i class="fa fa-check-square-o" style="color: green; float: right;" title="' +
198
                    e["_str"] = e["description"]
237
                                __("Is selected") +
199
                    return e
238
                                '" />'
200
                })
239
                        }
201
240
                        return node
202
            let additional_filters = {
241
                    },
203
                publication_title: function () {
204
                    return filters.publication_title || ""
205
                },
206
                publication_type: function () {
207
                    return filters.publication_type || ""
208
                },
242
                },
209
                selection_type: function () {
243
                {
210
                    return filters.selection_type || ""
244
                    title: __("Publisher name"),
245
                    data: "me.publisher_name",
246
                    searchable: false,
247
                    orderable: false,
248
                    render: function (data, type, row, meta) {
249
                        return escape_str(row.publisher_name)
250
                    },
211
                },
251
                },
212
            }
213
            $("#" + table_id).kohaTable(
214
                {
252
                {
215
                    ajax: {
253
                    title: __("Publication type"),
216
                        url: "/api/v1/erm/eholdings/ebsco/titles",
254
                    data: "publication_type",
255
                    searchable: false,
256
                    orderable: false,
257
                    render: function (data, type, row, meta) {
258
                        return escape_str(
259
                            get_lib_from_av(
260
                                "av_title_publication_types",
261
                                row.publication_type
262
                            )
263
                        )
217
                    },
264
                    },
218
                    ordering: false,
265
                },
219
                    dom: '<"top pager"<"table_entries"ilp>>tr<"bottom pager"ip>',
266
                {
220
                    aLengthMenu: [
267
                    title: __("Identifier"),
221
                        [10, 20, 50, 100],
268
                    data: "print_identifier:online_identifier",
222
                        [10, 20, 50, 100],
269
                    searchable: false,
223
                    ],
270
                    orderable: false,
224
                    deferLoading: true,
271
                    render: function (data, type, row, meta) {
225
                    autoWidth: false,
272
                        let print_identifier = row.print_identifier
226
                    columns: [
273
                        let online_identifier = row.online_identifier
227
                        {
274
                        return (
228
                            title: __("Title"),
275
                            (print_identifier
229
                            data: "me.publication_title",
276
                                ? escape_str(
230
                            searchable: false,
277
                                      _("ISBN (Print): %s").format(
231
                            orderable: false,
278
                                          print_identifier
232
                            render: function (data, type, row, meta) {
279
                                      )
233
                                // Rendering done in drawCallback
280
                                  )
234
                                return ""
281
                                : "") +
235
                            },
282
                            (online_identifier
236
                        },
283
                                ? escape_str(
237
                        {
284
                                      _("ISBN (Online): %s").format(
238
                            title: __("Publisher name"),
285
                                          online_identifier
239
                            data: "me.publisher_name",
286
                                      )
240
                            searchable: false,
287
                                  )
241
                            orderable: false,
288
                                : "")
242
                            render: function (data, type, row, meta) {
243
                                return escape_str(row.publisher_name)
244
                            },
245
                        },
246
                        {
247
                            title: __("Publication type"),
248
                            data: "publication_type",
249
                            searchable: false,
250
                            orderable: false,
251
                            render: function (data, type, row, meta) {
252
                                return escape_str(
253
                                    get_lib_from_av(
254
                                        "av_title_publication_types",
255
                                        row.publication_type
256
                                    )
257
                                )
258
                            },
259
                        },
260
                        {
261
                            title: __("Identifier"),
262
                            data: "print_identifier:online_identifier",
263
                            searchable: false,
264
                            orderable: false,
265
                            render: function (data, type, row, meta) {
266
                                let print_identifier = row.print_identifier
267
                                let online_identifier = row.online_identifier
268
                                return (
269
                                    (print_identifier
270
                                        ? escape_str(
271
                                              _("ISBN (Print): %s").format(
272
                                                  print_identifier
273
                                              )
274
                                          )
275
                                        : "") +
276
                                    (online_identifier
277
                                        ? escape_str(
278
                                              _("ISBN (Online): %s").format(
279
                                                  online_identifier
280
                                              )
281
                                          )
282
                                        : "")
283
                                )
284
                            },
285
                        },
286
                    ],
287
                    drawCallback: function (settings) {
288
                        var api = new $.fn.dataTable.Api(settings)
289
290
                        if (!api.rows({ search: "applied" }).count()) return
291
292
                        $.each(
293
                            $(this).find("tbody tr td:first-child"),
294
                            function (index, e) {
295
                                let tr = $(this).parent()
296
                                let row = api.row(tr).data()
297
                                if (!row) return // Happen if the table is empty
298
                                let n = createVNode(
299
                                    "a",
300
                                    {
301
                                        role: "button",
302
                                        onClick: e => {
303
                                            e.preventDefault()
304
                                            show_title(row.title_id)
305
                                        },
306
                                    },
307
                                    `${row.publication_title} (#${row.title_id})`
308
                                )
309
310
                                if (row.is_selected) {
311
                                    n = createVNode("span", {}, [
312
                                        n,
313
                                        " ",
314
                                        createVNode("i", {
315
                                            class: "fa fa-check-square-o",
316
                                            style: {
317
                                                color: "green",
318
                                                float: "right",
319
                                            },
320
                                            title: __("Is selected"),
321
                                        }),
322
                                    ])
323
                                }
324
                                render(n, e)
325
                            }
326
                        )
289
                        )
327
                    },
290
                    },
328
                },
291
                },
329
                null,
292
            ]
330
                0,
331
                additional_filters
332
            )
333
334
            if (filters.publication_title.length) {
335
                this.filter_table()
336
            }
337
        },
293
        },
338
    },
294
    },
295
    components: { KohaTable },
339
    name: "EHoldingsEBSCOTitlesList",
296
    name: "EHoldingsEBSCOTitlesList",
340
}
297
}
341
</script>
298
</script>
342
- 

Return to bug 33066