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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-23 / +38 lines)
Lines 1332-1342 Link Here
1332
        }
1332
        }
1333
1333
1334
        [% IF StaffDetailItemSelection %]
1334
        [% IF StaffDetailItemSelection %]
1335
            function itemSelectionBuildDeleteLink(div) {
1335
1336
                var itemnumbers = new Array();
1336
            let items_selection = {};
1337
                $("input[name='itemnumber'][type='checkbox']:checked", div).each(function() {
1337
            function itemSelectionBuildDeleteLink(tab_id) {
1338
                    itemnumbers.push($(this).val());
1338
                var itemnumbers = items_selection[tab_id];
1339
                });
1340
                if (itemnumbers.length > 0) {
1339
                if (itemnumbers.length > 0) {
1341
                    var url = '/cgi-bin/koha/tools/batchMod.pl?op=show&del=1';
1340
                    var url = '/cgi-bin/koha/tools/batchMod.pl?op=show&del=1';
1342
                    url += '&itemnumber=' + itemnumbers.join('&itemnumber=');
1341
                    url += '&itemnumber=' + itemnumbers.join('&itemnumber=');
Lines 1349-1359 Link Here
1349
                return true
1348
                return true
1350
            }
1349
            }
1351
1350
1352
            function itemSelectionBuildModifyLink(div) {
1351
            function itemSelectionBuildModifyLink(tab_id) {
1353
                var itemnumbers = new Array();
1352
                var itemnumbers = items_selection[tab_id];
1354
                $("input[name='itemnumber'][type='checkbox']:checked", div).each(function() {
1355
                    itemnumbers.push($(this).val());
1356
                });
1357
                if (itemnumbers.length > 0) {
1353
                if (itemnumbers.length > 0) {
1358
                    var url = '/cgi-bin/koha/tools/batchMod.pl?op=show';
1354
                    var url = '/cgi-bin/koha/tools/batchMod.pl?op=show';
1359
                    url += '&itemnumber=' + itemnumbers.join('&itemnumber=');
1355
                    url += '&itemnumber=' + itemnumbers.join('&itemnumber=');
Lines 1366-1375 Link Here
1366
                return true;
1362
                return true;
1367
            }
1363
            }
1368
1364
1369
            function itemSelectionBuildActionLinks(tab) {
1365
            function itemSelectionBuildActionLinks(tab_id) {
1370
                var div = $("#" + tab);
1366
                var delete_link_ok = itemSelectionBuildDeleteLink(tab_id);
1371
                var delete_link_ok = itemSelectionBuildDeleteLink(div);
1367
                var modify_link_ok = itemSelectionBuildModifyLink(tab_id);
1372
                var modify_link_ok = itemSelectionBuildModifyLink(div);
1368
                var div = $("#" + tab_id);
1373
                if (modify_link_ok || delete_link_ok) {
1369
                if (modify_link_ok || delete_link_ok) {
1374
                    $('.itemselection_actions', div).show();
1370
                    $('.itemselection_actions', div).show();
1375
                } else {
1371
                } else {
Lines 1378-1387 Link Here
1378
            }
1374
            }
1379
1375
1380
            $(document).ready(function() {
1376
            $(document).ready(function() {
1381
                $('table.items_table').each(function() {
1382
                    var div = $(this).parent().attr("id");
1383
                    itemSelectionBuildActionLinks(div);
1384
                });
1385
1377
1386
                $(".SelectAll").on("click",function(e){
1378
                $(".SelectAll").on("click",function(e){
1387
                    e.preventDefault();
1379
                    e.preventDefault();
Lines 2220-2225 Link Here
2220
            [% IF hidden_count %]
2212
            [% IF hidden_count %]
2221
                default_filters.lost_status = "0";
2213
                default_filters.lost_status = "0";
2222
            [% END %]
2214
            [% END %]
2215
            if ( !items_selection.hasOwnProperty(tab_id) ){
2216
                items_selection[tab_id] = [];
2217
            }
2223
            var items_table = $("#" + tab_id + '_table').kohaTable({
2218
            var items_table = $("#" + tab_id + '_table').kohaTable({
2224
                ajax: { url: item_table_url },
2219
                ajax: { url: item_table_url },
2225
                order: [[ 0, "asc" ]],
2220
                order: [[ 0, "asc" ]],
Lines 2234-2240 Link Here
2234
                    orderable: false,
2229
                    orderable: false,
2235
                    render: function (data, type, row, meta) {
2230
                    render: function (data, type, row, meta) {
2236
                        if ( can_edit_items_from[row.holding_library_id] ){
2231
                        if ( can_edit_items_from[row.holding_library_id] ){
2237
                            return '<input type="checkbox" value="%s" name="itemnumber" />'.format(row.item_id);
2232
                            if ( items_selection[tab_id].includes(row.item_id) ) {
2233
                                return '<input type="checkbox" value="%s" name="itemnumber" checked />'.format(row.item_id);
2234
                            } else {
2235
                                return '<input type="checkbox" value="%s" name="itemnumber" />'.format(row.item_id);
2236
                            }
2238
                        } else {
2237
                        } else {
2239
                            return ''
2238
                            return ''
2240
                        }
2239
                        }
Lines 2686-2696 Link Here
2686
                    });
2685
                    });
2687
                    itemSelectionBuildActionLinks(tab_id);
2686
                    itemSelectionBuildActionLinks(tab_id);
2688
                },
2687
                },
2688
                [% IF StaffDetailItemSelection %]
2689
                drawCallback: function(settings){
2689
                drawCallback: function(settings){
2690
                    $(this).find("td:first input[name='itemnumber'][type='checkbox']").on("change", function(){
2690
                    var api = new $.fn.dataTable.Api(settings)
2691
                        itemSelectionBuildActionLinks(tab_id);
2691
                    $.each(
2692
                    });
2692
                        $(this).find("tbody tr td:first-child"),
2693
                        function (index, e) {
2694
                            let tr = $(this).parent()
2695
                            let row = api.row(tr).data()
2696
                            if (!row) return // Happen if the table is empty
2697
                            $(this).find("input[name='itemnumber'][type='checkbox']").on("change", function(){
2698
                                let itemnumber = parseInt($(this).val());
2699
                                if( $(this).prop("checked") ){
2700
                                    items_selection[tab_id].push(itemnumber);
2701
                                } else {
2702
                                    items_selection[tab_id] = items_selection[tab_id].filter( id => id != itemnumber );
2703
                                }
2704
                                itemSelectionBuildActionLinks(tab_id);
2705
                            });
2706
                        }
2707
                    );
2693
                },
2708
                },
2709
                [% END %]
2694
                ...dt_options,
2710
                ...dt_options,
2695
            },
2711
            },
2696
            items_table_settings[tab_id],
2712
            items_table_settings[tab_id],
2697
- 

Return to bug 33568