diff --git a/public/src/admin/manage/groups.js b/public/src/admin/manage/groups.js index b2ae0c0afb..ed8cc59683 100644 --- a/public/src/admin/manage/groups.js +++ b/public/src/admin/manage/groups.js @@ -1,5 +1,5 @@ "use strict"; -/*global define, templates, socket, ajaxify, app, admin, bootbox*/ +/*global define, templates, socket, ajaxify, app, admin, bootbox, utils, config, translator */ define('admin/manage/groups', [ 'iconSelect', @@ -50,19 +50,13 @@ define('admin/manage/groups', [ socket.emit('admin.groups.create', submitObj, function(err) { 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; + if (err.hasOwnProperty('message') && utils.hasLanguageKey(err.message)) { + translator.translate(err.message, config.defaultLang, function(translated) { + createModalError.html(translated).removeClass('hide'); + }); + } else { + createModalError.html('Uh-OhThere was a problem creating your group. Please try again later!
').removeClass('hide'); } - - createModalError.html(errorText).removeClass('hide'); } else { createModalError.addClass('hide'); createGroupName.val(''); diff --git a/public/src/utils.js b/public/src/utils.js index 3b82573c9b..e0fef6151b 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -71,6 +71,7 @@ trimTrailingDash: /-$/g, trimLeadingDash: /^-/g, isLatin: /^[\w]+$/, + languageKeyRegex: /\[\[[\w]+:.+\]\]/, //http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/ slugify: function(str) { @@ -108,6 +109,10 @@ return !isNaN(parseFloat(n)) && isFinite(n); }, + hasLanguageKey: function(input) { + return utils.languageKeyRegex.test(input); + }, + // shallow objects merge merge: function() { var result = {}, obj, keys; diff --git a/src/groups.js b/src/groups.js index f82e452b96..2c0015d75a 100644 --- a/src/groups.js +++ b/src/groups.js @@ -43,20 +43,14 @@ var async = require('async'), return groups; } }, - getEphemeralGroup: function(groupName, options, callback) { - Groups.exists(groupName, function(err, exists) { - if (!err && exists) { - Groups.get.apply(null, arguments); - } else { - callback(null, { - name: groupName, - description: '', - deleted: '0', - hidden: '0', - system: '1' - }); - } - }); + getEphemeralGroup: function(groupName) { + return { + name: groupName, + description: '', + deleted: '0', + hidden: '0', + system: '1' + }; }, removeEphemeralGroups: function(groups) { var x = groups.length; @@ -95,6 +89,9 @@ var async = require('async'), }; Groups.get = function(groupName, options, callback) { + if (!arguments[0]) { + console.log(new Error.stack); + } var truncated = false, numUsers; @@ -103,7 +100,7 @@ var async = require('async'), if (ephemeralGroups.indexOf(groupName) === -1) { db.getObject('group:' + groupName, next); } else { - internals.getEphemeralGroup(groupName, options, next); + next(null, internals.getEphemeralGroup(groupName)); } }, users: function (next) { @@ -400,6 +397,11 @@ var async = require('async'), return utils.slugify(groupName); }); async.parallel([ + function(next) { + callback(null, slugs.map(function(slug) { + return ephemeralGroups.indexOf(slug) !== -1; + })); + }, async.apply(db.isObjectFields, 'groupslug:groupname', slugs), async.apply(db.isSortedSetMembers, 'groups:createtime', name) ], function(err, results) { @@ -407,17 +409,20 @@ var async = require('async'), return callback(err); } - callback(null, results.map(function(pair) { - return pair[0] || pair[1]; + callback(null, results.map(function(result) { + return result[0] || result[1] || result[2]; })); }); } else { var slug = utils.slugify(name); async.parallel([ + function(next) { + next(null, ephemeralGroups.indexOf(slug) !== -1); + }, async.apply(db.isObjectField, 'groupslug:groupname', slug), async.apply(db.isSortedSetMember, 'groups:createtime', name) ], function(err, results) { - callback(err, !err ? (results[0] || results[1]) : null); + callback(err, !err ? (results[0] || results[1] || results[2]) : null); }); } };