Skip to content

Commit

Permalink
Adds components for a selectable table
Browse files Browse the repository at this point in the history
Fixes: OX-11093
  • Loading branch information
mko-sci committed Oct 22, 2024
1 parent ceff24b commit 5f70b1f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
sirius.ready(function () {
document.querySelectorAll('.select-all-visible-table-rows-checkbox-js').forEach(function (_selectAllCheckbox) {
const _table = _selectAllCheckbox.closest('table');
// Handle changing the state of the select-all checkbox found in the table head row
_selectAllCheckbox.addEventListener('change', function () {
_table.querySelectorAll('.select-table-row-checkbox-js').forEach(_checkbox => {
_checkbox.checked = _selectAllCheckbox.checked;
toggleRowSelection(_checkbox);
});
});

_table.querySelectorAll('.select-table-row-checkbox-js').forEach(function (_checkbox) {
// Handle changing the state of the select-all checkbox found in the table head row
// When all rows are selected, the select-all checkbox should be checked as well
_checkbox.addEventListener('change', function () {
toggleRowSelection(_checkbox);
changeSelectAllCheckboxState(_table);
});

const _tr = _checkbox.closest('tr');
// Handle clicks on the row for convenience
_tr.addEventListener('click', function (event) {
if (event.target.tagName.toLowerCase() !== 'input' &&
event.target.tagName.toLowerCase() !== 'a' &&
event.target.tagName.toLowerCase() !== 'button') {
_checkbox.checked = !_checkbox.checked;
_checkbox.dispatchEvent(new Event('change'));
}
});

});
});

function toggleRowSelection(_checkbox) {
const _tr = _checkbox.closest('tr');
if (_checkbox.checked) {
_tr.style.backgroundColor = 'lightgray';
} else {
_tr.style.backgroundColor = '';
}
}

function changeSelectAllCheckboxState(_table) {
const allChecked = _table.querySelectorAll('.select-table-row-checkbox-js:checked').length === _table.querySelectorAll('.select-table-row-checkbox-js').length;
_table.querySelectorAll('.select-all-visible-table-rows-checkbox-js').forEach(_node => {
_node.checked = allChecked;
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ ___invoke("/assets/tycho/scripts/history.js.pasta")
___invoke("/assets/tycho/scripts/messages.js.pasta")
___invoke("/assets/tycho/scripts/colors.js.pasta")
___invoke("/assets/tycho/scripts/charts.js.pasta")
___invoke("/assets/tycho/scripts/selectableTable.js.pasta")

<i:extensions target="tycho-script" point="tycho-script" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<i:pragma name="description">
Adds a table header row to a selectable table. The row will contain a checkbox in the first column which can be used to select or deselect all rows.
</i:pragma>

<thead>
<tr>
<th class="align-top">
<input class="cursor-pointer select-all-visible-table-rows-checkbox-js"
type="checkbox"
title="@i18n('selectableTable.row.selection.all')"/>
</th>
<i:render name="body"/>
</tr>
</thead>
19 changes: 19 additions & 0 deletions src/main/resources/default/taglib/t/selectableTableRow.html.pasta
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<i:arg name="entityId" type="String" description="The id of the entity to which this table row is associated with"/>


<i:pragma name="description">
Renders a table row which can be selected by the user. The row will have a checkbox in the first column.
The checkbox visualizes the selection state of the row and can be used to select or deselect the row.
The table row can also be selected by simply clicking on it.
Note: Links and buttons in the row will not trigger the selection of the row.
</i:pragma>

<tr class="cursor-pointer">
<td>
<input class="cursor-pointer select-table-row-checkbox-js"
type="checkbox"
title="@i18n('selectableTable.row.selection')"
data-entity-id="@entityId"/>
</td>
<i:render name="body"/>
</tr>
2 changes: 2 additions & 0 deletions src/main/resources/web_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ fileUpload.URL = URL
fileUpload.specifyURL = URL angeben
footer-menu.html.help = Hilfesystem
help = Hilfe
selectableTable.row.selection = Aus-/Abwählen
selectableTable.row.selection.all = Alle aus-/abwählen
table.html.empty = Keine Inhalte gefunden
template.html.additionalActions = Weitere Aktionen
template.html.confirmHeader = Sind Sie sicher?
Expand Down

0 comments on commit 5f70b1f

Please sign in to comment.