mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 00:06:04 +08:00
Show number before trust level. Also use less memory for trust levels.
This commit is contained in:
parent
35128c212b
commit
62d161fd70
@ -62,23 +62,17 @@ Discourse.AdminUser = Discourse.User.extend({
|
|||||||
return this.get('username').toLowerCase();
|
return this.get('username').toLowerCase();
|
||||||
}).property('username'),
|
}).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() {
|
setOriginalTrustLevel: function() {
|
||||||
this.set('originalTrustLevel', this.get('trust_level'));
|
this.set('originalTrustLevel', this.get('trust_level'));
|
||||||
},
|
},
|
||||||
|
|
||||||
trustLevels: function() {
|
trustLevels: function() {
|
||||||
var site = Discourse.Site.instance();
|
return Discourse.Site.instance().get('trustLevels').map(function (tl) {
|
||||||
return site.get('trust_levels');
|
return {id: tl.get('id'), name: tl.get('detailedName') };
|
||||||
|
});
|
||||||
}.property('trust_level'),
|
}.property('trust_level'),
|
||||||
|
|
||||||
dirty: function() {
|
dirty: Discourse.computed.propertyNotEqual('originalTrustLevel', 'trustLevel.id'),
|
||||||
return this.get('originalTrustLevel') !== parseInt(this.get('trustLevel.id'), 10);
|
|
||||||
}.property('originalTrustLevel', 'trustLevel.id'),
|
|
||||||
|
|
||||||
saveTrustLevel: function() {
|
saveTrustLevel: function() {
|
||||||
Discourse.ajax("/admin/users/" + this.id + "/trust_level", {
|
Discourse.ajax("/admin/users/" + this.id + "/trust_level", {
|
||||||
|
@ -165,7 +165,7 @@
|
|||||||
<div class='display-row'>
|
<div class='display-row'>
|
||||||
<div class='field'>{{i18n trust_level}}</div>
|
<div class='field'>{{i18n trust_level}}</div>
|
||||||
<div class="value">
|
<div class="value">
|
||||||
{{combobox content=trustLevels value=trustLevel.id }}
|
{{combobox content=trustLevels value=trust_level }}
|
||||||
</div>
|
</div>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{#if dirty}}
|
{{#if dirty}}
|
||||||
|
@ -14,6 +14,20 @@ Discourse.computed = {
|
|||||||
}).property(p1, p2);
|
}).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:
|
Uses an Ember String `fmt` call to format a string. See:
|
||||||
http://emberjs.com/api/classes/Ember.String.html#method_fmt
|
http://emberjs.com/api/classes/Ember.String.html#method_fmt
|
||||||
|
@ -49,11 +49,19 @@ Discourse.Site.reopenClass({
|
|||||||
return Discourse.Category.create(c);
|
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) {
|
if (result.post_action_types) {
|
||||||
result.postActionByIdLookup = Em.Object.create();
|
result.postActionByIdLookup = Em.Object.create();
|
||||||
result.post_action_types = _.map(result.post_action_types,function(p) {
|
result.post_action_types = _.map(result.post_action_types,function(p) {
|
||||||
var actionType;
|
var actionType = Discourse.PostActionType.create(p);
|
||||||
actionType = Discourse.PostActionType.create(p);
|
|
||||||
result.postActionByIdLookup.set("action" + p.id, actionType);
|
result.postActionByIdLookup.set("action" + p.id, actionType);
|
||||||
return 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}
|
@type {Integer}
|
||||||
**/
|
**/
|
||||||
trustLevel: function() {
|
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'),
|
}.property('trust_level'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,7 @@ module("Discourse.Computed");
|
|||||||
|
|
||||||
var testClass = Em.Object.extend({
|
var testClass = Em.Object.extend({
|
||||||
same: Discourse.computed.propertyEqual('cookies', 'biscuits'),
|
same: Discourse.computed.propertyEqual('cookies', 'biscuits'),
|
||||||
|
diff: Discourse.computed.propertyNotEqual('cookies', 'biscuits'),
|
||||||
exclaimyUsername: Discourse.computed.fmt('username', "!!! %@ !!!"),
|
exclaimyUsername: Discourse.computed.fmt('username', "!!! %@ !!!"),
|
||||||
multiple: Discourse.computed.fmt('username', 'mood', "%@ is %@"),
|
multiple: Discourse.computed.fmt('username', 'mood', "%@ is %@"),
|
||||||
userUrl: Discourse.computed.url('username', "/users/%@")
|
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");
|
ok(t.get('same'), "it is true when the properties are the same");
|
||||||
|
|
||||||
t.set('biscuits', 9);
|
t.set('biscuits', 9);
|
||||||
ok(!t.get('same'), "it isn't true when one property is different");
|
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() {
|
test("fmt", function() {
|
||||||
var t = testClass.create({
|
var t = testClass.create({
|
||||||
|
@ -7,5 +7,6 @@ test('instance', function(){
|
|||||||
present(site, "We have a current site singleton");
|
present(site, "We have a current site singleton");
|
||||||
present(site.get('categories'), "The instance has a list of categories");
|
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('flagTypes'), "The instance has a list of flag types");
|
||||||
|
present(site.get('trustLevels'), "The instance has a list of trust levels");
|
||||||
|
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user