From 053519beae0cb380864773a0cca6dd3d009a5899 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Mon, 16 Sep 2024 13:57:31 +0200 Subject: templates: save checkbox state in images and repos Store the checked checkboxes of the sidebar in Images and Repos. Autoselect the correct server after updating the checkboxes. --- ogcp/static/js/ogcp.js | 55 ++++++++++++++-------------------------------- ogcp/templates/base.html | 2 +- ogcp/templates/images.html | 6 +++-- ogcp/templates/repos.html | 4 +++- 4 files changed, 24 insertions(+), 43 deletions(-) (limited to 'ogcp') diff --git a/ogcp/static/js/ogcp.js b/ogcp/static/js/ogcp.js index f70f77c..96bf3d9 100644 --- a/ogcp/static/js/ogcp.js +++ b/ogcp/static/js/ogcp.js @@ -298,41 +298,6 @@ function updateScopes(scopes) { return hasLiveChildren; } -function checkImageServer() { - const images = $('input:checkbox[form|="imagesForm"][name!="image-server"]') - - images.on('change', function() { - const selectedServer = $('#' + $.escapeSelector(this.dataset.server)); - const serversSelector = 'input:checkbox[name|="image-server"]'; - const nonSelectedServers = $(serversSelector).not(selectedServer); - - selectedServer.prop('checked', true); - - nonSelectedServers.each(function() { - $(this).prop('checked', false); - const checkboxes = $('input:checkbox[data-server|="' + this.id + '"]'); - checkboxes.prop('checked', false); - }); - }); -} - -function checkRepoServer() { - const repos = $('input:checkbox[form|="reposForm"][name!="repos-server"]') - repos.on('change', function() { - const selectedServer = $('#' + $.escapeSelector(this.dataset.server)); - const serversSelector = 'input:checkbox[name|="repos-server"]'; - const nonSelectedServers = $(serversSelector).not(selectedServer); - - selectedServer.prop('checked', true); - - nonSelectedServers.each(function() { - $(this).prop('checked', false); - const checkboxes = $('input:checkbox[data-server|="' + this.id + '"]'); - checkboxes.prop('checked', false); - }); - }); -} - function checkFolderParent(context) { const folder = $('#sidebar input:checkbox[name="folder"]') folder.on('change', function() { @@ -362,7 +327,7 @@ function limitCheckboxes(context) { } }); - checkScopeServer(); + checkCheckbox('scope-server'); checkboxes.each(function() { storeCheckboxStatus(this, context); @@ -371,9 +336,9 @@ function limitCheckboxes(context) { }); } -function checkScopeServer() { - const servers = $('#sidebar input:checkbox[name="scope-server"]'); - servers.each(function() { +function checkCheckbox(inputName) { + const checkboxes = $('#sidebar input:checkbox[name="' + inputName + '"]'); + checkboxes.each(function() { const checkbox = this; const checkboxChildren = $('input:checkbox', this.parentNode).not(this); if (checkboxChildren.length == 0) return; @@ -382,3 +347,15 @@ function checkScopeServer() { checkbox.checked = checkedChildren.length > 0; }); } + +function checkOnChange(inputName) { + const checkboxes = $('#sidebar input:checkbox') + + checkboxes.on('change', function (event) { + checkCheckbox(inputName); + }); + + checkboxes.each(function () { + checkCheckbox(inputName) + }); +} diff --git a/ogcp/templates/base.html b/ogcp/templates/base.html index 9c6b3e1..f245c8d 100644 --- a/ogcp/templates/base.html +++ b/ogcp/templates/base.html @@ -111,7 +111,7 @@ - + @@ -45,7 +46,8 @@ + name="{{ image["name"] }}_{{ image["id"] }}" + id="image{{ image["id"] }}"/> {{ image["name"] }} {% endfor %} diff --git a/ogcp/templates/repos.html b/ogcp/templates/repos.html index 9f15391..2f5fe1b 100644 --- a/ogcp/templates/repos.html +++ b/ogcp/templates/repos.html @@ -27,6 +27,7 @@ {% for r in repos_list %}