mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 22:39:36 +08:00
Don't display granted badges in the badge grant combobox.
This commit is contained in:
parent
fa6ff26061
commit
61ec2b390e
|
@ -13,6 +13,36 @@ Discourse.AdminUserBadgesController = Ember.ArrayController.extend({
|
||||||
sortProperties: ['granted_at'],
|
sortProperties: ['granted_at'],
|
||||||
sortAscending: false,
|
sortAscending: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
Array of badges that have not been granted to this user.
|
||||||
|
|
||||||
|
@property grantableBadges
|
||||||
|
@type {Boolean}
|
||||||
|
**/
|
||||||
|
grantableBadges: function() {
|
||||||
|
var granted = {};
|
||||||
|
this.get('model').forEach(function(userBadge) {
|
||||||
|
granted[userBadge.get('badge_id')] = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
var badges = [];
|
||||||
|
this.get('badges').forEach(function(badge) {
|
||||||
|
if (!granted[badge.get('id')]) {
|
||||||
|
badges.push(badge);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return badges;
|
||||||
|
}.property('badges.@each', 'model.@each'),
|
||||||
|
|
||||||
|
/**
|
||||||
|
Whether there are any badges that can be granted.
|
||||||
|
|
||||||
|
@property noBadges
|
||||||
|
@type {Boolean}
|
||||||
|
**/
|
||||||
|
noBadges: Em.computed.empty('grantableBadges'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +55,10 @@ Discourse.AdminUserBadgesController = Ember.ArrayController.extend({
|
||||||
var self = this;
|
var self = this;
|
||||||
Discourse.UserBadge.grant(badgeId, this.get('user.username')).then(function(userBadge) {
|
Discourse.UserBadge.grant(badgeId, this.get('user.username')).then(function(userBadge) {
|
||||||
self.pushObject(userBadge);
|
self.pushObject(userBadge);
|
||||||
|
Ember.run.next(function() {
|
||||||
|
// Update the selected badge ID after the combobox has re-rendered.
|
||||||
|
self.set('selectedBadgeId', self.get('grantableBadges')[0].get('id'));
|
||||||
|
});
|
||||||
}, function() {
|
}, function() {
|
||||||
// Failure
|
// Failure
|
||||||
bootbox.alert(I18n.t('generic_error'));
|
bootbox.alert(I18n.t('generic_error'));
|
||||||
|
|
|
@ -19,9 +19,10 @@ Discourse.AdminUserBadgesRoute = Discourse.Route.extend({
|
||||||
Discourse.Badge.findAll().then(function(badges) {
|
Discourse.Badge.findAll().then(function(badges) {
|
||||||
controller.set('badges', badges);
|
controller.set('badges', badges);
|
||||||
if (badges.length > 0) {
|
if (badges.length > 0) {
|
||||||
controller.set('selectedBadgeId', badges[0].get('id'));
|
var grantableBadges = controller.get('grantableBadges');
|
||||||
} else {
|
if (grantableBadges.length > 0) {
|
||||||
controller.set('noBadges', true);
|
controller.set('selectedBadgeId', grantableBadges[0].get('id'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
controller.set('loading', false);
|
controller.set('loading', false);
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<p>{{i18n admin.badges.no_badges}}</p>
|
<p>{{i18n admin.badges.no_badges}}</p>
|
||||||
{{else}}
|
{{else}}
|
||||||
<br>
|
<br>
|
||||||
{{combobox valueAttribute="id" value=controller.selectedBadgeId content=controller.badges}}
|
{{combobox valueAttribute="id" value=controller.selectedBadgeId content=controller.grantableBadges}}
|
||||||
<button class='btn btn-primary' {{action grantBadge controller.selectedBadgeId}}>{{i18n admin.badges.grant}}</button>
|
<button class='btn btn-primary' {{action grantBadge controller.selectedBadgeId}}>{{i18n admin.badges.grant}}</button>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user