Module: Edgar::ControllerCommon

Included in:
EdgarController, EdgarPopupController
Defined in:
app/controllers/edgar/controller_common.rb

Overview

Common module for EdgarController and EdgarPopupController.

Instance Method Summary (collapse)

Instance Method Details

- (Object) prepare_list (private)

  1. prepare followings:

  2. @view_status

  3. @count

  4. @list (with user_scoped if defined)

  5. update @view_status.page if params exists

This private method is called from both EdgarController and EdgarPopupController to draw list.

You can overwrite prepare_list() to show list at your controller.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/edgar/controller_common.rb', line 24

def prepare_list
  @view_status = view_status
  if params[:page]
    @view_status.update_attribute(:page, params[:page])
  end
  options   = {conditions:  @view_status.model.conditions,
               page:        @view_status.page,
               per_page:    @view_status.lines}
  if !@view_status.order_by.blank?
    options.merge!(:order => @view_status.order_by + ' ' + @view_status.dir)
  end
  @list   = user_scoped.paginate(options)
  @count  = user_scoped.count(:conditions=>@view_status.model.conditions)
end

- (Object) scope_context (private)

provide 2nd parameter for Model.user_scoped(user, context). Default is @sssn.



41
42
43
# File 'app/controllers/edgar/controller_common.rb', line 41

def scope_context
  @sssn
end

- (Object) user_scoped (private)

narrow data scope on model_class

Model's user_coped parameters are as follows:

1st argument

current_user

2nd argument

scope_context method result (default = @sssn)

3rd argument

target for popup (see below for the detail)

3rd argument

This is used to identify which column the selected value on the popup is populated.



55
56
57
58
59
# File 'app/controllers/edgar/controller_common.rb', line 55

def user_scoped
  @_user_scoped ||= model_class.respond_to?(:user_scoped) ?
      model_class.user_scoped(current_user, scope_context, params[:id_target]) :
      model_class
end

- (Object) view_status_save

page is reset to 1 since order and/or lines/page are/is changed.



4
5
6
7
8
9
10
11
# File 'app/controllers/edgar/controller_common.rb', line 4

def view_status_save
  vc = @sssn.view_status.find(params[:id])
  return if !vc   # do nothing if the id is not users'

  vc.update_attributes(params[:edgar_view_status])
  vc.update_attribute(:page, 1)
  prepare_list
end