Merge branch 'feature/save-amount-shown-per-page' into 'marietje-zuid'

Store page size on manage and request pages

Closes #51

See merge request technicie/MarietjeDjango!68
This commit is contained in:
2023-10-11 16:09:30 +02:00
4 changed files with 37 additions and 4 deletions

View File

@ -37,3 +37,25 @@ Number.prototype.timestampToHHMMSS = function () {
}
return hours + ':' + minutes + ':' + seconds;
};
function setCookie(name, value, days) {
let expires = "";
value = encodeURI(value);
if (days) {
let date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
let nameEQ = name + "=";
let ca = document.cookie.split(';');
for(let i=0;i < ca.length;i++) {
let c = ca[i];
while (c.charAt(0)===' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length,c.length));
}
return null;
}

View File

@ -22,6 +22,10 @@
<!-- Base JavaScript -->
<script type="text/javascript" src="{% static "marietje/js/base.js" %}"></script>
<script>
const CSRF_TOKEN = "{{ csrf_token }}";
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-primary">
@ -109,9 +113,6 @@
</footer>
{% endif %}
{% bootstrap_javascript %}
<script>
const CSRF_TOKEN = "{{ csrf_token }}";
</script>
{% block js %}{% endblock %}
</body>
</html>

View File

@ -425,6 +425,7 @@
this.page_size = 10;
}
this.page_number = 1;
setCookie("REQUEST_PAGE_SIZE", this.page_size, 14);
this.search();
}
}
@ -455,6 +456,10 @@
tata.error("", "An unknown error occurred, please try again.")
}
});
const stored_page_size = parseInt(getCookie("REQUEST_PAGE_SIZE"));
if (stored_page_size !== Number.NaN && stored_page_size > 0) {
this.page_size = stored_page_size;
}
},
methods: {
search() {

View File

@ -101,6 +101,7 @@
this.page_size = 10;
}
this.page_number = 1;
setCookie("MANAGE_PAGE_SIZE", this.page_size, 14);
this.refresh();
}
}
@ -131,6 +132,10 @@
tata.error("", "An unknown error occurred, please try again.")
}
});
const stored_page_size = parseInt(getCookie("MANAGE_PAGE_SIZE"));
if (stored_page_size !== Number.NaN && stored_page_size > 0) {
this.page_size = stored_page_size;
}
},
methods: {
search() {