diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js
index 90b063e0166..79cc831289a 100644
--- a/app/assets/javascripts/admin/models/admin_user.js
+++ b/app/assets/javascripts/admin/models/admin_user.js
@@ -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", {
diff --git a/app/assets/javascripts/admin/templates/user.js.handlebars b/app/assets/javascripts/admin/templates/user.js.handlebars
index e01e6402046..0690b6b2ea6 100644
--- a/app/assets/javascripts/admin/templates/user.js.handlebars
+++ b/app/assets/javascripts/admin/templates/user.js.handlebars
@@ -165,7 +165,7 @@
{{i18n trust_level}}
- {{combobox content=trustLevels value=trustLevel.id }}
+ {{combobox content=trustLevels value=trust_level }}
{{#if dirty}}
diff --git a/app/assets/javascripts/discourse/components/computed.js b/app/assets/javascripts/discourse/components/computed.js
index d3b7e7ff0b7..42d3bd228a0 100644
--- a/app/assets/javascripts/discourse/components/computed.js
+++ b/app/assets/javascripts/discourse/components/computed.js
@@ -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
diff --git a/app/assets/javascripts/discourse/models/site.js b/app/assets/javascripts/discourse/models/site.js
index 1913631934d..45c1d2c0965 100644
--- a/app/assets/javascripts/discourse/models/site.js
+++ b/app/assets/javascripts/discourse/models/site.js
@@ -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;
});
diff --git a/app/assets/javascripts/discourse/models/trust_level.js b/app/assets/javascripts/discourse/models/trust_level.js
new file mode 100644
index 00000000000..673077b4026
--- /dev/null
+++ b/app/assets/javascripts/discourse/models/trust_level.js
@@ -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', '%@ - %@')
+});
\ No newline at end of file
diff --git a/app/assets/javascripts/discourse/models/user.js b/app/assets/javascripts/discourse/models/user.js
index e1f1a580054..2e291c900c2 100644
--- a/app/assets/javascripts/discourse/models/user.js
+++ b/app/assets/javascripts/discourse/models/user.js
@@ -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'),
/**
diff --git a/test/javascripts/components/computed_test.js b/test/javascripts/components/computed_test.js
index 000ea5fd6a7..3367f317e48 100644
--- a/test/javascripts/components/computed_test.js
+++ b/test/javascripts/components/computed_test.js
@@ -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({
diff --git a/test/javascripts/models/site_test.js b/test/javascripts/models/site_test.js
index 7f08c211cbb..b0cdd42962a 100644
--- a/test/javascripts/models/site_test.js
+++ b/test/javascripts/models/site_test.js
@@ -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");
});
\ No newline at end of file