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