Class | ListController
In: | app/controllers/list_controller.rb
Parent: | ApplicationController

一覧設定画面の制御を行う。

### Methods

add destroy edit glance_to_import import index order_selected order_unselected search_to_import select_to_import update

### Public Instance methods

add()

新規の一覧を追加する。

[Source]

        # File app/controllers/list_controller.rb, line 12
    12:   def add
    13:     default_list = DefaultList.find_by_user_id_and_product_id(User.current_id, @product.id)
    14:     source = default_list && Display.find_by_id(default_list.display_id)
    15:     source ||= DisplayToList.find_by_product_id(@product.id)
    16:     raise ActiveRecord::RecordNotFound, "source list not found" unless source
    17:     source.private_copy
    18:     load_displays
    19:     view_list
    20:     render :template => "list/index"
    21:   end

destroy()

既存の一覧を削除する。

[Source]

        # File app/controllers/list_controller.rb, line 24
    24:   def destroy
    25:     verify_display_id
    26:     @display.destroy
    27:     view_detail
    28:     x_close_or_redirect_to :action => "index", :id => @product.id
    29:   end

edit()

既存の一覧を編集するための画面を開く。

[Source]

        # File app/controllers/list_controller.rb, line 32
    32:   def edit
    33:     verify_display_id
    34:     view_detail
    35:     @mode = :edit
    36:     if flash[:pick]
    37:       # restore temporary input values.
    38:       session[:picker] ||= {}
    39:       if picker_session = session[:picker]
    40:         @display.name = picker_session[:display_before_picker][:name]
    41:         if picker_session[:set_default_before_picker].to_i > 0
    42:           def @display.default_list?() true; end
    43:         else
    44:           def @display.default_list?() false; end
    45:         end
    46:       end
    47:       session[:picker] = nil
    48:       case flash[:pick][:lump_pick]
    49:       when "company"
    50:         @roleable = Company.find(flash[:pick][:company])
    51:       when "organization"
    52:         @roleable = Organization.find(flash[:pick][:organization])
    53:       when "person"
    54:         @roleable = Person.find(flash[:pick][:person])
    55:       when "group"
    56:         @roleable = Group.find(flash[:pick][:group])
    57:       end
    58:     end
    59:     render :partial => "detail"
    60:   end

glance_to_import()

共有一覧の内容情報を取得する

[Source]

         # File app/controllers/list_controller.rb, line 142
    142:   def glance_to_import
    143:     view_list # x_form_tag needs @current_view
    144:     @shared_list = SharedList.find(params[:shared_list_id].to_i)
    145:     render :partial => "glance"
    146:   end

import()

共有一覧をインポートする画面を表示する。

[Source]

         # File app/controllers/list_controller.rb, line 121
    121:   def import
    122:     view_import
    123:     render :partial => "import"
    124:   end

index()

一覧を一覧表示する。

[Source]

       # File app/controllers/list_controller.rb, line 6
    6:   def index
    7:     load_displays
    8:     view_list
    9:   end

order_selected()

選択された項目を並び替える。

[Source]

         # File app/controllers/list_controller.rb, line 90
     90:   def order_selected
     91:     verify_display_id
     92:     if params[:selected_items].respond_to?(:map)
     93:       ids = params[:selected_items].map(&:to_i)
     94:       items = @display.items
     95:       ids.each_with_index do |id,i|
     96:         items = items.delete_if do |item|
     97:           r = (item.id == id)
     98:           if r
     99:             item.layout = i + 1
    100:             item.selected = true
    101:             item.save!
    102:           end
    103:           r
    104:         end
    105:       end
    106:       items.each do |item|
    107:         item.selected = false
    108:         item.save!
    109:       end
    110:     end
    111:     render :nothing => true
    112:   end

order_unselected()

選択されていない項目を並び替える。

[Source]

         # File app/controllers/list_controller.rb, line 115
    115:   def order_unselected
    116:     # nothing to do
    117:     render :nothing => true
    118:   end

search_to_import()

共有一覧を検索する

[Source]

         # File app/controllers/list_controller.rb, line 127
    127:   def search_to_import
    128:     view_import
    129:     @target = params[:target]
    130:     unless @target
    131:       render :partial => "import"
    132:       return
    133:     end
    134:     @shared_lists = SharedList.find(:all).select do |shared_list|
    135:       (@target[:display_sub].blank? || shared_list.display.name[@target[:display_sub]]) &&
    136:         (@target[:creator_sub].blank? || shared_list.creator.name[@target[:creator_sub]])
    137:     end
    138:     render :partial => "import"
    139:   end

select_to_import()

共有一覧を選択する

[Source]

         # File app/controllers/list_controller.rb, line 149
    149:   def select_to_import
    150:     shared_list = SharedList.find(params[:shared_list_id].to_i)
    151:     shared_list.export(User.current.person)
    152:     view_detail
    153:     x_close_or_redirect_to :action => "index", :id => @product.id
    154:   end

update()

既存の一覧を更新する。

[Source]

        # File app/controllers/list_controller.rb, line 63
    63:   def   updateupdateupdate
    64:     verify_display_id
    65:     view_detail
    66:     return if use_picker
    67:     Language.all.each do |lang|
    68:       @display.__send__("name_#{lang.code}=", params[:display][:name])
    69:     end
    70:     @display.save!
    71:     default_list = DefaultList.find_or_initialize_by_product_id_and_user_id(@product.id, User.current_id)
    72:     if params[:set_default].to_i > 0
    73:       # set default
    74:       default_list.display_id = @display.id
    75:       default_list.save!
    76:     elsif !default_list.new_record? && default_list.display_id == @display.id
    77:       # drop default
    78:       default_list.destroy
    79:     end
    80:     if params[:share].to_i > 0
    81:       # create a shared list
    82:       roleable_class = params[:roleable_type].to_s.classify.constantize
    83:       roleable = roleable_class.find(params[:roleable_id].to_i)
    84:       @display.share(roleable)
    85:     end
    86:     x_close_or_redirect_to :action => "index", :id => @product.id
    87:   end

[Validate]