Add ability to run validation on site settings. notification_email and other email address settings are now validated.

This commit is contained in:
Neil Lalonde
2014-06-09 15:17:36 -04:00
parent 8e882ad145
commit c61462662b
10 changed files with 100 additions and 10 deletions

View File

@ -8,6 +8,8 @@
**/
Discourse.SiteSetting = Discourse.Model.extend({
validationMessage: null,
/**
Is the boolean setting true?
@ -67,6 +69,7 @@ Discourse.SiteSetting = Discourse.Model.extend({
**/
resetValue: function() {
this.set('value', this.get('originalValue'));
this.set('validationMessage', null);
},
/**
@ -76,13 +79,20 @@ Discourse.SiteSetting = Discourse.Model.extend({
**/
save: function() {
// Update the setting
var setting = this, data = {};
var self = this, data = {};
data[this.get('setting')] = this.get('value');
return Discourse.ajax("/admin/site_settings/" + this.get('setting'), {
data: data,
type: 'PUT'
}).then(function() {
setting.set('originalValue', setting.get('value'));
self.set('originalValue', self.get('value'));
self.set('validationMessage', null);
}, function(e) {
if (e.responseJSON && e.responseJSON.errors) {
self.set('validationMessage', e.responseJSON.errors[0]);
} else {
self.set('validationMessage', I18n.t('generic_error'));
}
});
},