Skip to content

Commit

Permalink
add removegroup function, gh Flotype#163
Browse files Browse the repository at this point in the history
  • Loading branch information
ericz committed Dec 27, 2011
1 parent 5af1217 commit 7e9ec90
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/handlers.js
Expand Up @@ -138,4 +138,20 @@ exports.initialize = function (nowjs) {
nowjs.on('groupdel', function (e) {
deleteVar(e, e.fqn);
});

nowjs.on('removegroup', function (name) {
if (nowUtil.hasProperty(this.groups, name)) {
var self = this;
// Get the actual group
group = this.getGroup(name);
group.getUsers(function(users){
users.map(function(user){
group.removeUser(user);
});
});
// Finally, delete the group itself.
delete this.groups[name];
}
});

};
23 changes: 23 additions & 0 deletions lib/now.js
Expand Up @@ -112,6 +112,29 @@ Now.prototype.getGroup = function (name) {
return this.groups[name];
};

/**
* @memberOf nowjs#
* @function
* @name removeGroup
* @description Removes all traces of a group.
* @param {String} name The name of the group to be retrieved.
* @type Group
* @example var new_group = nowjs.getGroup('a new group');
*/
Now.prototype.removeGroup = function (name) {
/**
* @name nowjs#removegroup
* @event
* @param {Group} group The group removed by {@link nowjs#getGroup}.
* @description Called when a group is removed.
* @example nowjs.on('removegroup', function (group) {
* console.log('Group `' + group.groupName + '` eliminated from existence.');
* });
*/
this.emit('removegroup', name);
};


/**
* @static
* @memberOf nowjs
Expand Down

0 comments on commit 7e9ec90

Please sign in to comment.