Class: TabStudentsController
- Inherits:
-
Object
- Object
- TabStudentsController
- Defined in:
- lib/source/controllers/tab_students_controller.rb
Instance Method Summary collapse
- #delete_selected(selected_row) ⇒ Object
- #get_page ⇒ Object
-
#initialize(view, student_per_page) ⇒ TabStudentsController
constructor
A new instance of TabStudentsController.
- #next_page(is_left) ⇒ Object
- #refresh_data ⇒ Object
- #show_modal_add ⇒ Object
- #show_modal_edit(selected_row) ⇒ Object
- #show_view ⇒ Object
Constructor Details
#initialize(view, student_per_page) ⇒ TabStudentsController
Returns a new instance of TabStudentsController.
13 14 15 16 17 18 |
# File 'lib/source/controllers/tab_students_controller.rb', line 13 def initialize(view, student_per_page) @view = view @data_list = DataListStudentShort.new(list: []) @student_per_page = student_per_page @current_page = 1 end |
Instance Method Details
#delete_selected(selected_row) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/source/controllers/tab_students_controller.rb', line 40 def delete_selected(selected_row) begin student_num = (@current_page - 1) * @student_per_page + selected_row student_id = @data_list.get_id_by_index(student_num) StudentsListDB.remove_student(student_id) rescue on_db_conn_error end end |
#get_page ⇒ Object
56 57 58 |
# File 'lib/source/controllers/tab_students_controller.rb', line 56 def get_page @current_page end |
#next_page(is_left) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/source/controllers/tab_students_controller.rb', line 60 def next_page(is_left) if is_left @current_page = [@current_page - 1, 1].max else @current_page = [@current_page + 1, (@total_count / STUDENTS_PER_PAGE.to_f).ceil].min end @controller.refresh_data(@current_page) end |
#refresh_data ⇒ Object
51 52 53 54 |
# File 'lib/source/controllers/tab_students_controller.rb', line 51 def refresh_data StudentsListDB.get_students_slice(@current_page, @student_per_page, @data_list) EventManager.notify(EventUpdateStudentsCount.new(StudentsListDB.count)) end |
#show_modal_add ⇒ Object
24 25 26 27 28 29 |
# File 'lib/source/controllers/tab_students_controller.rb', line 24 def show_modal_add controller = StudentInputFormControllerCreate.new(self) view = StudentInputForm.new(controller,self) controller.set_view(view) view.create.show end |
#show_modal_edit(selected_row) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/source/controllers/tab_students_controller.rb', line 31 def show_modal_edit(selected_row) student_num = (@current_page - 1) * @student_per_page + selected_row student_id = @data_list.get_id_by_index(student_num) controller = StudentInputFormControllerEdit.new(self, student_id) view = StudentInputForm.new(controller, self) controller.set_view(view) view.create.show end |
#show_view ⇒ Object
20 21 22 |
# File 'lib/source/controllers/tab_students_controller.rb', line 20 def show_view @view.create.show end |