Class: StudentContactFormController

Inherits:
Object
  • Object
show all
Defined in:
lib/source/controllers/student_contact_form_controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent_controller, existing_student_id) ⇒ StudentContactFormController

Returns a new instance of StudentContactFormController.



4
5
6
7
# File 'lib/source/controllers/student_contact_form_controller.rb', line 4

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

Instance Method Details

#on_view_createdObject



13
14
15
16
17
18
# File 'lib/source/controllers/student_contact_form_controller.rb', line 13

def on_view_created
  @student_list = StudentList.new(StudentListDbAdapter.new)
  @existing_student = @student_list.student_by_id(@existing_student_id)
  @view.make_readonly(:first_name,:last_name,:paternal_name, :git)
  set_fields(@existing_student)
end

#process_fields(fields) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/source/controllers/student_contact_form_controller.rb', line 33

def process_fields(fields)
  new_student = Student.from_hash(fields)

  @student_list.replace_student(@existing_student_id, new_student)

  @view.close
end

#set_fields(student) ⇒ Object



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

def set_fields(student)
  student = student
  puts 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

#view=(view) ⇒ Object



9
10
11
# File 'lib/source/controllers/student_contact_form_controller.rb', line 9

def view=(view)
  @view = view
end