0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-09-19 23:31:11 +02:00
discourse-custom-wizard/lib/builder.rb

43 Zeilen
1.023 B
Ruby

2017-09-23 04:34:07 +02:00
class CustomWizard::Builder
2017-09-25 16:47:40 +02:00
def initialize(user, wizard_name)
rows = PluginStoreRow.where(plugin_name: 'custom_wizards')
return if !rows
[*rows].each do |r|
wizard = CustomWizard::Wizard.new(r.value)
@template = wizard if wizard.name.dasherize.downcase == wizard_name
end
2017-09-23 04:34:07 +02:00
@wizard = Wizard.new(user)
end
def build
2017-09-25 16:47:40 +02:00
@template.steps.each do |s|
@wizard.append_step(s['title']) do |step|
2017-09-23 04:34:07 +02:00
2017-09-25 16:47:40 +02:00
step.banner = s['banner'] if s['banner']
2017-09-23 04:34:07 +02:00
2017-09-25 16:47:40 +02:00
s['fields'].each do |f|
field = step.add_field(id: f['id'],
type: f['type'],
required: f['required'],
value: f['value'])
2017-09-23 04:34:07 +02:00
2017-09-25 16:47:40 +02:00
if f['type'] == 'dropdown'
f['choices'].each do |c|
2017-09-23 04:34:07 +02:00
field.add_choice(c)
end
end
end
step.on_update do |updater|
puts "UPDATER: #{updater}"
## do stuff
end
end
end
@wizard
end
end