2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
Our data model for interacting with site settings.
|
|
|
|
|
2013-03-01 12:45:25 -05:00
|
|
|
@class SiteSetting
|
2013-02-22 15:41:12 -05:00
|
|
|
@extends Discourse.Model
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-03-01 12:45:25 -05:00
|
|
|
**/
|
2013-02-22 15:41:12 -05:00
|
|
|
Discourse.SiteSetting = Discourse.Model.extend({
|
2013-03-01 12:45:25 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Is the boolean setting true?
|
|
|
|
|
|
|
|
@property enabled
|
|
|
|
**/
|
|
|
|
enabled: function(key, value) {
|
|
|
|
|
|
|
|
if (arguments.length === 1) {
|
|
|
|
// get the boolean value of the setting
|
|
|
|
if (this.blank('value')) return false;
|
|
|
|
return this.get('value') === 'true';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// set the boolean value of the setting
|
|
|
|
this.set('value', value ? 'true' : 'false');
|
|
|
|
|
|
|
|
// We save booleans right away, it's not like a text field where it makes sense to
|
|
|
|
// undo what you typed in.
|
|
|
|
this.save();
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
|
2013-03-01 12:45:25 -05:00
|
|
|
}.property('value'),
|
|
|
|
|
|
|
|
/**
|
|
|
|
Has the user changed the setting? If so we should save it.
|
|
|
|
|
|
|
|
@property dirty
|
|
|
|
**/
|
|
|
|
dirty: function() {
|
|
|
|
return this.get('originalValue') !== this.get('value');
|
|
|
|
}.property('originalValue', 'value'),
|
|
|
|
|
|
|
|
/**
|
|
|
|
Has the setting been overridden from its default value?
|
|
|
|
|
|
|
|
@property overridden
|
|
|
|
**/
|
|
|
|
overridden: function() {
|
|
|
|
var val = this.get('value');
|
|
|
|
var defaultVal = this.get('default');
|
|
|
|
|
|
|
|
if (val === null) val = '';
|
|
|
|
if (defaultVal === null) defaultVal = '';
|
|
|
|
|
|
|
|
return val.toString() !== defaultVal.toString();
|
|
|
|
}.property('value'),
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reset the setting to its original value.
|
|
|
|
|
|
|
|
@method resetValue
|
|
|
|
**/
|
2013-02-22 15:41:12 -05:00
|
|
|
resetValue: function() {
|
|
|
|
this.set('value', this.get('originalValue'));
|
|
|
|
},
|
|
|
|
|
2013-03-01 12:45:25 -05:00
|
|
|
/**
|
|
|
|
Save the setting's value.
|
|
|
|
|
|
|
|
@method save
|
|
|
|
**/
|
2013-02-22 15:41:12 -05:00
|
|
|
save: function() {
|
|
|
|
// Update the setting
|
2013-03-01 12:45:25 -05:00
|
|
|
var setting = this;
|
2013-05-07 13:30:12 -04:00
|
|
|
return Discourse.ajax("/admin/site_settings/" + (this.get('setting')), {
|
2013-02-22 15:41:12 -05:00
|
|
|
data: { value: this.get('value') },
|
2013-04-03 16:06:55 -04:00
|
|
|
type: 'PUT'
|
|
|
|
}).then(function() {
|
|
|
|
setting.set('originalValue', setting.get('value'));
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
2013-06-11 11:39:55 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
validValues: function() {
|
2013-08-23 17:35:01 -04:00
|
|
|
var vals, setting;
|
2013-06-11 11:39:55 -04:00
|
|
|
vals = Em.A();
|
2013-08-23 17:35:01 -04:00
|
|
|
setting = this;
|
2013-06-11 14:23:52 -04:00
|
|
|
_.each(this.get('valid_values'), function(v) {
|
2013-08-23 17:35:01 -04:00
|
|
|
if (v.name && v.name.length > 0) {
|
|
|
|
if (setting.translate_names) {
|
|
|
|
vals.addObject({name: I18n.t(v.name), value: v.value});
|
|
|
|
} else {
|
|
|
|
vals.addObject(v);
|
|
|
|
}
|
|
|
|
}
|
2013-06-11 11:39:55 -04:00
|
|
|
});
|
|
|
|
return vals;
|
2013-06-11 14:23:52 -04:00
|
|
|
}.property('valid_values'),
|
|
|
|
|
|
|
|
allowsNone: function() {
|
|
|
|
if ( _.indexOf(this.get('valid_values'), '') >= 0 ) return 'admin.site_settings.none';
|
2013-06-11 11:39:55 -04:00
|
|
|
}.property('valid_values')
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
Discourse.SiteSetting.reopenClass({
|
2013-03-01 12:45:25 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieve all settings from the server
|
|
|
|
|
|
|
|
@method findAll
|
|
|
|
**/
|
2013-02-22 15:41:12 -05:00
|
|
|
findAll: function() {
|
2013-03-01 12:45:25 -05:00
|
|
|
var result = Em.A();
|
2013-05-07 13:30:12 -04:00
|
|
|
Discourse.ajax("/admin/site_settings").then(function (settings) {
|
2013-06-10 16:48:50 -04:00
|
|
|
_.each(settings.site_settings,function(s) {
|
2013-02-22 15:41:12 -05:00
|
|
|
s.originalValue = s.value;
|
2013-04-01 16:28:26 -04:00
|
|
|
result.pushObject(Discourse.SiteSetting.create(s));
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
2013-04-05 02:43:48 -04:00
|
|
|
result.set('diags', settings.diags);
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
return result;
|
2013-05-03 17:55:04 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
update: function(key, value) {
|
2013-05-07 13:30:12 -04:00
|
|
|
return Discourse.ajax("/admin/site_settings/" + key, {
|
2013-05-03 17:55:04 -04:00
|
|
|
type: 'PUT',
|
|
|
|
data: { value: value }
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
|
|
|
});
|
2013-02-20 13:15:50 -05:00
|
|
|
|
|
|
|
|