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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt (-169 / +167 lines)
Lines 182-190 Link Here
182
        const patron_id = "[% patron.borrowernumber | html %]";
182
        const patron_id = "[% patron.borrowernumber | html %]";
183
    </script>
183
    </script>
184
    <script>
184
    <script>
185
        $(document).ready(function() {
185
        $(document).ready(function () {
186
            let item_type_column = table_settings.columns.find(c => c.columnname == 'itemtype');
186
            let item_type_column = table_settings.columns.find(c => c.columnname == "itemtype");
187
            if ( !show_itemtype_column ) {
187
            if (!show_itemtype_column) {
188
                item_type_column.is_hidden = 1;
188
                item_type_column.is_hidden = 1;
189
                item_type_column.cannot_be_toggled = 1;
189
                item_type_column.cannot_be_toggled = 1;
190
            } else {
190
            } else {
Lines 194-401 Link Here
194
194
195
            let current_holds_table = build_holds_table("#table_holdshistory");
195
            let current_holds_table = build_holds_table("#table_holdshistory");
196
            let old_holds_table = build_holds_table("#table_oldholdshistory", 1);
196
            let old_holds_table = build_holds_table("#table_oldholdshistory", 1);
197
            function build_holds_table(table_id, old){
197
            function build_holds_table(table_id, old) {
198
                let additional_filters = {
198
                let additional_filters = {
199
                    "-and": function(){
199
                    "-and": function () {
200
                        let statuses = [];
200
                        let statuses = [];
201
                        let include_cancelled = false;
201
                        let include_cancelled = false;
202
                        if ( table_id == '#table_holdshistory' ) {
202
                        if (table_id == "#table_holdshistory") {
203
                            if ( $("#current_pending_filter").is(":checked") ) {
203
                            if ($("#current_pending_filter").is(":checked")) {
204
                                statuses.push(null);
204
                                statuses.push(null);
205
                            }
205
                            }
206
                            if ( $("#current_waiting_filter").is(":checked") ) {
206
                            if ($("#current_waiting_filter").is(":checked")) {
207
                                statuses.push("W");
207
                                statuses.push("W");
208
                            }
208
                            }
209
                            if ( $("#current_processing_filter").is(":checked") ) {
209
                            if ($("#current_processing_filter").is(":checked")) {
210
                                statuses.push("P");
210
                                statuses.push("P");
211
                            }
211
                            }
212
                            if ( $("#current_transit_filter").is(":checked") ) {
212
                            if ($("#current_transit_filter").is(":checked")) {
213
                                statuses.push("T");
213
                                statuses.push("T");
214
                            }
214
                            }
215
                        } else {
215
                        } else {
216
                            if ( $("#old_fulfilled_filter").is(":checked") ) {
216
                            if ($("#old_fulfilled_filter").is(":checked")) {
217
                                statuses.push("F");
217
                                statuses.push("F");
218
                            }
218
                            }
219
                            if ( $("#old_cancelled_filter").is(":checked") ) {
219
                            if ($("#old_cancelled_filter").is(":checked")) {
220
                                include_cancelled = true;
220
                                include_cancelled = true;
221
                            }
221
                            }
222
                        }
222
                        }
223
                        if ( include_cancelled ) {
223
                        if (include_cancelled) {
224
                            return [{status: statuses}, { cancellation_date: {"<": new Date().toISOString() } } ]; // cancellation_date cannot be in the future. Would be better a 'not null' here however.
224
                            return [{ status: statuses }, { cancellation_date: { "<": new Date().toISOString() } }]; // cancellation_date cannot be in the future. Would be better a 'not null' here however.
225
                        } else {
225
                        } else {
226
                            return [{status: statuses}];
226
                            return [{ status: statuses }];
227
                        }
227
                        }
228
                    },
228
                    },
229
230
                };
229
                };
231
230
232
                let table_url = `/api/v1/patrons/${patron_id}/holds`;
231
                let table_url = `/api/v1/patrons/${patron_id}/holds`;
233
                let table_embeds = ['+strings', 'biblio', 'item', 'pickup_library'];
232
                let table_embeds = ["+strings", "biblio", "item", "pickup_library"];
234
                if (old){
233
                if (old) {
235
                    table_url += '?old=1';
234
                    table_url += "?old=1";
236
                    table_embeds.push('deleted_biblio');
235
                    table_embeds.push("deleted_biblio");
237
                }
236
                }
238
                return $(table_id).kohaTable({
237
                return $(table_id).kohaTable(
239
                    ajax: {
238
                    {
240
                        url: table_url,
239
                        ajax: {
241
                    },
240
                            url: table_url,
242
                    order: [],
243
                    embed: table_embeds,
244
                    columns: [
245
                        {
246
                            data: "biblio.title:biblio.subtitle:biblio.medium",
247
                            searchable: true,
248
                            orderable: true,
249
                            render: function (data, type, row, meta) {
250
                                if( row.biblio ){
251
                                    return $biblio_to_html(row.biblio, { link: 1 });
252
                                } else {
253
                                    return $biblio_to_html(row.deleted_biblio, { link: 0, deleted: 1 });
254
                                }
255
                            }
256
                        },
257
                        {
258
                            data: "biblio.author",
259
                            searchable: true,
260
                            orderable: true,
261
                            render: function (data, type, row, meta) {
262
                                let biblio = row.biblio ? row.biblio : row.deleted_biblio;
263
                                return biblio ? biblio.author : "";
264
                            }
265
                        },
266
                        {
267
                            data: "item.external_id",
268
                            searchable: true,
269
                            orderable: true,
270
                            render: function (data, type, row, meta) {
271
                                return row.item ? row.item.external_id : "";
272
                            }
273
                        },
241
                        },
274
                        {
242
                        order: [],
275
                            data: "item.callnumber",
243
                        embed: table_embeds,
276
                            searchable: true,
244
                        columns: [
277
                            orderable: true,
245
                            {
278
                            render: function (data, type, row, meta) {
246
                                data: "biblio.title:biblio.subtitle:biblio.medium",
279
                                return row.item ? row.item.callnumber: "";
247
                                searchable: true,
280
                            }
248
                                orderable: true,
281
                        },
249
                                render: function (data, type, row, meta) {
282
                        {
250
                                    if (row.biblio) {
283
                            data: "me.pickup_library_id",
251
                                        return $biblio_to_html(row.biblio, { link: 1 });
284
                            datatype: "coded_value:library",
285
                            dataFilter: "libraries",
286
                            searchable: true,
287
                            orderable: true,
288
                            render: function (data, type, row, meta) {
289
                                return escape_str(row._strings.pickup_library_id ? row._strings.pickup_library_id.str : row.pickup_library_id);
290
                            }
291
                        },
292
                        {
293
                            data: "hold_date",
294
                            type: "date",
295
                            searchable: true,
296
                            orderable: true,
297
                            render: function (data, type, row, meta) {
298
                                return $date(row.hold_date);
299
                            }
300
                        },
301
                        {
302
                            data: "expiration_date",
303
                            type: "date",
304
                            searchable: true,
305
                            orderable: true,
306
                            render: function (data, type, row, meta) {
307
                                return $date(row.expiration_date)
308
                            }
309
                        },
310
                        {
311
                            data: "waiting_date",
312
                            type: "date",
313
                            searchable: true,
314
                            orderable: true,
315
                            render: function (data, type, row, meta) {
316
                                return $date(row.waiting_date)
317
                            }
318
                        },
319
                        {
320
                            data: "cancellation_date",
321
                            type: "date",
322
                            searchable: true,
323
                            orderable: true,
324
                            render: function (data, type, row, meta) {
325
                                return $date(row.cancellation_date)
326
                            }
327
                        },
328
                        ...(show_itemtype_column?
329
                        [{
330
                            data: "item_type_id",
331
                            datatype: "coded_value:item_type",
332
                            dataFilter: "item_types",
333
                            searchable: true,
334
                            orderable: true,
335
                            render: function (data, type, row, meta) {
336
                                [% IF Koha.Preference('AllowHoldItemTypeSelection') %]
337
                                    if ( row.item_type_id ) {
338
                                        return row._strings.item_type_id ? row._strings.item_type_id.str : row.item_type_id;
339
                                    } else {
252
                                    } else {
340
                                        return _("Any item type");
253
                                        return $biblio_to_html(row.deleted_biblio, { link: 0, deleted: 1 });
341
                                    }
254
                                    }
342
                                [% ELSE %]
255
                                },
343
                                    return "";
256
                            },
344
                                [% END %]
257
                            {
345
                            }
258
                                data: "biblio.author",
346
                        }]:[]),
259
                                searchable: true,
347
                        {
260
                                orderable: true,
348
                            data: "status",
261
                                render: function (data, type, row, meta) {
349
                            searchable: false,
262
                                    let biblio = row.biblio ? row.biblio : row.deleted_biblio;
350
                            orderable: true,
263
                                    return biblio ? biblio.author : "";
351
                            render: function (data, type, row, meta) {
264
                                },
352
                                if ( row.status == 'F' ) {
265
                            },
353
                                    return _("Fulfilled");
266
                            {
354
                                } else if (row.cancellation_date) {
267
                                data: "item.external_id",
355
                                    let r = _("Cancelled");
268
                                searchable: true,
356
                                    if (row.cancellation_reason){
269
                                orderable: true,
357
                                        r += " (%s)".format(row._strings.cancellation_reason.str);
270
                                render: function (data, type, row, meta) {
271
                                    return row.item ? row.item.external_id : "";
272
                                },
273
                            },
274
                            {
275
                                data: "item.callnumber",
276
                                searchable: true,
277
                                orderable: true,
278
                                render: function (data, type, row, meta) {
279
                                    return row.item ? row.item.callnumber : "";
280
                                },
281
                            },
282
                            {
283
                                data: "me.pickup_library_id",
284
                                datatype: "coded_value:library",
285
                                dataFilter: "libraries",
286
                                searchable: true,
287
                                orderable: true,
288
                                render: function (data, type, row, meta) {
289
                                    return escape_str(row._strings.pickup_library_id ? row._strings.pickup_library_id.str : row.pickup_library_id);
290
                                },
291
                            },
292
                            {
293
                                data: "hold_date",
294
                                type: "date",
295
                                searchable: true,
296
                                orderable: true,
297
                                render: function (data, type, row, meta) {
298
                                    return $date(row.hold_date);
299
                                },
300
                            },
301
                            {
302
                                data: "expiration_date",
303
                                type: "date",
304
                                searchable: true,
305
                                orderable: true,
306
                                render: function (data, type, row, meta) {
307
                                    return $date(row.expiration_date);
308
                                },
309
                            },
310
                            {
311
                                data: "waiting_date",
312
                                type: "date",
313
                                searchable: true,
314
                                orderable: true,
315
                                render: function (data, type, row, meta) {
316
                                    return $date(row.waiting_date);
317
                                },
318
                            },
319
                            {
320
                                data: "cancellation_date",
321
                                type: "date",
322
                                searchable: true,
323
                                orderable: true,
324
                                render: function (data, type, row, meta) {
325
                                    return $date(row.cancellation_date);
326
                                },
327
                            },
328
                            {
329
                                data: "item_type_id",
330
                                datatype: "coded_value:item_type",
331
                                dataFilter: "item_types",
332
                                searchable: true,
333
                                orderable: true,
334
                                render: function (data, type, row, meta) {
335
                                    if (show_itemtype_column) {
336
                                        if (row.item_type_id) {
337
                                            return row._strings.item_type_id ? row._strings.item_type_id.str : row.item_type_id;
338
                                        } else {
339
                                            return _("Any item type");
340
                                        }
341
                                    } else {
342
                                        return "";
343
                                    }
344
                                },
345
                            },
346
                            {
347
                                data: "status",
348
                                searchable: false,
349
                                orderable: true,
350
                                render: function (data, type, row, meta) {
351
                                    if (row.status == "F") {
352
                                        return _("Fulfilled");
353
                                    } else if (row.cancellation_date) {
354
                                        let r = _("Cancelled");
355
                                        if (row.cancellation_reason) {
356
                                            r += " (%s)".format(row._strings.cancellation_reason.str);
357
                                        }
358
                                        return r;
359
                                    } else if (row.status == "W") {
360
                                        return _("Waiting");
361
                                    } else if (row.status == "P") {
362
                                        return _("Processing");
363
                                    } else if (row.status == "T") {
364
                                        return _("In transit");
358
                                    }
365
                                    }
359
                                    return r;
360
                                } else if (row.status == 'W') {
361
                                    return _("Waiting");
362
                                } else if (row.status == 'P') {
363
                                    return _("Processing");
364
                                } else if (row.status == 'T') {
365
                                    return _("In transit");
366
                                }
367
366
368
                                return _("Pending");
367
                                    return _("Pending");
369
                            }
368
                                },
370
                        },
369
                            },
371
                        {
370
                            {
372
                            data: "notes",
371
                                data: "notes",
373
                            searchable: true,
372
                                searchable: true,
374
                            orderable: true,
373
                                orderable: true,
375
                            render: function (data, type, row, meta) {
374
                                render: function (data, type, row, meta) {
376
                                return row.notes;
375
                                    return row.notes;
377
                            }
376
                                },
378
                        },
377
                            },
379
                    ],
378
                        ],
380
                    bKohaColumnsUseNames: true,
379
                        bKohaColumnsUseNames: true,
381
                },
380
                    },
382
                table_settings,
381
                    table_settings,
383
                true,
382
                    true,
384
                additional_filters,
383
                    additional_filters,
385
                filters_options,
384
                    filters_options
386
                );
385
                );
387
            }
386
            }
388
            $("#current_holds_filters :checkbox, #old_holds_filters :checkbox").on("change", function(e){
387
            $("#current_holds_filters :checkbox, #old_holds_filters :checkbox").on("change", function (e) {
389
                e.preventDefault();
388
                e.preventDefault();
390
                let container = $(this).closest("div");
389
                let container = $(this).closest("div");
391
                if ( $(this).hasClass("show_all") ) {
390
                if ($(this).hasClass("show_all")) {
392
                    if ( $(this).is(":checked") ) {
391
                    if ($(this).is(":checked")) {
393
                        container.find(":checkbox").prop("checked", true);
392
                        container.find(":checkbox").prop("checked", true);
394
                    }
393
                    }
395
                } else if ( $(this).not(":checked") ) {
394
                } else if ($(this).not(":checked")) {
396
                    container.find(".show_all").prop("checked", false);
395
                    container.find(".show_all").prop("checked", false);
397
                }
396
                }
398
                let table_dt = $("#"+container.data("table-id")).DataTable();
397
                let table_dt = $("#" + container.data("table-id")).DataTable();
399
                table_dt.draw();
398
                table_dt.draw();
400
            });
399
            });
401
        });
400
        });
402
- 

Return to bug 41572