discourse/lib/wizard/field.rb

39 lines
688 B
Ruby
Raw Normal View History

2016-08-25 13:14:56 -04:00
class Wizard
2016-09-07 18:04:01 -04:00
class Choice
2016-09-09 15:57:44 -04:00
attr_reader :id, :label, :icon, :data
2016-09-07 18:04:01 -04:00
attr_accessor :field
def initialize(id, opts)
@id = id
@data = opts[:data]
@label = opts[:label]
2016-09-09 15:57:44 -04:00
@icon = opts[:icon]
2016-09-07 18:04:01 -04:00
end
end
class Field
attr_reader :id, :type, :required, :value, :choices
2016-08-25 13:14:56 -04:00
attr_accessor :step
def initialize(attrs)
attrs = attrs || {}
@id = attrs[:id]
@type = attrs[:type]
@required = !!attrs[:required]
@value = attrs[:value]
2016-09-07 18:04:01 -04:00
@choices = []
end
2016-09-07 18:04:01 -04:00
def add_choice(id, opts=nil)
choice = Choice.new(id, opts || {})
choice.field = self
@choices << choice
choice
2016-08-25 13:14:56 -04:00
end
2016-08-25 13:14:56 -04:00
end
end