Move `Discourse.Group` into public models
This commit is contained in:
parent
de57f29467
commit
003eb06807
|
@ -1,5 +1,6 @@
|
||||||
Discourse.AdminGroupsController = Ember.Controller.extend({
|
Discourse.AdminGroupsController = Ember.Controller.extend({
|
||||||
itemController: 'adminGroup',
|
itemController: 'adminGroup',
|
||||||
|
aliasLevels: null,
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
edit: function(group){
|
edit: function(group){
|
||||||
|
|
|
@ -10,6 +10,11 @@ Discourse.AdminGroupsRoute = Discourse.Route.extend({
|
||||||
|
|
||||||
model: function() {
|
model: function() {
|
||||||
return Discourse.Group.findAll();
|
return Discourse.Group.findAll();
|
||||||
|
},
|
||||||
|
|
||||||
|
setupController: function(controller, model) {
|
||||||
|
controller.set('model', model);
|
||||||
|
controller.set('aliasLevelOptions', Discourse.Group.aliasLevelOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,9 +31,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">{{i18n admin.groups.alias_levels.title}}</label>
|
<label class="control-label">{{i18n groups.alias_levels.title}}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{combobox valueAttribute="value" value=alias_level content=validValues}}
|
{{combobox valueAttribute="value" value=alias_level content=controller.aliasLevelOptions}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='controls'>
|
<div class='controls'>
|
||||||
|
|
|
@ -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({
|
Discourse.Group = Discourse.Model.extend({
|
||||||
loaded: false,
|
loaded: false,
|
||||||
|
|
||||||
|
|
||||||
ALIAS_LEVELS : {
|
|
||||||
"nobody": 0,
|
|
||||||
"only_admins": 1,
|
|
||||||
"mods_and_admins": 2,
|
|
||||||
"members_mods_and_admins": 3,
|
|
||||||
"everyone": 99
|
|
||||||
},
|
|
||||||
|
|
||||||
userCountDisplay: function(){
|
userCountDisplay: function(){
|
||||||
var c = this.get('user_count');
|
var c = this.get('user_count');
|
||||||
// don't display zero its ugly
|
// don't display zero its ugly
|
||||||
|
@ -21,14 +34,14 @@ Discourse.Group = Discourse.Model.extend({
|
||||||
load: function() {
|
load: function() {
|
||||||
var id = this.get('id');
|
var id = this.get('id');
|
||||||
if(id && !this.get('loaded')) {
|
if(id && !this.get('loaded')) {
|
||||||
var group = this;
|
var self = this;
|
||||||
Discourse.ajax('/admin/groups/' + this.get('id') + '/users').then(function(payload){
|
Discourse.ajax('/admin/groups/' + this.get('id') + '/users').then(function(payload){
|
||||||
var users = Em.A();
|
var users = Em.A();
|
||||||
_.each(payload,function(user){
|
_.each(payload,function(user){
|
||||||
users.addObject(Discourse.User.create(user));
|
users.addObject(Discourse.User.create(user));
|
||||||
});
|
});
|
||||||
group.set('users', users);
|
self.set('users', users);
|
||||||
group.set('loaded', true);
|
self.set('loaded', true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -44,35 +57,25 @@ Discourse.Group = Discourse.Model.extend({
|
||||||
return usernames;
|
return usernames;
|
||||||
}.property('users'),
|
}.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(){
|
destroy: function(){
|
||||||
if(!this.id) return;
|
if(!this.id) return;
|
||||||
|
|
||||||
var group = this;
|
var self = this;
|
||||||
group.set('disableSave', true);
|
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(){
|
.then(function(){
|
||||||
return true;
|
return true;
|
||||||
}, function() {
|
}, function() {
|
||||||
group.set('disableSave', false);
|
self.set('disableSave', false);
|
||||||
bootbox.alert(I18n.t("admin.groups.delete_failed"));
|
bootbox.alert(I18n.t("admin.groups.delete_failed"));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
create: function(){
|
create: function(){
|
||||||
var group = this;
|
var self = this;
|
||||||
group.set('disableSave', true);
|
self.set('disableSave', true);
|
||||||
|
|
||||||
return Discourse.ajax("/admin/groups", {type: "POST", data: {
|
return Discourse.ajax("/admin/groups", {type: "POST", data: {
|
||||||
group: {
|
group: {
|
||||||
|
@ -81,10 +84,10 @@ Discourse.Group = Discourse.Model.extend({
|
||||||
usernames: this.get('usernames')
|
usernames: this.get('usernames')
|
||||||
}
|
}
|
||||||
}}).then(function(resp) {
|
}}).then(function(resp) {
|
||||||
group.set('disableSave', false);
|
self.set('disableSave', false);
|
||||||
group.set('id', resp.id);
|
self.set('id', resp.id);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
group.set('disableSave', false);
|
self.set('disableSave', false);
|
||||||
if (error && error.responseText) {
|
if (error && error.responseText) {
|
||||||
bootbox.alert($.parseJSON(error.responseText).errors);
|
bootbox.alert($.parseJSON(error.responseText).errors);
|
||||||
}
|
}
|
||||||
|
@ -95,8 +98,8 @@ Discourse.Group = Discourse.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
save: function(){
|
save: function(){
|
||||||
var group = this;
|
var self = this;
|
||||||
group.set('disableSave', true);
|
self.set('disableSave', true);
|
||||||
|
|
||||||
return Discourse.ajax("/admin/groups/" + this.get('id'), {
|
return Discourse.ajax("/admin/groups/" + this.get('id'), {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
|
@ -108,7 +111,7 @@ Discourse.Group = Discourse.Model.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).then(function(){
|
}).then(function(){
|
||||||
group.set('disableSave', false);
|
self.set('disableSave', false);
|
||||||
}, function(e){
|
}, function(e){
|
||||||
var message = $.parseJSON(e.responseText).errors;
|
var message = $.parseJSON(e.responseText).errors;
|
||||||
bootbox.alert(message);
|
bootbox.alert(message);
|
||||||
|
@ -128,5 +131,9 @@ Discourse.Group.reopenClass({
|
||||||
});
|
});
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
},
|
||||||
|
|
||||||
|
aliasLevelOptions: function() {
|
||||||
|
return aliasLevelOptions;
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -1,7 +1,7 @@
|
||||||
Discourse.GroupRoute = Discourse.Route.extend({
|
Discourse.GroupRoute = Discourse.Route.extend({
|
||||||
|
|
||||||
model: function() {
|
model: function() {
|
||||||
return Discourse.AdminGroup.create();
|
return Discourse.Group.create();
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -172,6 +172,15 @@ de:
|
||||||
sent_by_user: "Gesendet von <a href='{{userUrl}}'>{{user}}</a>"
|
sent_by_user: "Gesendet von <a href='{{userUrl}}'>{{user}}</a>"
|
||||||
sent_by_you: "Gesendet von <a href='{{userUrl}}'>dir</a>"
|
sent_by_you: "Gesendet von <a href='{{userUrl}}'>dir</a>"
|
||||||
|
|
||||||
|
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:
|
user_action_groups:
|
||||||
"1": "„Gefällt mir“ gegeben"
|
"1": "„Gefällt mir“ gegeben"
|
||||||
"2": "„Gefällt mir“ erhalten"
|
"2": "„Gefällt mir“ erhalten"
|
||||||
|
@ -1259,13 +1268,6 @@ de:
|
||||||
delete: "Löschen"
|
delete: "Löschen"
|
||||||
delete_confirm: "Diese gruppe 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."
|
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:
|
api:
|
||||||
generate_master: "Master API Key generieren"
|
generate_master: "Master API Key generieren"
|
||||||
|
|
|
@ -173,6 +173,15 @@ en:
|
||||||
sent_by_user: "Sent by <a href='{{userUrl}}'>{{user}}</a>"
|
sent_by_user: "Sent by <a href='{{userUrl}}'>{{user}}</a>"
|
||||||
sent_by_you: "Sent by <a href='{{userUrl}}'>you</a>"
|
sent_by_you: "Sent by <a href='{{userUrl}}'>you</a>"
|
||||||
|
|
||||||
|
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:
|
user_action_groups:
|
||||||
"1": "Likes Given"
|
"1": "Likes Given"
|
||||||
"2": "Likes Received"
|
"2": "Likes Received"
|
||||||
|
@ -1261,13 +1270,6 @@ en:
|
||||||
delete: "Delete"
|
delete: "Delete"
|
||||||
delete_confirm: "Delete this group?"
|
delete_confirm: "Delete this group?"
|
||||||
delete_failed: "Unable to delete group. If this is an automatic group, it cannot be destroyed."
|
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:
|
api:
|
||||||
generate_master: "Generate Master API Key"
|
generate_master: "Generate Master API Key"
|
||||||
|
|
|
@ -175,6 +175,15 @@ nl:
|
||||||
sent_by_user: "Verzonden door <a href='{{userUrl}}'>{{user}}</a>"
|
sent_by_user: "Verzonden door <a href='{{userUrl}}'>{{user}}</a>"
|
||||||
sent_by_you: "Verzonden door <a href='{{userUrl}}'>jou</a>"
|
sent_by_you: "Verzonden door <a href='{{userUrl}}'>jou</a>"
|
||||||
|
|
||||||
|
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:
|
user_action_groups:
|
||||||
"1": "Likes gegeven"
|
"1": "Likes gegeven"
|
||||||
"2": "Likes ontvangen"
|
"2": "Likes ontvangen"
|
||||||
|
@ -1241,13 +1250,6 @@ nl:
|
||||||
delete: Verwijder
|
delete: Verwijder
|
||||||
delete_confirm: Verwijder deze groepen?
|
delete_confirm: Verwijder deze groepen?
|
||||||
delete_failed: "Unable to delete group. If this is an automatic group, it cannot be destroyed."
|
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:
|
api:
|
||||||
generate_master: Genereer Master API Key
|
generate_master: Genereer Master API Key
|
||||||
|
|
|
@ -171,6 +171,15 @@ zh_CN:
|
||||||
sent_by_user: "发送人 <a href='{{userUrl}}'>{{user}}</a>"
|
sent_by_user: "发送人 <a href='{{userUrl}}'>{{user}}</a>"
|
||||||
sent_by_you: "发送人 <a href='{{userUrl}}'>你</a>"
|
sent_by_you: "发送人 <a href='{{userUrl}}'>你</a>"
|
||||||
|
|
||||||
|
groups:
|
||||||
|
alias_levels:
|
||||||
|
title: "谁能把组名作为别名?"
|
||||||
|
nobody: "无"
|
||||||
|
only_admins: "仅管理员"
|
||||||
|
mods_and_admins: "仅版主与管理员"
|
||||||
|
members_mods_and_admins: "仅组员、版主与管理员"
|
||||||
|
everyone: "任何人"
|
||||||
|
|
||||||
user_action_groups:
|
user_action_groups:
|
||||||
"1": "给出的赞"
|
"1": "给出的赞"
|
||||||
"2": "收到的赞"
|
"2": "收到的赞"
|
||||||
|
@ -1238,13 +1247,6 @@ zh_CN:
|
||||||
delete: "删除"
|
delete: "删除"
|
||||||
delete_confirm: "删除这个小组吗?"
|
delete_confirm: "删除这个小组吗?"
|
||||||
delete_failed: "无法删除小组。如果该小组是自动生成的,则不可删除。"
|
delete_failed: "无法删除小组。如果该小组是自动生成的,则不可删除。"
|
||||||
alias_levels:
|
|
||||||
title: "谁能把组名作为别名?"
|
|
||||||
nobody: "无"
|
|
||||||
only_admins: "仅管理员"
|
|
||||||
mods_and_admins: "仅版主与管理员"
|
|
||||||
members_mods_and_admins: "仅组员、版主与管理员"
|
|
||||||
everyone: "任何人"
|
|
||||||
|
|
||||||
api:
|
api:
|
||||||
generate_master: "生成主API密钥"
|
generate_master: "生成主API密钥"
|
||||||
|
|
Loading…
Reference in New Issue