group creation and deletion from outside ACP, #2588

v1.18.x
Julian Lam 10 years ago
parent 765975e667
commit 635393a274

@ -2,6 +2,8 @@
"groups": "Groups",
"view_group": "View Group",
"owner": "Group Owner",
"new_group": "Create New Group",
"no_groups_found": "There are no groups to see",
"details.title": "Group Details",
"details.members": "Member List",
@ -11,5 +13,8 @@
"details.private": "Private Group",
"details.public": "Public Group",
"details.owner_options": "Group Administration"
"details.owner_options": "Group Administration",
"event.updated": "Group details have been updated",
"event.deleted": "The group \"%1\" has been deleted"
}

@ -1,5 +1,5 @@
"use strict";
/* globals define, socket, ajaxify, app */
/* globals define, socket, ajaxify, app, bootbox */
define('forum/groups/details', ['iconSelect', 'vendor/colorpicker/colorpicker'], function(iconSelect) {
var Details = {};
@ -38,6 +38,10 @@ define('forum/groups/details', ['iconSelect', 'vendor/colorpicker/colorpicker'],
Details.update();
break;
case 'delete':
Details.deleteGroup();
break;
case 'join': // intentional fall-throughs!
case 'leave':
case 'accept':
@ -118,10 +122,33 @@ define('forum/groups/details', ['iconSelect', 'vendor/colorpicker/colorpicker'],
} else {
ajaxify.refresh();
}
app.alertSuccess('[[groups:event.updated');
});
});
}
};
Details.deleteGroup = function() {
bootbox.confirm('Are you sure you want to delete the group: ' + ajaxify.variables.get('group_name'), function(confirm) {
if (confirm) {
bootbox.prompt('Please enter the name of this group in order to delete it:', function(response) {
if (response === ajaxify.variables.get('group_name')) {
socket.emit('groups.delete', {
groupName: ajaxify.variables.get('group_name')
}, function(err) {
if (!err) {
app.alertSuccess('[[groups:event.deleted, ' + ajaxify.variables.get('group_name') + ']]');
ajaxify.go('groups');
} else {
app.alertError(err.message);
}
});
}
});
}
});
};
return Details;
});

@ -1,5 +1,5 @@
"use strict";
/* globals define, ajaxify, socket */
/* globals app, define, ajaxify, socket, bootbox */
define('forum/groups/list', function() {
var Groups = {};
@ -20,6 +20,23 @@ define('forum/groups/list', function() {
}
});
});
// Group creation
$('button[data-action="new"]').on('click', function() {
bootbox.prompt('Group Name:', function(name) {
if (name && name.length) {
socket.emit('groups.create', {
name: name
}, function(err) {
if (!err) {
ajaxify.go('groups/' + name);
} else {
app.alertError(err.message);
}
});
}
});
});
};
return Groups;

@ -386,7 +386,7 @@ var async = require('async'),
var groupData = {
name: data.name,
userTitle: data.name,
description: data.description,
description: data.description || '',
deleted: '0',
hidden: '0',
system: system ? '1' : '0',

@ -101,6 +101,17 @@ SocketGroups.update = function(socket, data, callback) {
});
};
SocketGroups.create = function(socket, data, callback) {
if(!data) {
return callback(new Error('[[error:invalid-data]]'));
} else if (socket.uid === 0) {
return callback(new Error('[[error:no-privileges]]'));
}
data.ownerUid = socket.uid;
groups.create(data, callback);
};
SocketGroups.delete = function(socket, data, callback) {
if(!data) {
return callback(new Error('[[error:invalid-data]]'));

Loading…
Cancel
Save