2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-08 08:18:50 +00:00
Oliver 95645c7b14
Notification fix (#3939)
* Fix docstring for NotificationMessage class

* Fix for 'refresh' button in notification table

* Simplify API for marking notifications as 'read'

- Simply update the detail serializer
- No requirement for extra API endpoints
- Same updates for news feed entry
- Hide 'read' news on the home page
- Add ability to mark news items as read via table

* Bug fix for build.js

* Fix for part category template
2022-11-17 08:26:19 +11:00

81 lines
2.1 KiB
JavaScript

{% load i18n %}
{% load inventree_extras %}
/* exported
loadNewsFeedTable,
*/
/*
* Load notification table
*/
function loadNewsFeedTable(table, options={}, enableDelete=false) {
setupFilterList('news', table);
$(table).inventreeTable({
url: options.url,
name: 'news',
groupBy: false,
queryParams: {
ordering: 'published',
read: false,
},
paginationVAlign: 'bottom',
formatNoMatches: function() {
return '{% trans "No news found" %}';
},
columns: [
{
field: 'pk',
title: '{% trans "ID" %}',
visible: false,
switchable: false,
},
{
field: 'title',
title: '{% trans "Title" %}',
sortable: 'true',
formatter: function(value, row) {
return `<a href="` + row.link + `">` + value + `</a>`;
}
},
{
field: 'summary',
title: '{% trans "Summary" %}',
},
{
field: 'author',
title: '{% trans "Author" %}',
},
{
field: 'published',
title: '{% trans "Published" %}',
sortable: 'true',
formatter: function(value, row) {
var html = renderDate(value);
var buttons = getReadEditButton(row.pk, row.read);
html += `<div class='btn-group float-right' role='group'>${buttons}</div>`;
return html;
}
},
]
});
$(table).on('click', '.notification-read', function() {
var pk = $(this).attr('pk');
var url = `/api/news/${pk}/`;
inventreePut(url,
{
read: true,
},
{
method: 'PATCH',
success: function() {
$(table).bootstrapTable('refresh');
}
}
);
});
}