^{table}
- $if pageCount > 1
-
- $# TODO: foreach (reachable pages) print link to that page
- _{MsgPage (succ psPage) pageCount}
-$else
- ^{table}
+ $if pageCount > 1
+
+ $# TODO: foreach (reachable pages) print link to that page
+ _{MsgPage (succ psPage) pageCount}
diff --git a/templates/table/layout.julius b/templates/table/layout.julius
new file mode 100644
index 000000000..45ca89830
--- /dev/null
+++ b/templates/table/layout.julius
@@ -0,0 +1,79 @@
+(function collonadeClosure() {
+ 'use strict';
+
+ document.addEventListener('DOMContentLoaded', function DOMContentLoaded() {
+
+ var ASC = 'asc';
+ var DESC = 'desc';
+
+ function setupSorting(wrapper) {
+
+ var table = wrapper.querySelector('#' + #{String $ wIdent "table-only"}.replace('-table-only', ''));
+ var ths = Array.from(table.querySelectorAll('th'));
+
+ // attach click handler to each table-header
+ ths.forEach(function(th) {
+ th.addEventListener('click', clickHandler);
+ // TODO: Remove this forEach once column-description is link
+ Array.from(th.querySelectorAll('a')).forEach(function(a) {
+ a.style.display = 'none';
+ })
+ });
+
+ // handles click on table header
+ function clickHandler(event) {
+ event.preventDefault();
+ var link = this.querySelector('a');
+ if (!link) {
+ return false;
+ }
+ var href = link.getAttribute('href');
+ var url = new URL(window.location.origin + window.location.pathname + href);
+ var order = this.dataset.order || ASC;
+ url.searchParams.set(#{String $ wIdent "table-only"}, 'yes');
+ updateTableFrom(url);
+ markAsSorted(this, order);
+ }
+
+ function markAsSorted(th, order) {
+ ths.forEach(function(th) {
+ th.classList.remove('sorted-asc', 'sorted-desc');
+ });
+ th.classList.add('sorted-' + order);
+ th.dataset.order = order;
+ }
+
+ function replaceContent(content) {
+ wrapper.innerHTML = content;
+ setupSorting(wrapper);
+ }
+
+ // fetches new sorted table from url with params and replaces contents of current table
+ function updateTableFrom(url) {
+ fetch(url, {
+ credentials: 'same-origin',
+ headers: {
+ 'Accept': 'text/html'
+ }
+ }).then(function(response) {
+ var contentType = response.headers.get("content-type");
+ if (!response.ok) {
+ throw ('Looks like there was a problem fetching ' + url.toString() + '. Status Code: ' + response.status);
+ }
+ return response.text();
+ }).then(function(data) {
+ // replace contents of table body
+ replaceContent(data);
+ table.querySelector('tbody').innerHTML = data;
+ }).catch(function(err) {
+ console.error(err);
+ });
+ }
+
+ }
+
+ // TODO: how to get 'terms' only?
+ var selector = #{String $ wIdent "table-only"}.replace('-only', '-wrapper');
+ setupSorting(document.querySelector('#' + selector));
+ });
+})();
diff --git a/templates/table/sortable-header.hamlet b/templates/table/sortable-header.hamlet
index b5e006b6a..1f358cbff 100644
--- a/templates/table/sortable-header.hamlet
+++ b/templates/table/sortable-header.hamlet
@@ -1,6 +1,5 @@
^{cellContents}
$maybe flag <- sortableKey
-
$case directions
$of [SortAsc]
"-desc")}>desc
@@ -8,7 +7,6 @@ $maybe flag <- sortableKey
"-asc")}>asc
$of []
"-desc")}>desc
- /
"-asc")}>asc
$of _
$nothing
diff --git a/templates/terms.hamlet b/templates/terms.hamlet
index d327861ab..4d5e14631 100644
--- a/templates/terms.hamlet
+++ b/templates/terms.hamlet
@@ -1,5 +1,4 @@
Semesterübersicht
-
- ^{table}
+ ^{table}