1
0
Fork 0
discourse-custom-wizard-unl.../lib/builder.rb

39 Zeilen
1 KiB
Ruby

2017-09-23 04:34:07 +02:00
class CustomWizard::Builder
def initialize(user, wizard_id)
data = PluginStore.get('custom_wizard', wizard_id)
@custom_wizard = CustomWizard::Wizard.new(data)
2017-09-23 04:34:07 +02:00
@wizard = Wizard.new(user)
@wizard.id = wizard_id
2017-09-23 04:34:07 +02:00
end
def build
@custom_wizard.steps.each do |s|
@wizard.append_step(s['id']) do |step|
step.title = s['title'] if s['title']
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'],
label: f['label'],
description: f['description'],
required: f['required'])
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|
field.add_choice(c['id'], label: c['label'])
2017-09-23 04:34:07 +02:00
end
end
end
step.on_update do |updater|
puts "UPDATER: #{updater}"
## do stuff
end
end
end
@wizard
end
end