Jump to content
thirty bees forum
  • 0

in borders I need help for admin.js


Pedalman

Question

I had in TB 1.4 an enhancement for me in the admin.js code that allowed me for selected orders in bo orders list to do a bulk action like downloading pdf.

My problem is that I cannot get it working with tb 1.6x. Even with the help of AI it won't work 🙂 

Line 875 admin.js

  if (window['kpis']) {
    $.each(window['kpis'], function(id, kpi) {
      if (kpi.initRefresh) {
        refresh_kpi(id, kpi);
      }
    });
  }
});

old V1.4 additional code

  if ($('.kpi-container').length) {
    refresh_kpis();
  }
  $('body.adminorders .bulk-actions ul').append('<li><a href="#" id="downloadBulkSingle"><i class="icon-download"></i>&nbsp;Bulk Rechnungsdownload</a></li>');
  $('a#downloadBulkSingle').click(function(e){
	  e.preventDefault();
	  $('[name="orderBox[]"]:checked').each((i,e)=>
		$(e).parents('tr').find('a[href*="generateInvoicePDF"]').each((a,c) => c.click()));
  });
});

ChatGPT thinks this would be proper....

In this version:

  • The code checks if #downloadBulkSingle already exists to avoid duplication.
  • It uses on for the click event, making it more flexible if the link is reloaded dynamically.
if (window['kpis']) {
    $.each(window['kpis'], function(id, kpi) {
        if (kpi.initRefresh) {
            refresh_kpi(id, kpi);
        }
    });

    if (!$('a#downloadBulkSingle').length) {  // Check if the link already exists
        $('body.adminorders .bulk-actions ul').append(
            '<li><a href="#" id="downloadBulkSingle"><i class="icon-download"></i>&nbsp;Bulk Rechnungsdownload</a></li>'
        );

        $('body').on('click', 'a#downloadBulkSingle', function(e) {
            e.preventDefault();
            $('[name="orderBox[]"]:checked').each((i, e) => {
                $(e).closest('tr').find('a[href*="generateInvoicePDF"]').each((a, c) => c.click());
            });
        });
    }
}

 

Would be nice if someone could make this work with 1.6 again.

thx

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

The code works for me.

Browser doesn't like it much, though. When you select multiple orders with invoices, and then click on multi-download, browser opens multiple tabs for every invoice. This is not a normal behaviour, and browser quite correctly treat this as unwanted popups. I had to click on 'always allow popup on this site' to make this functionaltiy work.

Note: please remove this code from admin.js -- that is a core file, and should not be modified. 

The best way to implement these changes is using custom module.

I've quickly prepared a very simple module that adds custom js file to all admin pages:

backofficejs-v1.0.0.zip

Just install it, and then modify file /modules/backofficejs/views/js/backoffice.js in order to add your code. 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...