Class | PickerController
In: | app/controllers/picker_controller.rb
Parent: | ApplicationController

選択部品を制御する:

- 個人選択
- グループ選択
- 役職選択
- 組織選択
- 企業選択
- 個人一括選択
- 一括選択
- 指定マスタ選択

### Methods

company group index lump mail organization person pick post record test

### Constants

PICKER_RETURN_TO | = | { :list_share => {:controller => "list", :action => "edit"}, :picker_test => {:controller => "picker", :action => "test"}, }.with_indifferent_access |  | allow registered return_to only; do not redirect to an arbitrary url
PICKER_ERROR_RETURN_TO | = | "/"

### Public Instance methods

company()

企業を検索する。

[Source]

         # File app/controllers/picker_controller.rb, line 119
    119:   def company
    120:     with_picker_scope(Company) do
    121:       search :companies
    122:       pass_params
    123:     end
    124:   end

group()

グループを検索する。

[Source]

         # File app/controllers/picker_controller.rb, line 111
    111:   def group
    112:     with_picker_scope(Group) do
    113:       search :groups
    114:       pass_params
    115:     end
    116:   end

index()

`test` へリダイレクトする。

[Source]

        # File app/controllers/picker_controller.rb, line 21
    21:   def index
    22:     redirect_to :action => :test
    23:   end

lump()

一括で検索する。

[Source]

         # File app/controllers/picker_controller.rb, line 158
    158:   def lump
    159:     set_mode_options
    160:     case params[:mode]
    161:     when "group"
    162:       lump_group
    163:     when "personal_group"
    164:       lump_personal_group
    165:     else
    166:       person
    167:     end
    168:   end

mail()

メールアドレスを検索する。

[Source]

         # File app/controllers/picker_controller.rb, line 171
    171:   def mail
    172:     picker_session = session[:picker] || {}
    173:     params[:mail] ||= picker_session[:mail_before_picker] || {}
    174:     params[:mail][:field_type] ||= "to"
    175:     if params[:mail][:recipients].is_a?(Hash)
    176:       params[:mail][:recipients] = params[:mail][:recipients].keys
    177:     end
    178:     # set params["commit"] too when mode changed
    179:     if !params["commit"] && params["pick"]
    180:       flash[:pick] = {
    181:         :field => params[:return_field],
    182:         :mail => params[:mail],
    183:       }
    184:       x_close_or_redirect_to return_to_url
    185:       return
    186:     end
    187:
    188:     @mail_field_type_list = [
    189:       [s_("Picker|Mail Field Type|To"), "to"],
    190:       [s_("Picker|Mail Field Type|Cc"), "cc"],
    191:       [s_("Picker|Mail Field Type|Bcc"), "bcc"],
    192:     ]
    193:
    194:     @select_more_columns_from_people = ",people.mail_address"
    195:     if params[:mail][:recipients]
    196:       if params[:mail][:recipients].is_a?(Hash)
    197:         params[:mail][:recipients] = params[:mail][:recipients].keys
    198:       elsif params[:mail][:recipients].is_a?(String)
    199:         params[:mail][:recipients] = params[:mail][:recipients].split(/,/)
    200:       end
    201:       @recipients = Person.find(params[:mail][:recipients].map(&:to_i)).select(&:receive_mail?)
    202:     else
    203:       @recipients = []
    204:     end
    205:
    206:     unless params["commit"]
    207:       %w"company organization group".each do |key|
    208:         if params[key]
    209:           key_id, = params[key].keys
    210:           case key_id
    211:           when /\Aopen(\d+)/
    212:             params["#{key}_id"] = $1
    213:           when /\Apick(\d+)/
    214:             params["#{key}_id"] = $1
    215:             @recipients += key.classify.constantize.find($1.to_i).people.find(:all, :conditions => "mail_address IS NOT NULL").select(&:receive_mail?)
    216:           end
    217:         end
    218:       end
    219:       if params["person"]
    220:         key_id, = params["person"].keys
    221:         person = Person.find(key_id, :conditions => "mail_address IS NOT NULL")
    222:         if person.receive_mail?
    223:           @recipients << person
    224:         end
    225:       end
    226:       @recipients.uniq!
    227:       if params["unset"]
    228:         key_id, = params["unset"].keys
    229:         key_id = key_id.to_i
    230:         @recipients.delete_if do |person|
    231:           person.id == key_id
    232:         end
    233:       end
    234:     end
    235:
    236:     lump
    237:   end

organization()

組織を検索する。

[Source]

         # File app/controllers/picker_controller.rb, line 127
    127:   def organization
    128:     with_picker_scope(Company, Organization) do
    129:       if company = search_by_id(:company)
    130:         search_under company, :organizations
    131:       end
    132:       pass_params :company
    133:     end
    134:   end

person()

個人を検索する。

[Source]

         # File app/controllers/picker_controller.rb, line 137
    137:   def person
    138:     with_picker_scope(Company, Organization, Person) do
    139:       if company = search_by_id(:company)
    140:         if organization = search_by_id(:organization, company)
    141:           search_under organization, :people
    142:         end
    143:       end
    144:       pass_params :company, :organization
    145:     end
    146:   end

pick()

