2017-09-23 04:34:07 +02:00
|
|
|
class CustomWizard::Builder
|
2017-09-29 13:27:03 +02:00
|
|
|
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)
|
2017-09-29 13:27:03 +02:00
|
|
|
@wizard.id = wizard_id
|
2017-09-23 04:34:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def build
|
2017-09-29 13:27:03 +02:00
|
|
|
@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'],
|
2017-09-29 13:27:03 +02:00
|
|
|
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|
|
2017-09-29 13:27:03 +02:00
|
|
|
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
|