Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds components for a selectable table #1468

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
sabieber marked this conversation as resolved.
Show resolved Hide resolved
// 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');
sabieber marked this conversation as resolved.
Show resolved Hide resolved
if (_checkbox.checked) {
_tr.style.backgroundColor = 'lightgray';
} else {
_tr.style.backgroundColor = '';
sabieber marked this conversation as resolved.
Show resolved Hide resolved
}
}

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 => {
sabieber marked this conversation as resolved.
Show resolved Hide resolved
_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"/>

mko-sci marked this conversation as resolved.
Show resolved Hide resolved

<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