discourse/lib/wizard/field.rb

42 lines
775 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-25 12:14:56 -05:00
class Wizard
2016-09-07 17:04:01 -05:00
class Choice
2016-09-21 10:22:46 -05:00
attr_reader :id, :label, :icon, :data, :extra_label
2016-09-07 17:04:01 -05:00
attr_accessor :field
def initialize(id, opts)
@id = id
@data = opts[:data]
@label = opts[:label]
2016-09-21 10:22:46 -05:00
@extra_label = opts[:extra_label]
2016-09-09 14:57:44 -05:00
@icon = opts[:icon]
2016-09-07 17:04:01 -05:00
end
end
class Field
attr_reader :id, :type, :required, :value, :choices
2016-08-25 12:14:56 -05:00
attr_accessor :step
def initialize(attrs)
attrs = attrs || {}
@id = attrs[:id]
@type = attrs[:type]
@required = !!attrs[:required]
@value = attrs[:value]
2016-09-07 17:04:01 -05:00
@choices = []
end
2017-07-27 20:20:09 -05:00
def add_choice(id, opts = nil)
2016-09-07 17:04:01 -05:00
choice = Choice.new(id, opts || {})
choice.field = self
@choices << choice
choice
2016-08-25 12:14:56 -05:00
end
2016-08-25 12:14:56 -05:00
end
end