Skip to content

Commit b79bfa0

Browse files
authored
CONCD-1326 (#3159)
* CONCD-1326 Recent Pages Worked on filter (WiP) * CONCD-1326 fixing an issue where dismissing the date filter was causing the page to reload with no data * CONCD-1326 trying to fix an issue where multiple event listeners are added * CONCD-1326 don't add a listener, unless the asset was actually reserved
1 parent 01ac58a commit b79bfa0

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

concordia/static/js/src/asset-reservation.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ function attemptToReserveAsset(reservationURL, findANewPageURL, actionType) {
9191
});
9292
}
9393
});
94+
}
9495

95-
window.addEventListener('beforeunload', function () {
96+
window.addEventListener('beforeunload', function () {
97+
if (assetReservationData.reserveAssetUrl) {
9698
let payload = {
9799
release: true,
98100
csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').val(),
@@ -101,16 +103,20 @@ function attemptToReserveAsset(reservationURL, findANewPageURL, actionType) {
101103
// We'll try Beacon since that's reliable but until we can drop support for IE11 we need a fallback:
102104
if ('sendBeacon' in navigator) {
103105
navigator.sendBeacon(
104-
reservationURL,
106+
assetReservationData.reserveAssetUrl,
105107
new Blob([$.param(payload)], {
106108
type: 'application/x-www-form-urlencoded',
107109
}),
108110
);
109111
} else {
110-
$.ajax({url: reservationURL, type: 'POST', data: payload});
112+
$.ajax({
113+
url: assetReservationData.reserveAssetUrl,
114+
type: 'POST',
115+
data: payload,
116+
});
111117
}
112-
});
113-
}
118+
}
119+
});
114120

115121
function reserveAssetForEditing() {
116122
if (assetReservationData.reserveAssetUrl) {

concordia/static/js/src/recent-pages.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,30 @@ export function getPages(queryString = window.location.search) {
77
dataType: 'json',
88
success: function (data) {
99
var recentPages = document.createElement('div');
10-
recentPages.setAttribute('class', 'col-md');
10+
recentPages.className = 'col-md';
1111
recentPages.innerHTML = data.content;
1212
$('#recent-pages').html(recentPages);
1313
},
14+
error: function () {
15+
$('#recent-pages').html('<p>Failed to load pages.</p>');
16+
},
1417
});
1518
}
1619

17-
$('#recent-tab').on('click', function () {
18-
getPages();
20+
$('#recent-tab').on('click', () => getPages(window.location.search));
21+
22+
$(document).on('submit', '.date-filter', function (event) {
23+
event.preventDefault();
24+
25+
const parameters = new URLSearchParams(new FormData(this));
26+
27+
getPages('?' + parameters.toString());
28+
});
29+
30+
$(document).on('click', '#current-filters a', function (event) {
31+
event.preventDefault();
32+
33+
const href = $(this).attr('href'); // e.g. "?tab=recent"
34+
35+
getPages(href);
1936
});

concordia/templates/fragments/recent-pages.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h2>Recent Pages Worked On</h2>
55
<div class="row mt-4">
66
{% include "fragments/standard-pagination.html" %}
77
</div>
8-
<form class="container form date-filter pb-1 mb-2">
8+
<form class="container form date-filter pb-1 mb-2" method="get">
99
<div class="d-flex flex-row">
1010
<span class="fw-bold me-1">Date: </span>Select Range
1111
</div>

0 commit comments

Comments
 (0)