Front end mods to use combobox for selecting user's trust level

This commit is contained in:
Navin 2013-07-01 16:22:21 +02:00
parent 4d4a5735d2
commit f92d9cec47
2 changed files with 44 additions and 1 deletions

View File

@ -64,9 +64,40 @@ Discourse.AdminUser = Discourse.User.extend({
trustLevel: function() {
var site = Discourse.Site.instance();
this.set('originalValue', this.get('trust_level'));
return site.get('trust_levels').findProperty('id', this.get('trust_level'));
}.property('trust_level'),
trustLevels: function() {
var site = Discourse.Site.instance();
// downgrading trust levels is not supported
var current = this.get('trust_level');
var levels = site.get('trust_levels');
return jQuery.grep(levels, function(e) { return e.id >= current })
}.property('trust_level'),
dirty: function() {
return this.get('originalValue') !== parseInt(this.get('trustLevel.id'), 10);
}.property('originalValue', 'trustLevel.id'),
saveTrustLevel: function() {
Discourse.ajax("/admin/users/" + this.id + "/trust_level", {
type: 'PUT',
data: {level: this.get('trustLevel.id')}
}).then(function () {
// succeeded
window.location.reload();
}, function(e) {
// failure
var error = Em.String.i18n('admin.user.trustlevel_change_failed', { error: "http: " + e.status + " - " + e.body });
bootbox.alert(error);
});
},
restoreTrustLevel: function() {
this.set('trustLevel.id', this.get('originalValue'));
},
isBanned: (function() {
return this.get('is_banned') === true;
}).property('is_banned'),

View File

@ -161,10 +161,22 @@
</div>
</div>
<div class='display-row'>
<div class='field'>{{i18n trust_level}}</div>
<div class='value'>{{trustLevel.name}}</div>
<div class="value">
{{combobox content=trustLevels value=trustLevel.id }}
</div>
<div class="controls">
{{#if dirty}}
<div>
<button class='btn ok' {{action saveTrustLevel target="content"}}><i class='icon-ok'></i></button>
<button class='btn cancel' {{action restoreTrustLevel target="content"}}><i class='icon-remove'></i></button>
</div>
{{/if}}
</div>
</div>
<div class='display-row'>
<div class='field'>{{i18n admin.user.banned}}</div>
<div class='value'>{{isBanned}}</div>