Class: StudentInputFormControllerEdit

Inherits:
Object
  • Object
show all
Defined in:
lib/source/controllers/student_input_form_controller_edit.rb,
lib/source/controllers/student_input_form/student_input_form_controller_edit.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent_controller, existing_student_id) ⇒ StudentInputFormControllerEdit

Returns a new instance of StudentInputFormControllerEdit.



6
7
8
9
# File 'lib/source/controllers/student_input_form_controller_edit.rb', line 6

def initialize(parent_controller, existing_student_id)
  @parent_controller = parent_controller
  @existing_student_id = existing_student_id
end

Instance Method Details

#on_view_createdObject



15
16
17
18
19
# File 'lib/source/controllers/student_input_form_controller_edit.rb', line 15

def on_view_created
  @existing_student = StudentsListDB.get_student(@existing_student_id)
  @view.make_readonly(:git, :telegram, :email, :phone)
  populate_fields(@existing_student)
end

#populate_fields(student) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/source/controllers/student_input_form_controller_edit.rb', line 21

def populate_fields(student)
  @view.set_value(:last_name, student.last_name)
  @view.set_value(:first_name, student.first_name)
  @view.set_value(:paternal_name, student.paternal_name)
  @view.set_value(:git, student.git)
  @view.set_value(:telegram, student.telegram)
  @view.set_value(:email, student.email)
  @view.set_value(:phone, student.phone)
end

#process_fields(fields) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/source/controllers/student_input_form_controller_edit.rb', line 31

def process_fields(fields)
  begin
    new_student = Student.from_json(JSON(fields))

    StudentsListDB.replace_student(@existing_student_id, new_student)

    @view.close
  rescue ArgumentError => e
    api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
    api.call(0, e.message, 'Error', 0)
  end
end

#refreshObject



18
19
20
# File 'lib/source/controllers/student_input_form/student_input_form_controller_edit.rb', line 18

def refresh
  @parent_controller.refresh_data(1, 20)
end

#set_view(view) ⇒ Object



11
12
13
# File 'lib/source/controllers/student_input_form_controller_edit.rb', line 11

def set_view(view)
  @view = view
end