|
4 | 4 | let add_to_btn_wrapper = add_to_btn.parentElement; |
5 | 5 |
|
6 | 6 | let handle_button_display = function () { |
7 | | - let checkedCheckboxes = document.querySelectorAll('main input[type="checkbox"]:checked'); |
| 7 | + let checkedCheckboxes = document.querySelectorAll('#object-list-table input[type="checkbox"]:checked'); |
8 | 8 | if (checkedCheckboxes.length >= 1) { |
9 | 9 | add_to_btn.classList.remove('disabled'); |
10 | 10 | add_to_btn_wrapper.setAttribute('data-bs-original-title', ''); |
|
15 | 15 | }; |
16 | 16 |
|
17 | 17 | // Adding change event listener to all checkboxes |
18 | | - document.querySelectorAll('main input[type="checkbox"]').forEach(function(checkbox) { |
| 18 | + document.querySelectorAll('#object-list-table input[type="checkbox"]').forEach(function(checkbox) { |
19 | 19 | checkbox.addEventListener('change', handle_button_display); |
20 | 20 | }); |
21 | 21 |
|
|
27 | 27 | handle_button_display(); |
28 | 28 | }); |
29 | 29 |
|
30 | | - $('#add-to-product-modal, #add-to-component-modal').on('show.bs.modal', function (event) { |
31 | | - // Do not include the select-all as its value is not an id we want to keep |
32 | | - let checked = $('main input[type="checkbox"]:checked').not('#checkbox-select-all'); |
| 30 | + document.querySelectorAll('#add-to-product-modal, #add-to-component-modal').forEach(function(modal) { |
| 31 | + modal.addEventListener('show.bs.modal', function (event) { |
| 32 | + // Do not include the select-all as its value is not an id we want to keep |
| 33 | + let checked = Array.from(document.querySelectorAll('#object-list-table input[type="checkbox"]:checked')) |
| 34 | + .filter(checkbox => checkbox.id !== 'checkbox-select-all'); |
33 | 35 |
|
34 | | - if (checked.length < 1) { |
35 | | - event.preventDefault(); |
36 | | - return false; |
37 | | - } |
| 36 | + if (checked.length < 1) { |
| 37 | + event.preventDefault(); |
| 38 | + return false; |
| 39 | + } |
38 | 40 |
|
39 | | - let ids_input = $(this).find('#id_ids'); |
40 | | - let object_repr_list = $(this).find('#object-repe-list'); |
| 41 | + let ids_input = modal.querySelector('#id_ids'); |
| 42 | + let object_repr_list = modal.querySelector('#object-repr-list'); |
41 | 43 |
|
42 | | - if (ids_input) { |
43 | | - let selected_ids = []; |
44 | | - object_repr_list.html(''); |
| 44 | + if (ids_input) { |
| 45 | + let selected_ids = []; |
| 46 | + object_repr_list.innerHTML = ''; |
45 | 47 |
|
46 | | - checked.each(function() { |
47 | | - selected_ids.push(this.value); |
48 | | - $('<li/>').text($(this).data('object-repr')).appendTo(object_repr_list); |
49 | | - }); |
| 48 | + checked.forEach(function(checkbox) { |
| 49 | + selected_ids.push(checkbox.value); |
| 50 | + let li = document.createElement('li'); |
| 51 | + li.textContent = checkbox.dataset.objectRepr; |
| 52 | + object_repr_list.appendChild(li); |
| 53 | + }); |
50 | 54 |
|
51 | | - ids_input.val(selected_ids); |
| 55 | + ids_input.value = selected_ids.join(','); |
52 | 56 |
|
53 | | - let new_component_link = $('#new-component-link'); |
54 | | - if (new_component_link) { |
55 | | - let new_component_url = new_component_link.data('add-url') + '?package_ids=' + selected_ids.join(); |
56 | | - new_component_link.attr('href', new_component_url); |
| 57 | + let new_component_link = document.getElementById('new-component-link'); |
| 58 | + if (new_component_link) { |
| 59 | + let new_component_url = new_component_link.dataset.addUrl + '?package_ids=' + selected_ids.join(','); |
| 60 | + new_component_link.setAttribute('href', new_component_url); |
| 61 | + } |
57 | 62 | } |
58 | | - } |
| 63 | + }); |
59 | 64 | }); |
60 | 65 |
|
61 | 66 | // Select all forms with id starting with "add-to-" |
|
0 commit comments