Implement single room selection for commands view

async-tree
Daniel García Moreno 2022-09-13 13:02:36 +02:00 committed by Javier Sánchez Parra
parent efe9731753
commit ea18207998
2 changed files with 26 additions and 4 deletions

View File

@ -85,6 +85,26 @@ function checkChildrenCheckboxes() {
checkboxes.on('change', function () {
const checked = this.checked
const children = $('input:checkbox', this.parentNode).not(this)
if (checked) {
// Only for rooms, deselect other rooms
if (this.name === 'scope-room') {
const others = $('input:checkbox[form|="scopesForm"]').not(this);
others.prop('checked', false);
others.trigger('change');
} else {
// Look for room, deselect all other rooms
const selectedRoom = $(this).parent().parent().parent().children('[name="scope-room"]');
const others = $('input:checkbox[name="scope-room"]').not(selectedRoom);
others.prop('checked', false).prop('indeterminate', false);
others.each(function() {
const checks = $(this).parent().find('input:checkbox').prop('checked', false);
checks.trigger('change');
});
others.trigger('change');
}
}
children.each(function () {
this.checked = checked;
storeCheckboxStatus(this);
@ -272,7 +292,7 @@ function limitCheckboxes() {
checkboxes.on('change', function () {
const checked = this;
checkboxes.filter((i, c) => c !== checked).prop('checked', false);
checkboxes.each(function() {
checkboxes.not('[name="scope-server"]').each(function() {
showSelectedClient(this);
});
checkScopeServer();

View File

@ -1,7 +1,7 @@
{% macro scopes_tree_collapse(scopes, state='', selection_mode='scopes') -%}
<ul id="scopes" class="nav flex-column nav-pills">
{{ scopes_tree_collapse_level(scopes["scope"], "", state) }}
{{ scopes_tree_collapse_level(scopes["scope"], "", state, selection_mode) }}
</ul>
<script>
// Launch the javascript on document ready, so all the global functions exists
@ -24,7 +24,7 @@
{% endmacro %}
{% macro scopes_tree_collapse_level(scopes, parent_id, state) -%}
{% macro scopes_tree_collapse_level(scopes, parent_id, state, selection_mode) -%}
{% for scope in scopes %}
<li id="{{ scope["name"]|replace(".", "_")|replace(" ", "_") }}_{{ scope["id"] }}" class="nav-item">
{% if scope["type"] == "server" %}
@ -33,11 +33,13 @@
{% if scope.get("selected", False) %}checked{% endif %}
name="scope-server" hidden/>
{% elif scope["type"] == "center" %}
{% if selection_mode != "commands" %}
<input class="form-check-input" type="checkbox" form="scopesForm"
value="{{ scope["id"] }}"
{% if state %}style="filter: grayscale(100%);" onclick="return false;"{% endif %}
{% if scope.get("selected", False) %}checked{% endif %}
name="scope-center" />
{% endif %}
{% elif scope["type"] == "room" %}
<input class="form-check-input" type="checkbox" form="scopesForm"
value="{{ scope["id"] }}"
@ -65,7 +67,7 @@
</a>
{% if scope["scope"] %}
<ul class="nav flex-column collapse level{{i}}" id="scope{{parent_id ~ "-" ~ loop.index}}">
{{ scopes_tree_collapse_level(scope["scope"], parent_id ~ "-" ~ loop.index, state) }}
{{ scopes_tree_collapse_level(scope["scope"], parent_id ~ "-" ~ loop.index, state, selection_mode) }}
</ul>
{% endif %}
</li>