Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remeber what tab was choosen on pdf/list #75

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions backend/static/js/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ export class BooleanOption {
}
}

export class CheckboxOption {
constructor(checkbox, callable, defaultValue) {
this.checkbox = checkbox;
this.callable = callable;
this.defaultValue = defaultValue || false;
}

get() {
return this.checkbox.filter(":checked").val()
}

set(value) {
this.checkbox.filter("[value=" + value + "]").prop("checked", true)
}

call(value) {
this.callable(value)
}

selector() {
return this.checkbox
}

default() {
return this.defaultValue
}
}
export class Options {
constructor(options) {
this.options = options
Expand Down
23 changes: 17 additions & 6 deletions pdf/templates/pdf/requests/list.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{% extends "base/frame.html" %}
{% load i18n %}
{% load types %}
{% load static %}

{% block title %} {% trans "PDF Requests" %} {% endblock %}
{% block header %} {% trans "PDF Requests" %} {% endblock %}

{% block extra_head %}
<script defer type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.13.6/datatables.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.13.6/datatables.min.css"/>
<script type="module" src="{% static 'js/js.cookie.js' %}"></script>
<script type="module" src="{% static 'js/Options.js' %}"></script>
{% endblock %}

{% block framed_body %}
<div class="btn-group btn-group-toggle mb-2 float-left" data-toggle="buttons">
<label class="btn btn-outline-info">
<input type="radio" name="options" value="{% trans "Manual" %}" checked> {% trans "Manual" %}
<input type="radio" name="options" value="{% trans "Manual" %}"> {% trans "Manual" %}
</label>

<label class="btn btn-outline-info active">
Expand Down Expand Up @@ -84,8 +87,19 @@
</table>
</div>
<script type="module">
const initial_value = $("input[type=radio][name=options]").val()
const table = $('#datatable').DataTable({
import {Options, CheckboxOption} from "{% static 'js/Options.js' %}"

let table = null
function switch_tab(value) {
if (table) table.column(2).search(value).draw()
}

const config = new Map([
["tab", new CheckboxOption($("input[type=radio][name=options]"), switch_tab, "{% trans "Manual" %}")],
])
const options = new Options(config)
const initial_value = options.get("tab")
table = $('#datatable').DataTable({
processing: true,
order: [[ 1, "desc" ]],
dom: 'rtip',
Expand All @@ -103,8 +117,5 @@
$("#searchInput").on("input", function (event) {
table.search($(this).val()).draw();
});
$("input[type=radio][name=options]").change(function() {
table.column(2).search(this.value).draw()
});
</script>
{% endblock %}