fix: markread selector

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 030ecffa15
commit a4878a5b22

@ -1,7 +1,9 @@
'use strict';
define('forum/unread', ['topicSelect', 'components', 'topicList'], function (topicSelect, components, topicList) {
define('forum/unread', [
'topicSelect', 'components', 'topicList', 'categorySelector',
], function (topicSelect, components, topicList, categorySelector) {
var Unread = {};
var watchStates = {
@ -13,25 +15,15 @@ define('forum/unread', ['topicSelect', 'components', 'topicList'], function (top
Unread.init = function () {
app.enterRoom('unread_topics');
handleMarkRead();
topicList.init('unread');
updateUnreadTopicCount('/' + ajaxify.data.selectedFilter.url, ajaxify.data.topicCount);
};
$('#markSelectedRead').on('click', function () {
var tids = topicSelect.getSelectedTids();
if (!tids.length) {
return;
}
socket.emit('topics.markAsRead', tids, function (err) {
if (err) {
return app.alertError(err.message);
}
doneRemovingTids(tids);
});
});
$('#markAllRead').on('click', function () {
function handleMarkRead() {
function markAllRead() {
socket.emit('topics.markAllRead', function (err) {
if (err) {
return app.alertError(err.message);
@ -44,9 +36,23 @@ define('forum/unread', ['topicSelect', 'components', 'topicList'], function (top
$('#category-no-topics').removeClass('hidden');
$('.markread').addClass('hidden');
});
});
}
$('.markread').on('click', '.category', function () {
function markSelectedRead() {
var tids = topicSelect.getSelectedTids();
if (!tids.length) {
return;
}
socket.emit('topics.markAsRead', tids, function (err) {
if (err) {
return app.alertError(err.message);
}
doneRemovingTids(tids);
});
}
function markCategoryRead(cid) {
function getCategoryTids(cid) {
var tids = [];
components.get('category/topic', 'cid', cid).each(function () {
@ -54,7 +60,6 @@ define('forum/unread', ['topicSelect', 'components', 'topicList'], function (top
});
return tids;
}
var cid = $(this).attr('data-cid');
var tids = getCategoryTids(cid);
socket.emit('topics.markCategoryTopicsRead', cid, function (err) {
@ -64,8 +69,35 @@ define('forum/unread', ['topicSelect', 'components', 'topicList'], function (top
doneRemovingTids(tids);
});
}
var selector = categorySelector.init($('[component="category-selector"]'), {
onSelect: function (category) {
console.log(category);
selector.selectCategory(0);
if (category.cid === 'all') {
markAllRead();
} else if (category.cid === 'selected') {
markSelectedRead();
} else if (parseInt(category.cid, 10) > 0) {
markCategoryRead(category.cid);
}
},
selectCategoryLabel: ajaxify.data.selectCategoryLabel || '[[unread:mark_as_read]]',
localCategories: [
{
cid: 'selected',
name: '[[unread:selected]]',
icon: '',
},
{
cid: 'all',
name: '[[unread:all]]',
icon: '',
},
],
});
};
}
function doneRemovingTids(tids) {
removeTids(tids);

@ -37,9 +37,13 @@ define('categorySelector', ['categorySearch'], function (categorySearch) {
};
if (categoryEl.length) {
selector.el.find('[component="category-selector-selected"]').html(categoryEl.find('[component="category-markup"]').html());
selector.el.find('[component="category-selector-selected"]').html(
categoryEl.find('[component="category-markup"]').html()
);
} else {
selector.el.find('[component="category-selector-selected"]').translateHtml('[[topic:thread_tools.select_category]]');
selector.el.find('[component="category-selector-selected"]').translateHtml(
options.selectCategoryLabel || '[[topic:thread_tools.select_category]]'
);
}
};
selector.getSelectedCategory = function () {

@ -48,6 +48,7 @@ unreadController.get = async function (req, res) {
data.allCategoriesUrl = 'unread' + helpers.buildQueryString(req.query, 'cid', '');
data.selectedCategory = categoryData.selectedCategory;
data.selectedCids = categoryData.selectedCids;
data.selectCategoryLabel = '[[unread:mark_as_read]]';
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/unread') || req.originalUrl.startsWith(nconf.get('relative_path') + '/unread')) {
data.title = '[[pages:unread]]';
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);

Loading…
Cancel
Save