mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Show number before trust level. Also use less memory for trust levels.
This commit is contained in:
parent
35128c212b
commit
62d161fd70
8 changed files with 54 additions and 15 deletions
|
@ -62,23 +62,17 @@ Discourse.AdminUser = Discourse.User.extend({
|
|||
return this.get('username').toLowerCase();
|
||||
}).property('username'),
|
||||
|
||||
trustLevel: function() {
|
||||
var site = Discourse.Site.instance();
|
||||
return site.get('trust_levels').findProperty('id', this.get('trust_level'));
|
||||
}.property('trust_level'),
|
||||
|
||||
setOriginalTrustLevel: function() {
|
||||
this.set('originalTrustLevel', this.get('trust_level'));
|
||||
},
|
||||
|
||||
trustLevels: function() {
|
||||
var site = Discourse.Site.instance();
|
||||
return site.get('trust_levels');
|
||||
return Discourse.Site.instance().get('trustLevels').map(function (tl) {
|
||||
return {id: tl.get('id'), name: tl.get('detailedName') };
|
||||
});
|
||||
}.property('trust_level'),
|
||||
|
||||
dirty: function() {
|
||||
return this.get('originalTrustLevel') !== parseInt(this.get('trustLevel.id'), 10);
|
||||
}.property('originalTrustLevel', 'trustLevel.id'),
|
||||
dirty: Discourse.computed.propertyNotEqual('originalTrustLevel', 'trustLevel.id'),
|
||||
|
||||
saveTrustLevel: function() {
|
||||
Discourse.ajax("/admin/users/" + this.id + "/trust_level", {
|
||||
|
|
|
@ -165,7 +165,7 @@
|
|||
<div class='display-row'>
|
||||
<div class='field'>{{i18n trust_level}}</div>
|
||||
<div class="value">
|
||||
{{combobox content=trustLevels value=trustLevel.id }}
|
||||
{{combobox content=trustLevels value=trust_level }}
|
||||
</div>
|
||||
<div class="controls">
|
||||
{{#if dirty}}
|
||||
|
|
|
@ -14,6 +14,20 @@ Discourse.computed = {
|
|||
}).property(p1, p2);
|
||||
},
|
||||
|
||||
/**
|
||||
Returns whether two properties are not equal to each other.
|
||||
|
||||
@method propertyNotEqual
|
||||
@params {String} p1 the first property
|
||||
@params {String} p2 the second property
|
||||
@return {Function} computedProperty function
|
||||
**/
|
||||
propertyNotEqual: function(p1, p2) {
|
||||
return Ember.computed(function() {
|
||||
return this.get(p1) !== this.get(p2);
|
||||
}).property(p1, p2);
|
||||
},
|
||||
|
||||
/**
|
||||
Uses an Ember String `fmt` call to format a string. See:
|
||||
http://emberjs.com/api/classes/Ember.String.html#method_fmt
|
||||
|
|
|
@ -49,11 +49,19 @@ Discourse.Site.reopenClass({
|
|||
return Discourse.Category.create(c);
|
||||
});
|
||||
}
|
||||
|
||||
if (result.trust_levels) {
|
||||
result.trustLevels = result.trust_levels.map(function (tl) {
|
||||
return Discourse.TrustLevel.create(tl);
|
||||
});
|
||||
|
||||
delete result.trust_levels;
|
||||
}
|
||||
|
||||
if (result.post_action_types) {
|
||||
result.postActionByIdLookup = Em.Object.create();
|
||||
result.post_action_types = _.map(result.post_action_types,function(p) {
|
||||
var actionType;
|
||||
actionType = Discourse.PostActionType.create(p);
|
||||
var actionType = Discourse.PostActionType.create(p);
|
||||
result.postActionByIdLookup.set("action" + p.id, actionType);
|
||||
return actionType;
|
||||
});
|
||||
|
|
11
app/assets/javascripts/discourse/models/trust_level.js
Normal file
11
app/assets/javascripts/discourse/models/trust_level.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
Represents a user's trust level in the system
|
||||
|
||||
@class TrustLevel
|
||||
@extends Discourse.Model
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.TrustLevel = Discourse.Model.extend({
|
||||
detailedName: Discourse.computed.fmt('id', 'name', '%@ - %@')
|
||||
});
|
|
@ -99,7 +99,7 @@ Discourse.User = Discourse.Model.extend({
|
|||
@type {Integer}
|
||||
**/
|
||||
trustLevel: function() {
|
||||
return Discourse.Site.instance().get('trust_levels').findProperty('id', this.get('trust_level'));
|
||||
return Discourse.Site.instance().get('trustLevels').findProperty('id', parseInt(this.get('trust_level'), 10));
|
||||
}.property('trust_level'),
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@ module("Discourse.Computed");
|
|||
|
||||
var testClass = Em.Object.extend({
|
||||
same: Discourse.computed.propertyEqual('cookies', 'biscuits'),
|
||||
diff: Discourse.computed.propertyNotEqual('cookies', 'biscuits'),
|
||||
exclaimyUsername: Discourse.computed.fmt('username', "!!! %@ !!!"),
|
||||
multiple: Discourse.computed.fmt('username', 'mood', "%@ is %@"),
|
||||
userUrl: Discourse.computed.url('username', "/users/%@")
|
||||
|
@ -14,11 +15,21 @@ test("propertyEqual", function() {
|
|||
});
|
||||
|
||||
ok(t.get('same'), "it is true when the properties are the same");
|
||||
|
||||
t.set('biscuits', 9);
|
||||
ok(!t.get('same'), "it isn't true when one property is different");
|
||||
});
|
||||
|
||||
test("propertyNotEqual", function() {
|
||||
var t = testClass.create({
|
||||
cookies: 10,
|
||||
biscuits: 10
|
||||
});
|
||||
|
||||
ok(!t.get('diff'), "it isn't true when the properties are the same");
|
||||
t.set('biscuits', 9);
|
||||
ok(t.get('diff'), "it is true when one property is different");
|
||||
});
|
||||
|
||||
|
||||
test("fmt", function() {
|
||||
var t = testClass.create({
|
||||
|
|
|
@ -7,5 +7,6 @@ test('instance', function(){
|
|||
present(site, "We have a current site singleton");
|
||||
present(site.get('categories'), "The instance has a list of categories");
|
||||
present(site.get('flagTypes'), "The instance has a list of flag types");
|
||||
present(site.get('trustLevels'), "The instance has a list of trust levels");
|
||||
|
||||
});
|
Loading…
Reference in a new issue