diff --git a/app/assets/javascripts/admin/controllers/admin_groups_controller.js b/app/assets/javascripts/admin/controllers/admin_groups_controller.js index e54ae33d2dd..bf0f47fb750 100644 --- a/app/assets/javascripts/admin/controllers/admin_groups_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_groups_controller.js @@ -1,5 +1,6 @@ Discourse.AdminGroupsController = Ember.Controller.extend({ itemController: 'adminGroup', + aliasLevels: null, actions: { edit: function(group){ diff --git a/app/assets/javascripts/admin/routes/admin_groups_routes.js b/app/assets/javascripts/admin/routes/admin_groups_routes.js index 0fea1c5020d..6db39d35a68 100644 --- a/app/assets/javascripts/admin/routes/admin_groups_routes.js +++ b/app/assets/javascripts/admin/routes/admin_groups_routes.js @@ -10,6 +10,11 @@ Discourse.AdminGroupsRoute = Discourse.Route.extend({ model: function() { return Discourse.Group.findAll(); + }, + + setupController: function(controller, model) { + controller.set('model', model); + controller.set('aliasLevelOptions', Discourse.Group.aliasLevelOptions()); } }); diff --git a/app/assets/javascripts/admin/templates/groups.js.handlebars b/app/assets/javascripts/admin/templates/groups.js.handlebars index ed19235f4b1..ce763e99bac 100644 --- a/app/assets/javascripts/admin/templates/groups.js.handlebars +++ b/app/assets/javascripts/admin/templates/groups.js.handlebars @@ -31,9 +31,9 @@
- +
- {{combobox valueAttribute="value" value=alias_level content=validValues}} + {{combobox valueAttribute="value" value=alias_level content=controller.aliasLevelOptions}}
diff --git a/app/assets/javascripts/admin/models/group.js b/app/assets/javascripts/discourse/models/group.js similarity index 64% rename from app/assets/javascripts/admin/models/group.js rename to app/assets/javascripts/discourse/models/group.js index fc979115c1d..7ab7c95e026 100644 --- a/app/assets/javascripts/admin/models/group.js +++ b/app/assets/javascripts/discourse/models/group.js @@ -1,15 +1,28 @@ +/** + The data model for a Group + + @class Group + @extends Discourse.Model + @namespace Discourse + @module Discourse +**/ +var ALIAS_LEVELS = { + nobody: 0, + only_admins: 1, + mods_and_admins: 2, + members_mods_and_admins: 3, + everyone: 99 + }, + aliasLevelOptions = [ + { name: I18n.t("groups.alias_levels.nobody"), value: ALIAS_LEVELS.nobody}, + { name: I18n.t("groups.alias_levels.mods_and_admins"), value: ALIAS_LEVELS.mods_and_admins}, + { name: I18n.t("groups.alias_levels.members_mods_and_admins"), value: ALIAS_LEVELS.members_mods_and_admins}, + { name: I18n.t("groups.alias_levels.everyone"), value: ALIAS_LEVELS.everyone} + ]; + Discourse.Group = Discourse.Model.extend({ loaded: false, - - ALIAS_LEVELS : { - "nobody": 0, - "only_admins": 1, - "mods_and_admins": 2, - "members_mods_and_admins": 3, - "everyone": 99 - }, - userCountDisplay: function(){ var c = this.get('user_count'); // don't display zero its ugly @@ -21,14 +34,14 @@ Discourse.Group = Discourse.Model.extend({ load: function() { var id = this.get('id'); if(id && !this.get('loaded')) { - var group = this; + var self = this; Discourse.ajax('/admin/groups/' + this.get('id') + '/users').then(function(payload){ var users = Em.A(); _.each(payload,function(user){ users.addObject(Discourse.User.create(user)); }); - group.set('users', users); - group.set('loaded', true); + self.set('users', users); + self.set('loaded', true); }); } }, @@ -44,35 +57,25 @@ Discourse.Group = Discourse.Model.extend({ return usernames; }.property('users'), - validValues: function() { - return Em.A([ - { name: I18n.t("admin.groups.alias_levels.nobody"), value: this.ALIAS_LEVELS.nobody}, - { name: I18n.t("admin.groups.alias_levels.only_admins"), value: this.ALIAS_LEVELS.only_admins}, - { name: I18n.t("admin.groups.alias_levels.mods_and_admins"), value: this.ALIAS_LEVELS.mods_and_admins}, - { name: I18n.t("admin.groups.alias_levels.members_mods_and_admins"), value: this.ALIAS_LEVELS.members_mods_and_admins}, - { name: I18n.t("admin.groups.alias_levels.everyone"), value: this.ALIAS_LEVELS.everyone} - ]); - }.property(), - destroy: function(){ if(!this.id) return; - var group = this; - group.set('disableSave', true); + var self = this; + this.set('disableSave', true); - return Discourse.ajax("/admin/groups/" + group.get('id'), {type: "DELETE"}) + return Discourse.ajax("/admin/groups/" + this.get('id'), {type: "DELETE"}) .then(function(){ return true; }, function() { - group.set('disableSave', false); + self.set('disableSave', false); bootbox.alert(I18n.t("admin.groups.delete_failed")); return false; }); }, create: function(){ - var group = this; - group.set('disableSave', true); + var self = this; + self.set('disableSave', true); return Discourse.ajax("/admin/groups", {type: "POST", data: { group: { @@ -81,10 +84,10 @@ Discourse.Group = Discourse.Model.extend({ usernames: this.get('usernames') } }}).then(function(resp) { - group.set('disableSave', false); - group.set('id', resp.id); + self.set('disableSave', false); + self.set('id', resp.id); }, function (error) { - group.set('disableSave', false); + self.set('disableSave', false); if (error && error.responseText) { bootbox.alert($.parseJSON(error.responseText).errors); } @@ -95,8 +98,8 @@ Discourse.Group = Discourse.Model.extend({ }, save: function(){ - var group = this; - group.set('disableSave', true); + var self = this; + self.set('disableSave', true); return Discourse.ajax("/admin/groups/" + this.get('id'), { type: "PUT", @@ -108,7 +111,7 @@ Discourse.Group = Discourse.Model.extend({ } } }).then(function(){ - group.set('disableSave', false); + self.set('disableSave', false); }, function(e){ var message = $.parseJSON(e.responseText).errors; bootbox.alert(message); @@ -128,5 +131,9 @@ Discourse.Group.reopenClass({ }); return list; + }, + + aliasLevelOptions: function() { + return aliasLevelOptions; } }); diff --git a/app/assets/javascripts/discourse/routes/group_route.js b/app/assets/javascripts/discourse/routes/group_route.js index ffaa4092389..04cba272587 100644 --- a/app/assets/javascripts/discourse/routes/group_route.js +++ b/app/assets/javascripts/discourse/routes/group_route.js @@ -1,7 +1,7 @@ Discourse.GroupRoute = Discourse.Route.extend({ model: function() { - return Discourse.AdminGroup.create(); + return Discourse.Group.create(); }, }); diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml index c0292426331..8ab65132b5f 100644 --- a/config/locales/client.de.yml +++ b/config/locales/client.de.yml @@ -172,6 +172,15 @@ de: sent_by_user: "Gesendet von {{user}}" sent_by_you: "Gesendet von dir" + groups: + alias_levels: + title: "Wer kann diese Gruppe als Alias verwenden?" + nobody: "Niemand" + only_admins: "Nur Administatoren" + mods_and_admins: "Nur Moderatoren und Administratoren" + members_mods_and_admins: "Nur Gruppenmitglieder, Moderatoren und Administratoren" + everyone: "Everyone" + user_action_groups: "1": "„Gefällt mir“ gegeben" "2": "„Gefällt mir“ erhalten" @@ -1259,13 +1268,6 @@ de: delete: "Löschen" delete_confirm: "Diese gruppe löschen?" delete_failed: "Gruppe konnte nicht gelöscht werden. Wenn dies eine automatische Gruppe ist, kann sie nicht gelöscht werden." - alias_levels: - title: "Wer kann diese Gruppe als Alias verwenden?" - nobody: "Niemand" - only_admins: "Nur Administatoren" - mods_and_admins: "Nur Moderatoren und Administratoren" - members_mods_and_admins: "Nur Gruppenmitglieder, Moderatoren und Administratoren" - everyone: "Everyone" api: generate_master: "Master API Key generieren" diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f81f8a84c4f..0e6a0d446d5 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -173,6 +173,15 @@ en: sent_by_user: "Sent by {{user}}" sent_by_you: "Sent by you" + groups: + alias_levels: + title: "Who can use this group as an alias?" + nobody: "Nobody" + only_admins: "Only admins" + mods_and_admins: "Only moderators and Admins" + members_mods_and_admins: "Only group members, moderators and admins" + everyone: "Everyone" + user_action_groups: "1": "Likes Given" "2": "Likes Received" @@ -1261,13 +1270,6 @@ en: delete: "Delete" delete_confirm: "Delete this group?" delete_failed: "Unable to delete group. If this is an automatic group, it cannot be destroyed." - alias_levels: - title: "Who can use this group as an alias?" - nobody: "Nobody" - only_admins: "Only admins" - mods_and_admins: "Only moderators and Admins" - members_mods_and_admins: "Only group members, moderators and admins" - everyone: "Everyone" api: generate_master: "Generate Master API Key" diff --git a/config/locales/client.nl.yml b/config/locales/client.nl.yml index 1e4c084479b..f59b6277941 100644 --- a/config/locales/client.nl.yml +++ b/config/locales/client.nl.yml @@ -175,6 +175,15 @@ nl: sent_by_user: "Verzonden door {{user}}" sent_by_you: "Verzonden door jou" + groups: + alias_levels: + title: "Wie kan deze groep als alias gebruiken?" + nobody: "Niemand" + only_admins: "Alleen admins" + mods_and_admins: "Alleen moderatoren and admins" + members_mods_and_admins: "Alleen leden van de groep, moderatoren en admins" + everyone: "Iedereen" + user_action_groups: "1": "Likes gegeven" "2": "Likes ontvangen" @@ -1241,13 +1250,6 @@ nl: delete: Verwijder delete_confirm: Verwijder deze groepen? delete_failed: "Unable to delete group. If this is an automatic group, it cannot be destroyed." - alias_levels: - title: "Wie kan deze groep als alias gebruiken?" - nobody: "Niemand" - only_admins: "Alleen admins" - mods_and_admins: "Alleen moderatoren and admins" - members_mods_and_admins: "Alleen leden van de groep, moderatoren en admins" - everyone: "Iedereen" api: generate_master: Genereer Master API Key diff --git a/config/locales/client.zh_CN.yml b/config/locales/client.zh_CN.yml index 44fb33e9be2..b86d04d11a4 100644 --- a/config/locales/client.zh_CN.yml +++ b/config/locales/client.zh_CN.yml @@ -171,6 +171,15 @@ zh_CN: sent_by_user: "发送人 {{user}}" sent_by_you: "发送人 " + groups: + alias_levels: + title: "谁能把组名作为别名?" + nobody: "无" + only_admins: "仅管理员" + mods_and_admins: "仅版主与管理员" + members_mods_and_admins: "仅组员、版主与管理员" + everyone: "任何人" + user_action_groups: "1": "给出的赞" "2": "收到的赞" @@ -1238,13 +1247,6 @@ zh_CN: delete: "删除" delete_confirm: "删除这个小组吗?" delete_failed: "无法删除小组。如果该小组是自动生成的,则不可删除。" - alias_levels: - title: "谁能把组名作为别名?" - nobody: "无" - only_admins: "仅管理员" - mods_and_admins: "仅版主与管理员" - members_mods_and_admins: "仅组员、版主与管理员" - everyone: "任何人" api: generate_master: "生成主API密钥"