mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Wizard - Color Scheme Step
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class Wizard
|
||||
class Field
|
||||
|
||||
attr_reader :id, :type, :required, :value, :options
|
||||
attr_reader :id, :type, :required, :value, :options, :option_data
|
||||
attr_accessor :step
|
||||
|
||||
def initialize(attrs)
|
||||
@@ -12,10 +12,12 @@ class Wizard
|
||||
@required = !!attrs[:required]
|
||||
@value = attrs[:value]
|
||||
@options = []
|
||||
@option_data = {}
|
||||
end
|
||||
|
||||
def add_option(id)
|
||||
def add_option(id, data=nil)
|
||||
@options << id
|
||||
@option_data[id] = data
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -23,6 +23,34 @@ class Wizard
|
||||
update_setting(:site_contact_username, fields, :site_contact_username)
|
||||
end
|
||||
|
||||
def update_colors(fields)
|
||||
scheme_name = fields[:color_scheme]
|
||||
|
||||
theme = ColorScheme.themes.find {|s| s[:id] == scheme_name }
|
||||
|
||||
colors = []
|
||||
theme[:colors].each do |name, hex|
|
||||
colors << {name: name, hex: hex[1..-1] }
|
||||
end
|
||||
|
||||
attrs = {
|
||||
enabled: true,
|
||||
name: I18n.t("wizard.step.colors.fields.color_scheme.options.#{scheme_name}"),
|
||||
colors: colors
|
||||
}
|
||||
|
||||
scheme = ColorScheme.where(via_wizard: true).first
|
||||
if scheme.present?
|
||||
attrs[:colors] = colors
|
||||
revisor = ColorSchemeRevisor.new(scheme, attrs)
|
||||
revisor.revise
|
||||
else
|
||||
attrs[:via_wizard] = true
|
||||
scheme = ColorScheme.new(attrs)
|
||||
scheme.save!
|
||||
end
|
||||
end
|
||||
|
||||
def success?
|
||||
@errors.blank?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user