builder.rb 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. class CustomWizard::Builder
  2. def initialize(user, wizard_name)
  3. rows = PluginStoreRow.where(plugin_name: 'custom_wizards')
  4. return if !rows
  5. [*rows].each do |r|
  6. wizard = CustomWizard::Wizard.new(r.value)
  7. @template = wizard if wizard.name.dasherize.downcase == wizard_name
  8. end
  9. @wizard = Wizard.new(user)
  10. end
  11. def build
  12. @template.steps.each do |s|
  13. @wizard.append_step(s['title']) do |step|
  14. step.banner = s['banner'] if s['banner']
  15. s['fields'].each do |f|
  16. field = step.add_field(id: f['id'],
  17. type: f['type'],
  18. required: f['required'],
  19. value: f['value'])
  20. if f['type'] == 'dropdown'
  21. f['choices'].each do |c|
  22. field.add_choice(c)
  23. end
  24. end
  25. end
  26. step.on_update do |updater|
  27. puts "UPDATER: #{updater}"
  28. ## do stuff
  29. end
  30. end
  31. end
  32. @wizard
  33. end
  34. end