Class: EdgarPopupController

Inherits:
ApplicationController
  • Object
show all
Includes:
Edgar::ControllerCommon, Edgar::PermissionMixin, Edgar::RescueMixin
Defined in:
app/controllers/edgar_popup_controller.rb

Overview

Modal popup controller to pick-up 'belongs_to' record

Instance Method Summary (collapse)

Methods included from Edgar::RescueMixin

included, #rescue_404, #rescue_edgar_error

Methods included from Edgar::PermissionMixin

#current_model_permissions, #current_user_roles, included, #require_create_permission, #require_delete_permission, #require_other_permission, #require_read_permission, #require_update_permission, #require_x_permission, #respond_to_permission_error

Methods included from Edgar::ControllerCommon

#prepare_list, #scope_context, #user_scoped, #view_status_save

Instance Method Details

- (Object) index

draw popup windows

INPUTS

params

popup model_class

params

id target DOM on click entry of popup

params

on paginate

Paginate logic

  • params exists -> save it to @view_status and use it

  • params doesn't exist -> use @view_status.page

call flow

draw popup

EdgarHelper.draw_belongs_to_label() is called. Example:

<a href='http://.../edgar_popup?...' data-remote=true>Author</a>
<input type=hidden name='book[author_id]'>
<span id='popup_target_book_author'>...</span>
    :

on opening popup

  1. edgar_popup URL .../edgar_popup?... is executed.

  2. EdgarPopupController.index() is called.

    1. data is searched based on @view_status and user_scoped and set it to @list.

  3. app/views/edgar_popup/index.js.erb

    1. $('#edgar_form_popup') dialog is opened.

on paginate

Same as above('on opening popup'), but page=N parameter is added.

on search

  1. post search condition to EdgarPopupController.search().

on clicking entry on the popup

TBD



46
47
48
49
# File 'app/controllers/edgar_popup_controller.rb', line 46

def index
  prepare_list
  @search = view_status.model
end

- (Object) model_class (private)

return model class.



73
74
75
76
77
78
79
80
# File 'app/controllers/edgar_popup_controller.rb', line 73

def model_class
  @model_class ||= params[:model_class].
      gsub(/[^a-zA-Z0-9_:]/, '').   # sanitize
      singularize.camelize.constantize
rescue NameError
  app_rescue
  raise Edgar::PopupModelNameError
end

- (Object) search

Ajax method to execute search

Actually, this saves condition for later use. Execution of search could be done at 'index' method, but do it in this action to avoid 'POST' redirect issue( POST method redirect resulted in 'POST index', not 'GET index').

INPUTS

params

popup model_class

params

id target DOM on click entry of popup

params

search condition



62
63
64
65
66
67
68
69
# File 'app/controllers/edgar_popup_controller.rb', line 62

def search
  vc        = view_status
  vc.model  = Edgar::SearchPopup.new(model_class, params[:search_form])
  vc.update_attribute(:page, 1)
  vc.save!
  @search   = vc.model
  prepare_list  if @search.valid?
end

- (Object) view_status (private)



82
83
84
85
86
87
# File 'app/controllers/edgar_popup_controller.rb', line 82

def view_status
  @view_status ||= Edgar::ViewStatus.intern(
      @sssn,
      'popup_' + model_class.to_s,
      Edgar::SearchPopup.new(model_class))
end