Skip to content

Commit

Permalink
views: Move js code to separate file
Browse files Browse the repository at this point in the history
Move patch-list related JS code to a new patch-list.js file, to
make the JavaScript easy to read and change in one place. This makes
automatic code formatting easier, makes it more straightforward to
measure test coverage and discover opportunities for refactoring, and
simplifies a possible future migration to TypeScript if the project
chooses to go in that direction.

No user-visible change should be noticed.

Signed-off-by: Raxel Gutierrez <[email protected]>
Signed-off-by: Stephen Finucane <[email protected]>
[stephenfin: Addressed merged conflicts]
  • Loading branch information
raxelg authored and stephenfin committed Nov 1, 2024
1 parent 09613eb commit 0cea2e4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
6 changes: 6 additions & 0 deletions htdocs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ js
:GitHub: https://github.com/js-cookie/js-cookie/
:Version: 3.0.0

``patch-list.js.``
Event helpers and other application logic for patch-list.html. These
support patch list manipulation.

Part of Patchwork.

``rest.js.``
Utility module for REST API requests to be used by other Patchwork JS files.

Expand Down
14 changes: 14 additions & 0 deletions htdocs/js/patch-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$( document ).ready(function() {
$("#patch-list").stickyTableHeaders();

$("#patch-list").checkboxes("range", true);

$("#check-all").change(function(e) {
if(this.checked) {
$("#patch-list > tbody").checkboxes("check");
} else {
$("#patch-list > tbody").checkboxes("uncheck");
}
e.preventDefault();
});
});
21 changes: 4 additions & 17 deletions patchwork/templates/patchwork/partials/patch-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
{% load project %}
{% load static %}

{% block headers %}
<script src="{% static "js/patch-list.js" %}"></script>
{% endblock %}

{% include "patchwork/partials/filters.html" %}
{% include "patchwork/partials/pagination.html" %}

Expand Down Expand Up @@ -32,23 +36,6 @@
</div>
{% endif %}

<script type="text/javascript">
$(document).ready(function() {
$('#patch-list').stickyTableHeaders();

$('#patch-list').checkboxes('range', true);

$('#check-all').change(function(e) {
if(this.checked) {
$('#patch-list > tbody').checkboxes('check');
} else {
$('#patch-list > tbody').checkboxes('uncheck');
}
e.preventDefault();
});
});
</script>

<form method="post">
{% csrf_token %}
<input type="hidden" name="form" value="patch-list-form"/>
Expand Down

0 comments on commit 0cea2e4

Please sign in to comment.