group searching

v1.18.x
Julian Lam 10 years ago
parent fa27461abc
commit 6502dd2561

@ -1,5 +1,5 @@
"use strict";
/* globals app, define, ajaxify, socket, bootbox, utils */
/* globals app, define, ajaxify, socket, bootbox, utils, templates */
define('forum/groups/list', function() {
var Groups = {};
@ -29,6 +29,32 @@ define('forum/groups/list', function() {
}
});
});
// Group searching
$('#search-text').on('keydown', function(e) {
if (e.keyCode === 13) { Groups.search($(this).val()); }
});
$('#search-button').on('click', function() {
Groups.search($(this).siblings('input').val());
});
};
Groups.search = function(query) {
var groupsEl = $('.groups.row');
socket.emit('groups.search', {
query: query,
options: {
expand: true
}
}, function(err, groups) {
templates.parse('partials/group_list', {
groups: groups
}, function(html) {
groupsEl.empty().append(html);
});
});
};
return Groups;

@ -898,4 +898,23 @@ var async = require('async'),
db.setRemove('group:' + groupName + ':owners', toUid, callback);
};
Groups.search = function(query, options, callback) {
if (!query || !query.length) {
return callback(null, []);
}
async.waterfall([
async.apply(db.getObjectValues, 'groupslug:groupname'),
function(groupNames, next) {
groupNames = groupNames.filter(function(name) {
return name.match(new RegExp(query, 'i'));
});
async.mapLimit(groupNames, 5, function(groupName, next) {
Groups.get(groupName, options || {}, next);
}, next);
}
], callback);
};
}(module.exports));

@ -126,6 +126,14 @@ SocketGroups.delete = function(socket, data, callback) {
});
};
SocketGroups.search = function(socket, data, callback) {
if (!data || !data.query) {
return callback(null, []);
}
groups.search(data.query, data.options || {}, callback);
};
SocketGroups.cover = {};
SocketGroups.cover.get = function(socket, data, callback) {

Loading…
Cancel
Save