選択を行う。

[Source]

         # File app/controllers/picker_controller.rb, line 96
     96:   def pick
     97:     flash[:pick] = {
     98:       :field => params[:return_field],
     99:       :group => params[:group_id],
    100:       :personal_group => params[:personal_group_id],
    101:       :company => params[:company_id],
    102:       :organization => params[:organization_id],
    103:       :person => params[:person_id],
    104:       :post => params[:post_id],
    105:       :lump_pick => params[:lump_pick],
    106:     }
    107:     x_close_or_redirect_to return_to_url
    108:   end

post()

役職を検索する。

[Source]

         # File app/controllers/picker_controller.rb, line 149
    149:   def post
    150:     with_picker_scope(Company, Post) do
    151:       company = search_by_id :company
    152:       search_under company, :posts
    153:       pass_params :company
    154:     end
    155:   end

record()

モデルとして指定されたテーブルを検索する。

[Source]

         # File app/controllers/picker_controller.rb, line 240
    240:   def record
    241:     @record_id, @record_name, @record_code = fields = params[:record_field].split(",")
    242:     case fields.size
    243:     when 2, 3
    244:       if !params[:commit] && params[:pick] # done
    245:         record = {
    246:           :record_id   => params[@record_id],
    247:           :record_name => params[@record_name],
    248:         }
    249:         record[:record_code] = params[@record_code] if @record_code
    250:         flash[:pick] = {
    251:           :field => params[:return_field],
    252:           :record => record
    253:         }
    254:         x_close_or_redirect_to return_to_url
    255:         return
    256:       end
    257:       pass_params
    258:       [:pick, :action].each do |key|
    259:         @pass_params_form[key] = "record"
    260:       end
    261:       [:record_field, :record_model].each do |key|
    262:         @pass_params_form[key] = params[key]
    263:       end
    264:     else
    265:       raise "wrong number of subject fields"
    266:     end
    267:     {:name => 1, :code => 2}.each do |key, i|
    268:       unless (value = params["record_#{key}"]).blank?
    269:         record_model = params[:record_model].classify.constantize
    270:         if @records
    271:           @records &= find_like(record_model, fields[i], value)
    272:         else
    273:           @records = find_like(record_model, fields[i], value)
    274:         end
    275:       end
    276:     end
    277:   end

test()

(試験用)

[Source]

        # File app/controllers/picker_controller.rb, line 26
    26:   def test
    27:     @current_view = "view_main"
    28:     @sub_view = "view_picker"
    29:
    30:     if flash[:pick]
    31:       case flash[:pick][:field]
    32:       when "group"
    33:         @group = Group.find(flash[:pick][:group])
    34:       when "company"
    35:         @company = Company.find(flash[:pick][:company])
    36:       when "organization"
    37:         @organization = Organization.find(flash[:pick][:organization])
    38:       when "organization,company"
    39:         @organization = Organization.find(flash[:pick][:organization])
    40:         @company = Company.find(flash[:pick][:company])
    41:       when "person"
    42:         @person = Person.find(flash[:pick][:person])
    43:       when "person,organization"
    44:         @person = Person.find(flash[:pick][:person])
    45:         @organization = Organization.find(flash[:pick][:organization])
    46:       when "person,organization,company"
    47:         @person = Person.find(flash[:pick][:person])
    48:         @organization = Organization.find(flash[:pick][:organization])
    49:         @company = Company.find(flash[:pick][:company])
    50:       when "post"
    51:         @post = Post.find(flash[:pick][:post])
    52:       when "lump"
    53:         case flash[:pick][:lump_pick]
    54:         when "company"
    55:           lump = @company = Company.find(flash[:pick][:company])
    56:         when "organization"
    57:           lump = @organization = Organization.find(flash[:pick][:organization])
    58:         when "group"
    59:           lump = @group = Group.find(flash[:pick][:group])
    60:         when "personal_group"
    61:           lump = @personal_group = PersonalGroup.find(flash[:pick][:personal_group])
    62:         when "person"
    63:           lump = @person = Person.find(flash[:pick][:person])
    64:         end
    65:         @people_ids = lump.id
    66:         @people_names = lump.name
    67:       when "lump_people"
    68:         case flash[:pick][:lump_pick]
    69:         when "company"
    70:           people = Company.find(flash[:pick][:company]).people
    71:         when "organization"
    72:           people = Organization.find(flash[:pick][:organization]).people
    73:         when "group"
    74:           people = Group.find(flash[:pick][:group]).people
    75:         when "personal_group"
    76:           people = PersonalGroup.find(flash[:pick][:personal_group]).people
    77:         when "person"
    78:           people = [Person.find(flash[:pick][:person])]
    79:         end
    80:         @people_ids = people.map(&:id).join(", ")
    81:         @people_names = people.map(&:name).join(", ")
    82:       when "mail"
    83:         if flash[:pick][:mail]
    84:           @mail = flash[:pick][:mail]
    85:           if @mail[:recipients]
    86:             @recipients = Person.find(@mail[:recipients])
    87:           end
    88:         end
    89:       when "record"
    90:         @record = flash[:pick][:record] || {}
    91:       end
    92:     end
    93:   end

[Validate]