group join/leave controls in groups list page (+ helper!)

v1.18.x
Julian Lam 10 years ago
parent f3fa2f10ed
commit 917f76feab

@ -17,6 +17,19 @@
return '<meta ' + name + property + content + '/>';
};
// Groups helpers
helpers.membershipBtn = function(groupObj) {
if (groupObj.isMember) {
return '<button class="btn btn-danger" data-action="leave" data-group="' + groupObj.name + '"><i class="fa fa-times"></i> Leave Group</button>';
} else {
if (groupObj.pending) {
return '<button class="btn btn-warning disabled"><i class="fa fa-clock-o"></i> Invitation Pending</button>';
} else {
return '<button class="btn btn-success" data-action="join" data-group="' + groupObj.name + '"><i class="fa fa-plus"></i> Join Group</button>';
}
}
};
if ('undefined' !== typeof window) {
$(document).ready(module.exports);
}
@ -26,6 +39,7 @@
templates.registerHelper('displayUsersLink', helpers.displayUsersLink);
templates.registerHelper('buildMetaTag', helpers.buildMetaTag);
templates.registerHelper('membershipBtn', helpers.membershipBtn);
};
})('undefined' === typeof module ? {

@ -9,7 +9,8 @@ var groups = require('../groups'),
groupsController.list = function(req, res, next) {
groups.list({
truncateUserList: true,
expand: true
expand: true,
uid: req.user ? req.user.uid : 0
}, function(err, groups) {
if (err) {
return next(err);

@ -71,7 +71,25 @@ var async = require('async'),
groupNames = groupNames.concat(ephemeralGroups);
async.map(groupNames, function (groupName, next) {
Groups.get(groupName, options, next);
async.waterfall([
async.apply(Groups.get, groupName, options),
function(groupObj, next) {
// Retrieve group membership state, if uid is passed in
if (!options.uid) {
return next(null, groupObj);
}
Groups.isMember(options.uid, groupName, function(err, isMember) {
if (err) {
winston.warn('[groups.list] Could not determine membership in group `' + groupName + '` for uid `' + options.uid + '`: ' + err.message);
return next(null, groupObj);
}
groupObj.isMember = isMember;
next(null, groupObj);
});
}
], next);
}, function (err, groups) {
callback(err, internals.filterGroups(groups, options));
});

Loading…
Cancel
Save