mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 00:45:47 +01:00
fixed pagination, and loading of template blocks on cold load (temp solution)
This commit is contained in:
@@ -74,9 +74,12 @@ define(['forum/accountheader'], function(header) {
|
||||
socket.emit('user.isOnline', theirid, Account.handleUserOnline);
|
||||
|
||||
socket.on('event:new_post', function(data) {
|
||||
var html = templates.prepare(templates['account'].blocks['posts']).parse(data);
|
||||
$('.user-recent-posts').prepend(html);
|
||||
$('.user-recent-posts span.timeago').timeago();
|
||||
templates.preload_template('account', function() {
|
||||
templates['account'].parse({posts:[]});
|
||||
var html = templates.prepare(templates['account'].blocks['posts']).parse(data);
|
||||
$('.user-recent-posts').prepend(html);
|
||||
$('.user-recent-posts span.timeago').timeago();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -34,20 +34,23 @@ define(['forum/accountheader'], function(header) {
|
||||
}
|
||||
|
||||
function onTopicsLoaded(posts) {
|
||||
var html = templates.prepare(templates['accountposts'].blocks['posts']).parse({
|
||||
posts: posts
|
||||
});
|
||||
templates.preload_template('accountposts', function() {
|
||||
templates['accountposts'].parse(posts: []);
|
||||
var html = templates.prepare(templates['accountposts'].blocks['posts']).parse({
|
||||
posts: posts
|
||||
});
|
||||
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
|
||||
$('#category-no-topics').remove();
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
html = $(translatedHTML);
|
||||
html.find('img').addClass('img-responsive');
|
||||
$('.user-favourite-posts').append(html);
|
||||
$('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
html = $(translatedHTML);
|
||||
html.find('img').addClass('img-responsive');
|
||||
$('.user-favourite-posts').append(html);
|
||||
$('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -117,14 +117,17 @@ define(['uploader'], function(uploader) {
|
||||
timeout: 2000
|
||||
});
|
||||
|
||||
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
|
||||
categories: [data]
|
||||
});
|
||||
html = $(html);
|
||||
html.find('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker);
|
||||
templates.preload_template('admin/categories', function() {
|
||||
templates['admin/categories'].parse({categories:[]});
|
||||
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
|
||||
categories: [data]
|
||||
});
|
||||
html = $(html);
|
||||
html.find('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker);
|
||||
|
||||
$('#entry-container').append(html);
|
||||
$('#new-category-modal').modal('hide');
|
||||
$('#entry-container').append(html);
|
||||
$('#new-category-modal').modal('hide');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -62,20 +62,23 @@ define(function() {
|
||||
var btnEl = $('#topics_loadmore');
|
||||
|
||||
if (topics.length > 0) {
|
||||
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({
|
||||
topics: topics
|
||||
}),
|
||||
topicsListEl = $('.topics');
|
||||
templates.preload_template('admin/topics', function() {
|
||||
templates['admin/topics'].parse({topics:[]});
|
||||
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({
|
||||
topics: topics
|
||||
}),
|
||||
topicsListEl = $('.topics');
|
||||
|
||||
// Fix relative paths
|
||||
html = html.replace(/\{relative_path\}/g, RELATIVE_PATH);
|
||||
// Fix relative paths
|
||||
html = html.replace(/\{relative_path\}/g, RELATIVE_PATH);
|
||||
|
||||
topicsListEl.html(topicsListEl.html() + html);
|
||||
topicsListEl.html(topicsListEl.html() + html);
|
||||
|
||||
Topics.resolveButtonStates();
|
||||
Topics.resolveButtonStates();
|
||||
|
||||
btnEl.html('Load More Topics');
|
||||
$('span.timeago').timeago();
|
||||
btnEl.html('Load More Topics');
|
||||
$('span.timeago').timeago();
|
||||
});
|
||||
} else {
|
||||
// Exhausted all topics
|
||||
btnEl.addClass('disabled');
|
||||
|
||||
@@ -190,27 +190,30 @@ define(function() {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
||||
users: data.users
|
||||
}),
|
||||
userListEl = document.querySelector('.users');
|
||||
templates.preload_template('admin/users', function() {
|
||||
templates['admin/users'].parse({users:[]});
|
||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
||||
users: data.users
|
||||
}),
|
||||
userListEl = document.querySelector('.users');
|
||||
|
||||
userListEl.innerHTML = html;
|
||||
$('.fa-spinner').addClass('none');
|
||||
userListEl.innerHTML = html;
|
||||
$('.fa-spinner').addClass('none');
|
||||
|
||||
if (data && data.users.length === 0) {
|
||||
$('#user-notfound-notify').html('User not found!')
|
||||
.show()
|
||||
.addClass('label-danger')
|
||||
.removeClass('label-success');
|
||||
} else {
|
||||
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.')
|
||||
.show()
|
||||
.addClass('label-success')
|
||||
.removeClass('label-danger');
|
||||
}
|
||||
if (data && data.users.length === 0) {
|
||||
$('#user-notfound-notify').html('User not found!')
|
||||
.show()
|
||||
.addClass('label-danger')
|
||||
.removeClass('label-success');
|
||||
} else {
|
||||
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.')
|
||||
.show()
|
||||
.addClass('label-success')
|
||||
.removeClass('label-danger');
|
||||
}
|
||||
|
||||
updateButtons();
|
||||
updateButtons();
|
||||
});
|
||||
});
|
||||
}, 250);
|
||||
});
|
||||
@@ -220,14 +223,17 @@ define(function() {
|
||||
handleUserCreate();
|
||||
|
||||
function onUsersLoaded(users) {
|
||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
||||
users: users
|
||||
});
|
||||
html = $(html);
|
||||
$('#users-container').append(html);
|
||||
templates.preload_template('admin/users', function() {
|
||||
templates['admin/users'].parse({users:[]});
|
||||
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
|
||||
users: users
|
||||
});
|
||||
html = $(html);
|
||||
$('#users-container').append(html);
|
||||
|
||||
updateUserBanButtons(html.find('.ban-btn'));
|
||||
updateUserAdminButtons(html.find('.admin-btn'));
|
||||
updateUserBanButtons(html.find('.ban-btn'));
|
||||
updateUserAdminButtons(html.find('.admin-btn'));
|
||||
});
|
||||
}
|
||||
|
||||
function loadMoreUsers() {
|
||||
|
||||
@@ -162,45 +162,47 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
||||
|
||||
Category.onNewTopic = function(data) {
|
||||
$(window).trigger('filter:categories.new_topic', data);
|
||||
|
||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
||||
topics: [data]
|
||||
});
|
||||
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
var topic = $(translatedHTML),
|
||||
container = $('#topics-container'),
|
||||
topics = $('#topics-container').children('.category-item'),
|
||||
numTopics = topics.length;
|
||||
|
||||
$('#topics-container, .category-sidebar').removeClass('hidden');
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
if (numTopics > 0) {
|
||||
for (var x = 0; x < numTopics; x++) {
|
||||
if ($(topics[x]).find('.fa-thumb-tack').length) {
|
||||
if(x === numTopics - 1) {
|
||||
topic.insertAfter(topics[x]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
topic.insertBefore(topics[x]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
container.append(topic);
|
||||
}
|
||||
|
||||
topic.hide().fadeIn('slow');
|
||||
|
||||
socket.emit('categories.getPageCount', templates.get('category_id'), function(err, newPageCount) {
|
||||
pagination.recreatePaginationLinks(newPageCount);
|
||||
templates.preload_template('category', function() {
|
||||
templates['category'].parse({topics:[]});
|
||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
||||
topics: [data]
|
||||
});
|
||||
|
||||
topic.find('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
var topic = $(translatedHTML),
|
||||
container = $('#topics-container'),
|
||||
topics = $('#topics-container').children('.category-item'),
|
||||
numTopics = topics.length;
|
||||
|
||||
$(window).trigger('action:categories.new_topic.loaded');
|
||||
$('#topics-container, .category-sidebar').removeClass('hidden');
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
if (numTopics > 0) {
|
||||
for (var x = 0; x < numTopics; x++) {
|
||||
if ($(topics[x]).find('.fa-thumb-tack').length) {
|
||||
if(x === numTopics - 1) {
|
||||
topic.insertAfter(topics[x]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
topic.insertBefore(topics[x]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
container.append(topic);
|
||||
}
|
||||
|
||||
topic.hide().fadeIn('slow');
|
||||
|
||||
socket.emit('categories.getPageCount', templates.get('category_id'), function(err, newPageCount) {
|
||||
pagination.recreatePaginationLinks(newPageCount);
|
||||
});
|
||||
|
||||
topic.find('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
|
||||
$(window).trigger('action:categories.new_topic.loaded');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -239,36 +241,39 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
||||
|
||||
findInsertionPoint();
|
||||
|
||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
||||
topics: topics
|
||||
});
|
||||
templates.preload_template('category', function() {
|
||||
templates['category'].parse({topics:[]});
|
||||
var html = templates.prepare(templates['category'].blocks['topics']).parse({
|
||||
topics: topics
|
||||
});
|
||||
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
var container = $('#topics-container'),
|
||||
html = $(translatedHTML);
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
var container = $('#topics-container'),
|
||||
html = $(translatedHTML);
|
||||
|
||||
$('#topics-container, .category-sidebar').removeClass('hidden');
|
||||
$('#category-no-topics').remove();
|
||||
$('#topics-container, .category-sidebar').removeClass('hidden');
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
if(config.usePagination) {
|
||||
container.empty().append(html);
|
||||
} else {
|
||||
if(after) {
|
||||
html.insertAfter(after);
|
||||
} else if(before) {
|
||||
html.insertBefore(before);
|
||||
if(config.usePagination) {
|
||||
container.empty().append(html);
|
||||
} else {
|
||||
container.append(html);
|
||||
if(after) {
|
||||
html.insertAfter(after);
|
||||
} else if(before) {
|
||||
html.insertBefore(before);
|
||||
} else {
|
||||
container.append(html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
html.find('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
html.find('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback(topics);
|
||||
}
|
||||
if (typeof callback === 'function') {
|
||||
callback(topics);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -33,20 +33,23 @@ define(['forum/accountheader'], function(header) {
|
||||
}
|
||||
|
||||
function onTopicsLoaded(posts) {
|
||||
var html = templates.prepare(templates['favourites'].blocks['posts']).parse({
|
||||
posts: posts
|
||||
});
|
||||
templates.preload_template('favourites', function() {
|
||||
templates['favourites'].parse({posts:[]});
|
||||
var html = templates.prepare(templates['favourites'].blocks['posts']).parse({
|
||||
posts: posts
|
||||
});
|
||||
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
|
||||
$('#category-no-topics').remove();
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
html = $(translatedHTML);
|
||||
html.find('img').addClass('img-responsive');
|
||||
$('.user-favourite-posts').append(html);
|
||||
$('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
html = $(translatedHTML);
|
||||
html.find('img').addClass('img-responsive');
|
||||
$('.user-favourite-posts').append(html);
|
||||
$('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -116,19 +116,22 @@ define(function() {
|
||||
}
|
||||
|
||||
Recent.onTopicsLoaded = function(template, topics) {
|
||||
var html = templates.prepare(templates[template].blocks['topics']).parse({
|
||||
topics: topics
|
||||
});
|
||||
templates.preload_template(template, function() {
|
||||
templates[template].parse({topics:[]});
|
||||
var html = templates.prepare(templates[template].blocks['topics']).parse({
|
||||
topics: topics
|
||||
});
|
||||
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
translator.translate(html, function(translatedHTML) {
|
||||
|
||||
$('#category-no-topics').remove();
|
||||
$('#category-no-topics').remove();
|
||||
|
||||
html = $(translatedHTML);
|
||||
$('#topics-container').append(html);
|
||||
$('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
html = $(translatedHTML);
|
||||
$('#topics-container').append(html);
|
||||
$('span.timeago').timeago();
|
||||
app.createUserTooltips();
|
||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1233,8 +1233,11 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
||||
}
|
||||
|
||||
function parseAndTranslatePosts(data, callback) {
|
||||
var html = templates.prepare(templates['topic'].blocks['posts']).parse(data);
|
||||
translator.translate(html, callback);
|
||||
templates.preload_template('topic', function() {
|
||||
templates['topic'].parse({posts: []});
|
||||
var html = templates.prepare(templates['topic'].blocks['posts']).parse(data);
|
||||
translator.translate(html, callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -59,22 +59,24 @@ define(function() {
|
||||
return;
|
||||
}
|
||||
|
||||
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
||||
users: data.users
|
||||
}),
|
||||
userListEl = $('#users-container');
|
||||
templates.preload_template('users', function() {
|
||||
templates['users'].parse({users:[]});
|
||||
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
||||
users: data.users
|
||||
}),
|
||||
userListEl = $('#users-container');
|
||||
|
||||
userListEl.html(html);
|
||||
userListEl.html(html);
|
||||
|
||||
|
||||
if (data && data.users.length === 0) {
|
||||
$('#user-notfound-notify').html('User not found!');
|
||||
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
||||
} else {
|
||||
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
|
||||
$('#user-notfound-notify').parent().addClass('btn-success label-success');
|
||||
}
|
||||
|
||||
if (data && data.users.length === 0) {
|
||||
$('#user-notfound-notify').html('User not found!');
|
||||
$('#user-notfound-notify').parent().addClass('btn-warning label-warning');
|
||||
} else {
|
||||
$('#user-notfound-notify').html(data.users.length + ' user' + (data.users.length > 1 ? 's' : '') + ' found! Search took ' + data.timing + ' ms.');
|
||||
$('#user-notfound-notify').parent().addClass('btn-success label-success');
|
||||
}
|
||||
});
|
||||
});
|
||||
}, 500); //replace this with global throttling function/constant
|
||||
|
||||
@@ -108,17 +110,20 @@ define(function() {
|
||||
}
|
||||
|
||||
function onUsersLoaded(users, emptyContainer) {
|
||||
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
||||
users: users
|
||||
});
|
||||
templates.preload_template('users', function() {
|
||||
templates['useres'].parse({users:[]});
|
||||
var html = templates.prepare(templates['users'].blocks['users']).parse({
|
||||
users: users
|
||||
});
|
||||
|
||||
translator.translate(html, function(translated) {
|
||||
if(emptyContainer) {
|
||||
$('#users-container .registered-user').remove();
|
||||
}
|
||||
translator.translate(html, function(translated) {
|
||||
if(emptyContainer) {
|
||||
$('#users-container .registered-user').remove();
|
||||
}
|
||||
|
||||
$('#users-container').append(translated);
|
||||
$('#users-container .anon-user').appendTo($('#users-container'));
|
||||
$('#users-container').append(translated);
|
||||
$('#users-container .anon-user').appendTo($('#users-container'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user