builder.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. class CustomWizard::Builder
  2. def initialize(user, wizard_id)
  3. data = PluginStore.get('custom_wizard', wizard_id)
  4. @custom_wizard = CustomWizard::Wizard.new(data)
  5. @wizard = Wizard.new(user)
  6. @wizard.id = wizard_id
  7. end
  8. def build
  9. @custom_wizard.steps.each do |s|
  10. @wizard.append_step(s['id']) do |step|
  11. step.title = s['title'] if s['title']
  12. step.banner = s['banner'] if s['banner']
  13. s['fields'].each do |f|
  14. field = step.add_field(id: f['id'],
  15. type: f['type'],
  16. label: f['label'],
  17. description: f['description'],
  18. required: f['required'])
  19. if f['type'] == 'dropdown'
  20. f['choices'].each do |c|
  21. field.add_choice(c['id'], label: c['label'])
  22. end
  23. end
  24. end
  25. step.on_update do |updater|
  26. puts "UPDATER: #{updater}"
  27. ## do stuff
  28. end
  29. end
  30. end
  31. @wizard
  32. end
  33. end