UX: Show proper HTML for category preview in site settings

This commit is contained in:
Robin Ward 2017-08-04 13:56:27 -04:00
parent 58d452fc41
commit a3ef814245
2 changed files with 14 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import BufferedContent from 'discourse/mixins/buffered-content';
import SiteSetting from 'admin/models/site-setting'; import SiteSetting from 'admin/models/site-setting';
import { propertyNotEqual } from 'discourse/lib/computed'; import { propertyNotEqual } from 'discourse/lib/computed';
import computed from 'ember-addons/ember-computed-decorators'; import computed from 'ember-addons/ember-computed-decorators';
import { categoryLinkHTML } from 'discourse/helpers/category-link';
const CustomTypes = ['bool', 'enum', 'list', 'url_list', 'host_list', 'category_list', 'value_list']; const CustomTypes = ['bool', 'enum', 'list', 'url_list', 'host_list', 'category_list', 'value_list'];
@ -11,8 +12,19 @@ export default Ember.Component.extend(BufferedContent, {
dirty: propertyNotEqual('buffered.value', 'setting.value'), dirty: propertyNotEqual('buffered.value', 'setting.value'),
validationMessage: null, validationMessage: null,
@computed("setting.preview", "buffered.value") @computed("setting", "buffered.value")
preview(preview, value) { preview(setting, value) {
// A bit hacky, but allows us to use helpers
if (setting.get('setting') === 'category_style') {
let category = this.site.get('categories.firstObject');
if (category) {
return categoryLinkHTML(category, {
categoryStyle: value
});
}
}
let preview = setting.get('preview');
if (preview) { if (preview) {
return new Handlebars.SafeString("<div class='preview'>" + preview.replace(/\{\{value\}\}/g, value) + "</div>"); return new Handlebars.SafeString("<div class='preview'>" + preview.replace(/\{\{value\}\}/g, value) + "</div>");
} }

View File

@ -182,7 +182,6 @@ basic:
- bar - bar
- box - box
- bullet - bullet
preview: '<span class="badge-wrapper {{value}}"><span class="badge-category-parent-bg" style="background-color: #aaa;"></span><span class="badge-category-bg" style="background-color: #777;"></span><span style="color: #fff;" data-drop-close="true" class="badge-category clear-badge">Category</span></span>'
enable_mobile_theme: enable_mobile_theme:
client: true client: true
default: true default: true