Class: TaskInputForm

Inherits:
Object
  • Object
show all
Includes:
Glimmer
Defined in:
lib/task/ui/task_input_form.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller, fields_to_create, existing_student = nil) ⇒ TaskInputForm

Returns a new instance of TaskInputForm.



10
11
12
13
14
15
# File 'lib/task/ui/task_input_form.rb', line 10

def initialize(controller, fields_to_create, existing_student = nil)
  @fields_to_create=fields_to_create
  @item = existing_student.to_hash unless existing_student.nil?
  @controller = controller
  @entries = {}
end

Instance Method Details

#closeObject



64
65
66
# File 'lib/task/ui/task_input_form.rb', line 64

def close
  @root_container.destroy
end

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/task/ui/task_input_form.rb', line 21

def create
  @root_container = window('Задание', 300, 70) {
    resizable false

    vertical_box {
      @student_form = form {
        stretchy false

        fields = @fields_to_create

        fields.each do |field|
          @entries[field[0]] = entry {
            label field[1]
          }
        end
      }

      button('Сохранить') {
        stretchy false

        on_clicked {
          values = @entries.transform_values { |v| v.text.force_encoding("utf-8").strip }
          values.transform_values! { |v| v.empty? ? nil : v}
          @controller.process_fields(values)
        }
      }
    }
  }
  on_create
  @root_container
end

#make_readonly(*fields) ⇒ Object



58
59
60
61
62
# File 'lib/task/ui/task_input_form.rb', line 58

def make_readonly(*fields)
  fields.each do |field|
    @entries[field].read_only = true
  end
end

#on_createObject



17
18
19
# File 'lib/task/ui/task_input_form.rb', line 17

def on_create
  @controller.on_view_created
end

#set_value(field, value) ⇒ Object



53
54
55
56
# File 'lib/task/ui/task_input_form.rb', line 53

def set_value(field, value)
  return unless @entries.include?(field)
  @entries[field].text = value
end