2013-02-20 13:15:50 -05:00
|
|
|
(function() {
|
|
|
|
|
2013-02-21 14:09:28 -05:00
|
|
|
/**
|
|
|
|
Our data model for interacting with site settings.
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-02-21 14:09:28 -05:00
|
|
|
@class SiteCustomization
|
|
|
|
@extends Discourse.Model
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
|
|
|
**/
|
|
|
|
window.Discourse.SiteSetting = Discourse.Model.extend(Discourse.Presence, {
|
|
|
|
|
|
|
|
// Whether a property is short.
|
2013-02-20 13:15:50 -05:00
|
|
|
short: (function() {
|
2013-02-21 14:09:28 -05:00
|
|
|
if (this.blank('value')) return true;
|
2013-02-20 13:15:50 -05:00
|
|
|
return this.get('value').toString().length < 80;
|
|
|
|
}).property('value'),
|
|
|
|
|
2013-02-21 14:09:28 -05:00
|
|
|
// Whether the site setting has changed
|
2013-02-20 13:15:50 -05:00
|
|
|
dirty: (function() {
|
|
|
|
return this.get('originalValue') !== this.get('value');
|
|
|
|
}).property('originalValue', 'value'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-20 13:15:50 -05:00
|
|
|
overridden: (function() {
|
|
|
|
var defaultVal, val;
|
|
|
|
val = this.get('value');
|
|
|
|
defaultVal = this.get('default');
|
|
|
|
if (val && defaultVal) {
|
|
|
|
return val.toString() !== defaultVal.toString();
|
|
|
|
}
|
|
|
|
return val !== defaultVal;
|
|
|
|
}).property('value'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-20 13:15:50 -05:00
|
|
|
resetValue: function() {
|
2013-02-21 14:09:28 -05:00
|
|
|
this.set('value', this.get('originalValue'));
|
2013-02-20 13:15:50 -05:00
|
|
|
},
|
|
|
|
|
2013-02-21 14:09:28 -05:00
|
|
|
save: function() {
|
|
|
|
// Update the setting
|
2013-02-20 13:15:50 -05:00
|
|
|
var _this = this;
|
|
|
|
return jQuery.ajax("/admin/site_settings/" + (this.get('setting')), {
|
2013-02-21 14:09:28 -05:00
|
|
|
data: { value: this.get('value') },
|
2013-02-20 13:15:50 -05:00
|
|
|
type: 'PUT',
|
|
|
|
success: function() {
|
2013-02-21 14:09:28 -05:00
|
|
|
_this.set('originalValue', _this.get('value'));
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
window.Discourse.SiteSetting.reopenClass({
|
|
|
|
findAll: function() {
|
|
|
|
var result;
|
|
|
|
result = Em.A();
|
|
|
|
jQuery.get("/admin/site_settings", function(settings) {
|
|
|
|
return settings.each(function(s) {
|
|
|
|
s.originalValue = s.value;
|
|
|
|
return result.pushObject(Discourse.SiteSetting.create(s));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}).call(this);
|