2013-03-01 12:45:25 -05:00
|
|
|
/**
|
|
|
|
A view to display a site setting with edit controls
|
|
|
|
|
|
|
|
@class SiteSettingView
|
|
|
|
@extends Discourse.View
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
|
|
|
**/
|
2014-02-16 12:53:18 -05:00
|
|
|
Discourse.SiteSettingView = Discourse.View.extend(Discourse.ScrollTop, {
|
2013-03-01 12:45:25 -05:00
|
|
|
classNameBindings: [':row', ':setting', 'content.overridden'],
|
|
|
|
|
2015-01-28 22:53:02 -05:00
|
|
|
preview: function() {
|
|
|
|
var preview = this.get('content.preview');
|
|
|
|
if(preview){
|
|
|
|
return new Handlebars.SafeString("<div class='preview'>" +
|
|
|
|
preview.replace("{{value}}",this.get('content.value')) +
|
|
|
|
"</div>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}.property('content.value'),
|
|
|
|
|
2013-03-01 12:45:25 -05:00
|
|
|
templateName: function() {
|
2014-03-30 01:32:33 -04:00
|
|
|
// If we're editing a boolean, show a checkbox
|
2013-06-11 11:39:55 -04:00
|
|
|
if (this.get('content.type') === 'bool') return 'admin/templates/site_settings/setting_bool';
|
|
|
|
|
|
|
|
// If we're editing an enum field, show a dropdown
|
2014-10-02 13:58:36 -04:00
|
|
|
if (this.get('content.type') === 'enum') return 'admin/templates/site_settings/setting_enum';
|
2013-03-01 12:45:25 -05:00
|
|
|
|
2014-03-30 01:32:33 -04:00
|
|
|
// If we're editing a list, show a list editor
|
2014-10-02 13:58:36 -04:00
|
|
|
if (this.get('content.type') === 'list') return 'admin/templates/site_settings/setting_list';
|
2014-03-30 01:32:33 -04:00
|
|
|
|
2013-03-01 12:45:25 -05:00
|
|
|
// Default to string editor
|
|
|
|
return 'admin/templates/site_settings/setting_string';
|
|
|
|
|
2014-07-11 14:44:30 -04:00
|
|
|
}.property('content.type'),
|
|
|
|
|
2014-07-15 17:32:27 -04:00
|
|
|
_watchEnterKey: function() {
|
2014-07-11 14:44:30 -04:00
|
|
|
var self = this;
|
2014-07-15 17:32:27 -04:00
|
|
|
this.$().on("keydown.site-setting-enter", ".input-setting-string", function (e) {
|
|
|
|
if (e.keyCode === 13) { // enter key
|
|
|
|
var setting = self.get('content');
|
|
|
|
if (setting.get('dirty')) {
|
|
|
|
setting.save();
|
2014-07-11 14:44:30 -04:00
|
|
|
}
|
2014-07-15 17:32:27 -04:00
|
|
|
}
|
2014-07-11 14:44:30 -04:00
|
|
|
});
|
2014-07-15 17:32:27 -04:00
|
|
|
}.on('didInsertElement'),
|
|
|
|
|
|
|
|
_removeBindings: function() {
|
|
|
|
this.$().off("keydown.site-setting-enter");
|
|
|
|
}.on("willDestroyElement")
|
2013-03-01 12:45:25 -05:00
|
|
|
|
|
|
|
});
|