define(function() { var Groups = {}; Groups.init = function() { var yourid = templates.get('yourid'), createEl = $('#create'), createModal = $('#create-modal'), createSubmitBtn = $('#create-modal-go'), createNameEl = $('#create-group-name'), detailsModal = $('#group-details-modal'), detailsSearch = detailsModal.find('#group-details-search'), searchResults = detailsModal.find('#group-details-search-results'), groupMembersEl = detailsModal.find('ul.current_members'), detailsModalSave = detailsModal.find('.btn-primary'), searchDelay = undefined, listEl = $('#groups-list'); createEl.on('click', function() { createModal.modal('show'); setTimeout(function() { createNameEl.focus(); }, 250); }); createSubmitBtn.on('click', function() { var submitObj = { name: createNameEl.val(), description: $('#create-group-desc').val() }, errorEl = $('#create-modal-error'), errorText; socket.emit('admin.groups.create', submitObj, function(err, data) { if (err) { switch (err) { case 'group-exists': errorText = 'Please choose another name
There seems to be a group with this name already.
'; break; case 'name-too-short': errorText = 'Please specify a group nameA group name is required for administrative purposes.
'; break; default: errorText = 'Uh-OhThere was a problem creating your group. Please try again later!
'; break; } errorEl.html(errorText).removeClass('hide'); } else { errorEl.addClass('hide'); createNameEl.val(''); createModal.on('hidden.bs.modal', function() { ajaxify.go('admin/groups'); }); createModal.modal('hide'); } }); }); listEl.on('click', 'button[data-action]', function() { var el = $(this), action = el.attr('data-action'), gid = el.parents('li[data-gid]').attr('data-gid'); switch (action) { case 'delete': bootbox.confirm('Are you sure you wish to delete this group?', function(confirm) { if (confirm) { socket.emit('admin.groups.delete', gid, function(err, data) { console.log(err, data); if(err) { return app.alertError(err.message); } ajaxify.go('admin/groups'); }); } }); break; case 'members': socket.emit('admin.groups.get', gid, function(err, groupObj) { var formEl = detailsModal.find('form'), nameEl = formEl.find('#change-group-name'), descEl = formEl.find('#change-group-desc'), numMembers = groupObj.members.length, x; nameEl.val(groupObj.name); descEl.val(groupObj.description); if (numMembers > 0) { groupMembersEl.empty(); for (x = 0; x < numMembers; x++) { var memberIcon = $('') .attr('data-uid', groupObj.members[x].uid) .append($('