Class: StudentInputFormController
- Inherits:
-
Object
- Object
- StudentInputFormController
- Defined in:
- lib/source/student_input_form_controller.rb
Instance Method Summary collapse
-
#initialize(parent_controller) ⇒ StudentInputFormController
constructor
A new instance of StudentInputFormController.
- #on_db_conn_error(error) ⇒ Object
- #on_view_created ⇒ Object
- #process_fields(fields) ⇒ Object
- #refresh ⇒ Object
- #set_view(view) ⇒ Object
Constructor Details
#initialize(parent_controller) ⇒ StudentInputFormController
Returns a new instance of StudentInputFormController.
6 7 8 9 |
# File 'lib/source/student_input_form_controller.rb', line 6 def initialize(parent_controller) @parent_controller = parent_controller LoggerHolder.instance.debug('StudentInputFormController: initialized') end |
Instance Method Details
#on_db_conn_error(error) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/source/student_input_form_controller.rb', line 49 def on_db_conn_error(error) LoggerHolder.instance.debug('StudentInputFormController: DB connection error:') LoggerHolder.instance.error(error.) api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I') api.call(0, "No connection to DB", "Error", 0) @view.close end |
#on_view_created ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/source/student_input_form_controller.rb', line 20 def on_view_created begin @student_list = StudentListAdv.new(StudentsListDBAdapter.new(StudentListDB.instance)) rescue Mysql2::Error::ConnectionError=>e on_db_conn_error(e) end end |
#process_fields(fields) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/source/student_input_form_controller.rb', line 28 def process_fields(fields) begin last_name = fields.delete(:last_name) first_name = fields.delete(:first_name) parental_name = fields.delete(:parental_name) return if last_name.nil? || first_name.nil? || parental_name.nil? student = Student.new(last_name, first_name, parental_name, **fields) @student_list.add_student(student) LoggerHolder.instance.debug('StudentInputFormController: adding student to DB') @view.close rescue ArgumentError => e api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I') LoggerHolder.instance.debug("StudentInputFormController: wrong fields: #{e.}") api.call(0, e., 'Error', 0) end end |
#refresh ⇒ Object
16 17 18 |
# File 'lib/source/student_input_form_controller.rb', line 16 def refresh @parent_controller.refresh_data(1,20) end |
#set_view(view) ⇒ Object
11 12 13 |
# File 'lib/source/student_input_form_controller.rb', line 11 def set_view(view) @view = view end |