Move to client side

v1.18.x
MrWaffle 11 years ago
parent 03d92eb5cd
commit d63ced8a5c

@ -342,7 +342,16 @@ define(['composer'], function(composer) {
}
})();
$('.favourite-tooltip').tooltip();
$('#post-container').on('mouseenter', '.favourite-tooltip', function(e) {
if (!$(this).data('users-loaded')) {
$(this).data('users-loaded', "true");
var pid = $(this).parents('.post-row').attr('data-pid');
var el = $(this).attr('title', "Loading...");
socket.emit('posts.getFavouritedUsers', pid, function(err, usernames) {
el.attr('title', usernames).tooltip('show');
});
}
});
});
function enableInfiniteLoading() {

@ -66,7 +66,7 @@
<!-- IF @first -->
<button class="btn btn-sm btn-default follow" type="button" title="Be notified of new replies in this topic"><i class="fa fa-eye"></i></button>
<!-- ENDIF @first -->
<button title="{posts.favourited_users}" data-favourited="{posts.favourited}" class="favourite favourite-tooltip btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
<button data-favourited="{posts.favourited}" class="favourite favourite-tooltip btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
<span class="favourite-text">[[topic:favourite]]</span>
<span class="post_rep_{posts.pid}">{posts.reputation} </span>
<!-- IF posts.favourited -->

@ -3,6 +3,7 @@ var posts = require('../posts'),
topics = require('../topics'),
favourites = require('../favourites'),
postTools = require('../postTools'),
user = require('../user'),
index = require('./index'),
SocketPosts = {};
@ -168,4 +169,28 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
});
};
SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
favourites.getFavouritedUidsByPids([pid], function(data) {
var max = 5; //hardcoded
var usernames = "";
var pid_uids = data[pid];
var rest_amount = 0;
if (data.hasOwnProperty(pid) && pid_uids.length > 0) {
if (pid_uids.length > max) {
rest_amount = pid_uids.length - max;
pid_uids = pid_uids.slice(0, max);
}
user.getUsernamesByUids(pid_uids, function(result) {
usernames = result.join(', ') + (rest_amount > 0
? " and " + rest_amount + (rest_amount > 1 ? " others" : " other")
: "");
callback(null, usernames);
});
} else {
callback(null, "");
}
});
};
module.exports = SocketPosts;

@ -370,33 +370,6 @@ var async = require('async'),
});
}
function getFavouritedUsers(next) {
favourites.getFavouritedUidsByPids(pids, function(data) {
var max = 5; //hardcoded
var usernames = {};
async.each(pids, function(pid, next) {
var pid_uids = data[pid];
var rest_amount = 0;
if (data.hasOwnProperty(pid) && pid_uids.length > 0) {
if (pid_uids.length > max) {
rest_amount = pid_uids.length - max;
pid_uids = pid_uids.slice(0, max);
}
user.getUsernamesByUids(pid_uids, function(result) {
usernames[pid] = result.join(', ') + (rest_amount > 0
? " and " + rest_amount + (rest_amount > 1 ? " others" : " other")
: "");
});
} else {
usernames[pid] = [];
}
next();
}, function(err) {
next(err, usernames);
});
});
}
function addUserInfoToPosts(next) {
function iterator(post, callback) {
posts.addUserInfoToPost(post, function() {
@ -426,19 +399,17 @@ var async = require('async'),
}
}
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges, getFavouritedUsers], function(err, results) {
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) {
if(err) {
return callback(err);
}
var fav_data = results[0],
privileges = results[2],
fav_users = results[3];
privileges = results[2];
for (var i = 0; i < postData.length; ++i) {
var pid = postData[i].pid;
postData[i].favourited = fav_data[pid];
postData[i].favourited_users = fav_users[pid];
postData[i].display_moderator_tools = (current_user != 0) && privileges[pid].editable;
postData[i].display_move_tools = privileges[pid].move ? '' : 'hidden';
}

Loading…
Cancel
Save