add button for unread + refactor

This commit is contained in:
Matthias 2021-11-29 01:09:36 +01:00
parent d57ebde265
commit 5bfe891208
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -22,6 +22,11 @@
{% block js_ready %} {% block js_ready %}
{{ block.super }} {{ block.super }}
function updateNotificationTables() {
$("#inbox-table").bootstrapTable('refresh');
$("#history-table").bootstrapTable('refresh');
}
function loadNotificationTable(table, options={}) { function loadNotificationTable(table, options={}) {
var params = options.params || {}; var params = options.params || {};
@ -82,7 +87,16 @@ function loadNotificationTable(table, options={}) {
}, },
{ {
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
var bRead = "<button title='{% trans "Mark as read" %}' class='notification-read btn btn-outline-secondary' type='button' pk='" + row.pk + "'><span class='fas fa-check icon-green'></span></button>"; if (row.read) {
var bReadText = '{% trans "Mark as unread" %}';
var bReadIcon = 'fa-uncheck icon-red';
var bReadTarget = 'unread';
} else {
var bReadText = '{% trans "Mark as read" %}';
var bReadIcon = 'fa-check icon-green';
var bReadTarget = 'read';
}
var bRead = `<button title='${bReadText}' class='notification-read btn btn-outline-secondary' type='button' pk='${row.pk}' target='${bReadTarget}'><span class='fas ${bReadIcon}'></span></button>`;
var html = "<div class='btn-group float-right' role='group'>" + bRead + "</div>"; var html = "<div class='btn-group float-right' role='group'>" + bRead + "</div>";
return html; return html;
} }
@ -91,13 +105,11 @@ function loadNotificationTable(table, options={}) {
}); });
$(table).on('click', '.notification-read', function() { $(table).on('click', '.notification-read', function() {
var url = "/api/notifications/" + $(this).attr('pk') + "/read/"; var url = `/api/notifications/${$(this).attr('pk')}/${$(this).attr('target')}/`;
inventreePut(url, {}, { inventreePut(url, {}, {
method: 'POST', method: 'POST',
success: function() { success: function() { updateNotificationTables(); }
$(table).bootstrapTable('refresh');
}
}); });
}); });
} }