mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 23:21:48 +08:00
add site_setting choices
- add site_setting choices lists to list entries - allows for handy autocompletion using the new select2.js UI - automatically merges plugin choices into existing list, allowing for easy extension
This commit is contained in:
@ -42,6 +42,10 @@ module SiteSettingExtension
|
||||
@lists ||= []
|
||||
end
|
||||
|
||||
def choices
|
||||
@choices ||= {}
|
||||
end
|
||||
|
||||
def hidden_settings
|
||||
@hidden_settings ||= []
|
||||
end
|
||||
@ -60,6 +64,11 @@ module SiteSettingExtension
|
||||
enum = opts[:enum]
|
||||
enums[name] = enum.is_a?(String) ? enum.constantize : enum
|
||||
end
|
||||
if opts[:choices]
|
||||
choices.has_key?(name) ?
|
||||
choices[name].concat(opts[:choices]) :
|
||||
choices[name] = opts[:choices]
|
||||
end
|
||||
if opts[:list]
|
||||
lists << name
|
||||
end
|
||||
@ -111,12 +120,16 @@ module SiteSettingExtension
|
||||
.map do |s, v|
|
||||
value = send(s)
|
||||
type = types[get_data_type(s, value)]
|
||||
{setting: s,
|
||||
opts = {setting: s,
|
||||
description: description(s),
|
||||
default: v,
|
||||
type: type.to_s,
|
||||
value: value.to_s,
|
||||
category: categories[s]}.merge( type == :enum ? {valid_values: enum_class(s).values, translate_names: enum_class(s).translate_names?} : {})
|
||||
category: categories[s]
|
||||
}
|
||||
opts.merge({valid_values: enum_class(s).values, translate_names: enum_class(s).translate_names?}) if type == :enum
|
||||
opts[:choices] = choices[s] if choices.has_key? s
|
||||
opts
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user