Fix deprecations in admin groups interface

This commit is contained in:
Robin Ward 2015-08-13 10:01:29 -04:00
parent a8d20c623f
commit 0442457e7b
8 changed files with 42 additions and 45 deletions

View File

@ -0,0 +1,9 @@
export default Ember.Component.extend({
classNames: ["item"],
actions: {
remove() {
this.sendAction('removeAction', this.get('member'));
}
}
});

View File

@ -6,14 +6,14 @@ export default Em.ObjectController.extend({
disableSave: false,
currentPage: function() {
if (this.get("user_count") === 0) { return 0; }
return Math.floor(this.get("offset") / this.get("limit")) + 1;
}.property("limit", "offset", "user_count"),
if (this.get("model.user_count") === 0) { return 0; }
return Math.floor(this.get("model.offset") / this.get("model.limit")) + 1;
}.property("model.limit", "model.offset", "model.user_count"),
totalPages: function() {
if (this.get("user_count") === 0) { return 0; }
return Math.floor(this.get("user_count") / this.get("limit")) + 1;
}.property("limit", "user_count"),
if (this.get("model.user_count") === 0) { return 0; }
return Math.floor(this.get("model.user_count") / this.get("model.limit")) + 1;
}.property("model.limit", "model.user_count"),
showingFirst: Em.computed.lte("currentPage", 1),
showingLast: propertyEqual("currentPage", "totalPages"),
@ -32,7 +32,7 @@ export default Em.ObjectController.extend({
if (this.get("showingLast")) { return; }
const group = this.get("model"),
offset = Math.min(group.get("offset") + group.get("limit"), group.get("user_count"));
offset = Math.min(group.get("offset") + group.get("model.limit"), group.get("user_count"));
group.set("offset", offset);
@ -43,7 +43,7 @@ export default Em.ObjectController.extend({
if (this.get("showingFirst")) { return; }
const group = this.get("model"),
offset = Math.max(group.get("offset") - group.get("limit"), 0);
offset = Math.max(group.get("offset") - group.get("model.limit"), 0);
group.set("offset", offset);
@ -52,7 +52,7 @@ export default Em.ObjectController.extend({
removeMember(member) {
const self = this,
message = I18n.t("admin.groups.delete_member_confirm", { username: member.get("username"), group: this.get("name") });
message = I18n.t("admin.groups.delete_member_confirm", { username: member.get("username"), group: this.get("model.name") });
return bootbox.confirm(message, I18n.t("no_value"), I18n.t("yes_value"), function(confirm) {
if (confirm) {
self.get("model").removeMember(member);
@ -61,10 +61,9 @@ export default Em.ObjectController.extend({
},
addMembers() {
if (Em.isEmpty(this.get("usernames"))) { return; }
this.get("model").addMembers(this.get("usernames"));
// clear the user selector
this.set("usernames", null);
if (Em.isEmpty(this.get("model.usernames"))) { return; }
this.get("model").addMembers(this.get("model.usernames")).catch(popupAjaxError);
this.set("model.usernames", null);
},
save() {

View File

@ -11,9 +11,7 @@ export default Discourse.Route.extend({
setupController: function(controller, model) {
controller.set("model", model);
// clear the user selector
controller.set("usernames", null);
// load the members of the group
controller.set("model.usernames", null);
model.findMembers();
}

View File

@ -0,0 +1 @@
<a href={{member.adminPath}}>{{avatar member imageSize="small"}}</a> {{member.username}} {{#unless automatic}}<a class='remove' {{action "remove"}}>{{fa-icon "times"}}</a>{{/unless}}

View File

@ -1,31 +1,33 @@
<form class="form-horizontal">
<div>
{{#if automatic}}
<h3>{{name}}</h3>
{{#if model.automatic}}
<h3>{{model.name}}</h3>
{{else}}
<label for="name">{{i18n 'admin.groups.name'}}</label>
{{text-field name="name" value=name placeholderKey="admin.groups.name_placeholder"}}
{{text-field name="name" value=model.name placeholderKey="admin.groups.name_placeholder"}}
{{/if}}
</div>
{{#if id}}
{{#if model.id}}
<div>
<label>{{i18n 'admin.groups.group_members'}} ({{user_count}})</label>
<label>{{i18n 'admin.groups.group_members'}} ({{model.user_count}})</label>
<div>
<a {{bind-attr class=":previous showingFirst:disabled"}} {{action "previous"}}>{{fa-icon "fast-backward"}}</a>
{{currentPage}}/{{totalPages}}
<a {{bind-attr class=":next showingLast:disabled"}} {{action "next"}}>{{fa-icon "fast-forward"}}</a>
</div>
<div class="ac-wrap clearfix">
{{each member in members itemView="group-member"}}
{{#each model.members as |member|}}
{{group-member member=member automatic=model.automatic removeAction="removeMember"}}
{{/each}}
</div>
</div>
{{#unless automatic}}
{{#unless model.automatic}}
<div>
<label for="user-selector">{{i18n 'admin.groups.add_members'}}</label>
{{user-selector usernames=usernames placeholderKey="admin.groups.selector_placeholder" id="user-selector"}}
{{user-selector usernames=model.usernames placeholderKey="admin.groups.selector_placeholder" id="user-selector"}}
<button {{action "addMembers"}} class='btn add'>{{fa-icon "plus"}} {{i18n 'admin.groups.add'}}</button>
</div>
{{/unless}}
@ -33,15 +35,15 @@
<div>
<label>
{{input type="checkbox" checked=visible}}
{{input type="checkbox" checked=model.visible}}
{{i18n 'groups.visible'}}
</label>
</div>
{{#unless automatic}}
{{#unless model.automatic}}
<div>
<label for="primary_group">
{{input type="checkbox" checked=primary_group}}
{{input type="checkbox" checked=model.primary_group}}
{{i18n 'admin.groups.primary_group'}}
</label>
</div>
@ -49,15 +51,15 @@
<div>
<label for="alias">{{i18n 'groups.alias_levels.title'}}</label>
{{combo-box name="alias" valueAttribute="value" value=alias_level content=aliasLevelOptions}}
{{combo-box name="alias" valueAttribute="value" value=model.alias_level content=aliasLevelOptions}}
</div>
{{#unless automatic}}
{{#unless model.automatic}}
<div>
<label for="automatic_membership">{{i18n 'admin.groups.automatic_membership_email_domains'}}</label>
{{list-setting name="automatic_membership" settingValue=emailDomains}}
{{list-setting name="automatic_membership" settingValue=model.emailDomains}}
<label>
{{input type="checkbox" checked=automatic_membership_retroactive}}
{{input type="checkbox" checked=model.automatic_membership_retroactive}}
{{i18n 'admin.groups.automatic_membership_retroactive'}}
</label>
</div>
@ -66,13 +68,13 @@
<label for="title">
{{i18n 'admin.groups.default_title'}}
</label>
{{input value=title}}
{{input value=model.title}}
</div>
{{/unless}}
<div class='buttons'>
<button {{action "save"}} {{bind-attr disabled="disableSave"}} class='btn btn-primary'>{{i18n 'admin.customize.save'}}</button>
{{#unless automatic}}
{{#unless model.automatic}}
<button {{action "destroy"}} class='btn btn-danger'>{{fa-icon "trash-o"}}{{i18n 'admin.customize.delete'}}</button>
{{/unless}}
</div>

View File

@ -1 +0,0 @@
<a href='{{unbound member.adminPath}}'>{{avatar member imageSize="small"}}</a> {{member.username}} {{#unless automatic}}<a class='remove' {{action "removeMember" member}}>{{fa-icon "times"}}</a>{{/unless}}

View File

@ -1,4 +0,0 @@
export default Discourse.View.extend({
classNames: ["item"],
templateName: "admin/templates/group_member"
});

View File

@ -50,14 +50,7 @@ const Group = Discourse.Model.extend({
type: "PUT",
data: { usernames: usernames }
}).then(function() {
// reload member list
self.findMembers();
}).catch(function(error) {
if (error && error.responseText) {
bootbox.alert($.parseJSON(error.responseText).errors[0]);
} else {
bootbox.alert(I18n.t('generic_error'));
}
});
},