mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 15:05:46 +01:00
finishing up topics list in admin panel with infinite loading
This commit is contained in:
@@ -24,13 +24,16 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
loadMoreEl.addEventListener('click', function() {
|
loadMoreEl.addEventListener('click', function() {
|
||||||
|
if (this.className.indexOf('disabled') === -1) {
|
||||||
var topics = document.querySelectorAll('.topics li[data-tid]'),
|
var topics = document.querySelectorAll('.topics li[data-tid]'),
|
||||||
lastTid = parseInt(topics[topics.length - 1].getAttribute('data-tid'));
|
lastTid = parseInt(topics[topics.length - 1].getAttribute('data-tid'));
|
||||||
|
|
||||||
|
this.innerHTML = '<i class="icon-refresh icon-spin"></i> Retrieving topics';
|
||||||
socket.emit('api:admin.topics.getMore', {
|
socket.emit('api:admin.topics.getMore', {
|
||||||
limit: 10,
|
limit: 10,
|
||||||
after: lastTid
|
after: lastTid
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
// Resolve proper button state for all topics
|
// Resolve proper button state for all topics
|
||||||
@@ -95,8 +98,21 @@ socket.on('api:topic.restore', function(response) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:admin.topics.getMore', function(topics) {
|
socket.on('api:admin.topics.getMore', function(topics) {
|
||||||
|
var btnEl = document.getElementById('topics_loadmore');
|
||||||
|
|
||||||
topics = JSON.parse(topics);
|
topics = JSON.parse(topics);
|
||||||
console.log(topics);
|
console.log(topics);
|
||||||
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse(topics);
|
if (topics.length > 0) {
|
||||||
console.log(html);
|
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({
|
||||||
|
topics: topics
|
||||||
|
}),
|
||||||
|
topicsListEl = document.querySelector('.topics');
|
||||||
|
|
||||||
|
topicsListEl.innerHTML += html;
|
||||||
|
btnEl.innerHTML = 'Load More Topics';
|
||||||
|
} else {
|
||||||
|
// Exhausted all topics
|
||||||
|
btnEl.className += ' disabled';
|
||||||
|
btnEl.innerHTML = 'No more topics';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user