From cba7a0c1c617e1039055652318c11f309eda932f Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Thu, 11 Jan 2024 13:36:19 +0100 Subject: views: Add computers to folder Add support for adding computers to a folder. It uses a js script that when selecting a folder in the html form, it will also select the parent of the folder. For instance, if the user were to select a folder that is contained inside a room, the room would also get selected. This allows the view to know which parent contains the folder. --- ogcp/forms/action_forms.py | 1 + ogcp/static/js/ogcp.js | 8 ++++++++ ogcp/templates/macros.html | 14 ++++++++------ ogcp/views.py | 10 ++++++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index cbdaaaa..c803b02 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -129,6 +129,7 @@ class ClientDetailsForm(FlaskForm): ('eth2', 'eth2')]) repo = SelectField(label=_l('Repository')) room = SelectField(label=_l('Room')) + folder_id = HiddenField() boot = SelectField(label=_l('Boot Mode')) submit = SubmitField(label=_l('Submit')) diff --git a/ogcp/static/js/ogcp.js b/ogcp/static/js/ogcp.js index 964e68d..ccd8a1e 100644 --- a/ogcp/static/js/ogcp.js +++ b/ogcp/static/js/ogcp.js @@ -374,6 +374,14 @@ function checkRepoServer() { }); } +function checkFolderParent() { + const folder = $('input:checkbox[form|="scopesForm"][name="folder"]') + folder.on('change', function() { + const folder_parent = $('#' + $.escapeSelector(this.dataset.parentInput)); + folder_parent.prop('checked', true); + }); +} + function limitCheckboxes() { const checkboxes = $('input:checkbox[form|="scopesForm"]'); diff --git a/ogcp/templates/macros.html b/ogcp/templates/macros.html index e78cb5b..a00556f 100644 --- a/ogcp/templates/macros.html +++ b/ogcp/templates/macros.html @@ -17,6 +17,7 @@ checkParentsCheckboxes(); {% elif selection_mode == 'scopes' %} limitCheckboxes(); + checkFolderParent(); {% endif %} } }); @@ -27,14 +28,15 @@ {% macro scopes_tree_collapse_level(scopes, parent_room, parent_id, state, selection_mode) -%} {% for scope in scopes %}