From: Raxel Gutierrez Date: Fri, 13 Aug 2021 05:31:20 +0000 (+0000) Subject: patch-detail: refactor JS code into submission.js X-Git-Tag: v3.1.0~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3870d7b87f64812c318149b2590916ae27ab818e;p=thirdparty%2Fpatchwork.git patch-detail: refactor JS code into submission.js Move submission.html script code for toggling header info to a separate submission.js file that makes the code easy to read and ready for change in one place. The listener is moved from the 'href' to separate, explicit click listener. Signed-off-by: Raxel Gutierrez [stephenfin: Removed existing JS href added in previous change and update commit message to reflect this] Signed-off-by: Stephen Finucane --- diff --git a/htdocs/js/submission.js b/htdocs/js/submission.js new file mode 100644 index 00000000..9676f348 --- /dev/null +++ b/htdocs/js/submission.js @@ -0,0 +1,42 @@ +$( document ).ready(function() { + function toggleDiv(link_id, headers_id, label_show, label_hide) { + const link = document.getElementById(link_id) + const headers = document.getElementById(headers_id) + + const hidden = headers.style['display'] == 'none'; + + if (hidden) { + link.innerHTML = label_hide || 'hide'; + headers.style['display'] = 'block'; + } else { + link.innerHTML = label_show || 'show'; + headers.style['display'] = 'none'; + } + } + + // Click listener to show/hide headers + document.getElementById("toggle-patch-headers").addEventListener("click", function() { + toggleDiv("toggle-patch-headers", "patch-headers"); + }); + + // Click listener to expand/collapse series + document.getElementById("toggle-patch-series").addEventListener("click", function() { + toggleDiv("toggle-patch-series", "patch-series", "expand", "collapse"); + }); + + // Click listener to show/hide related patches + let related = document.getElementById("toggle-related"); + if (related) { + document.getElementById("toggle-related").addEventListener("click", function() { + toggleDiv("toggle-related", "related"); + }); + } + + // Click listener to show/hide related patches from different projects + let relatedOutside = document.getElementById("toggle-related-outside"); + if (relatedOutside) { + document.getElementById("toggle-related-outside").addEventListener("click", function() { + toggleDiv("toggle-related-outside", "related-outside", "show from other projects"); + }); + } +}); \ No newline at end of file diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html index 9212fc99..19d9413a 100644 --- a/patchwork/templates/patchwork/submission.html +++ b/patchwork/templates/patchwork/submission.html @@ -4,28 +4,15 @@ {% load syntax %} {% load person %} {% load patch %} +{% load static %} + +{% block headers %} + +{% endblock %} {% block title %}{{submission.name}}{% endblock %} {% block body %} -
{% include "patchwork/partials/download-buttons.html" %} @@ -62,7 +49,7 @@ function toggle_div(link_id, headers_id, label_show, label_hide) Headers - show + show @@ -75,7 +62,7 @@ function toggle_div(link_id, headers_id, label_show, label_hide) {{ submission.series.name }} | - expand + expand