mirror of https://git.48k.eu/ogcp
Show selected clients in container block
On scopes and commands views, draw clients as users selects them in the scopes tree. Trigger client drawing on two events: 1."change" event, occurs when the user clicks a client checkbox. This event is standard [1]. 2. "show-client" event, fires when ogcp get selected clients from localStorage and when an user checks a parent checkbox. This event is custom. Dot characters (".") in clients names are replaced by underscore("_") when used as id to avoid errors. 1. https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_eventmulti-ogserver
parent
1d68e2619a
commit
886e6c7b67
|
@ -2,6 +2,34 @@ const Endpoint = '/scopes/status';
|
|||
const Interval = 1000;
|
||||
let updateTimeoutId = null;
|
||||
|
||||
function showSelectedClient(client_checkbox) {
|
||||
const container = $('#selected-clients');
|
||||
const pill_id = 'pill-' + client_checkbox.name.replaceAll('.', '_');
|
||||
|
||||
if (client_checkbox.checked) {
|
||||
if (!($('#' + pill_id).length))
|
||||
$(container).append('<div class="badge badge-pill badge-light" ' +
|
||||
'id="'+ pill_id + '">' + client_checkbox.name +
|
||||
'<br>' + client_checkbox.value + '</div>');
|
||||
return;
|
||||
}
|
||||
|
||||
$('#' + pill_id).remove();
|
||||
}
|
||||
|
||||
function showSelectedClientsOnEvents() {
|
||||
const checkboxes = $('input:checkbox[form|="scopesForm"]');
|
||||
const container = $('#selected-clients');
|
||||
|
||||
const client_checkboxes = checkboxes.filter(function () {
|
||||
return $(this).siblings().length == "1";
|
||||
});
|
||||
|
||||
client_checkboxes.on('change show-client', function () {
|
||||
showSelectedClient(this);
|
||||
});
|
||||
}
|
||||
|
||||
function storeCheckboxStatus(checkbox) {
|
||||
if (checkbox.checked)
|
||||
localStorage.setItem(checkbox.name, "check");
|
||||
|
@ -18,6 +46,7 @@ function checkChildrenCheckboxes() {
|
|||
children.each(function () {
|
||||
this.checked = checked;
|
||||
storeCheckboxStatus(this);
|
||||
$(this).trigger('show-client');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -32,6 +61,7 @@ function keepSelectedClients() {
|
|||
checkboxes.each(function () {
|
||||
if (localStorage.getItem(this.name) == 'check') {
|
||||
this.checked = true;
|
||||
$(this).trigger('show-client');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -96,3 +96,6 @@
|
|||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ macros.selected_clients() }}
|
||||
{% endblock %}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
// in the scope
|
||||
document.addEventListener('readystatechange', () => {
|
||||
if (document.readyState === 'complete') {
|
||||
showSelectedClientsOnEvents();
|
||||
updateScopeState();
|
||||
keepScopesTreeState();
|
||||
keepSelectedClients();
|
||||
|
@ -47,3 +48,7 @@
|
|||
</li>
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro selected_clients() -%}
|
||||
<div id="selected-clients" class="d-flex flex-wrap justify-content-center"></div>
|
||||
{% endmacro %}
|
||||
|
|
|
@ -29,3 +29,7 @@
|
|||
<input class="btn btn-light" type="submit" value="{{ _('Delete center') }}"
|
||||
form="scopesForm" formaction="{{ url_for('action_center_delete') }}" formmethod="get">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ macros.selected_clients() }}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue