Class | SearchController
In: | app/controllers/search_controller.rb
Parent: | ApplicationController

### Methods

add_item index order_item remove_item save

### Public Instance methods

add_item()

search_condition_items を追加する。

[Source]

        # File app/controllers/search_controller.rb, line 10
    10:   def add_item
    11:     @search_condition = SearchCondition.find_or_create_by_person_id_and_display_id(User.current.person_id, @display.id)
    12:   end

index()

[Source]

       # File app/controllers/search_controller.rb, line 4
    4:   def index
    5:     @search_condition = SearchCondition.find_or_create_by_person_id_and_display_id(User.current.person_id, @display.id)
    6:     load
    7:   end

order_item()

search_condition_items を並び替える。

[Source]

        # File app/controllers/search_controller.rb, line 20
    20:   def order_item
    21:     search_condition = verified_search_condition
    22:     render :update do |page|
    23:       page[:order_search_condition_items].value = params[:search_condition].to_json
    24:     end
    25:   end

remove_item()

search_condition_items を削除する。

[Source]

        # File app/controllers/search_controller.rb, line 15
    15:   def remove_item
    16:     @search_condition = SearchCondition.find_or_create_by_person_id_and_display_id(User.current.person_id, @display.id)
    17:   end

save()

編集した検索条件を保存する。

[Source]

        # File app/controllers/search_controller.rb, line 28
    28:   def save
    29:     @search_condition = SearchCondition.find_or_create_by_person_id_and_display_id(User.current.person_id, @display.id)
    30:     load
    31:     begin
    32:       # WARNING: must be replaced by ActiveSupport::JSON.decode with Rails 2.0.x
    33:       @old_search_condition_items = eval(params[:old_search_condition_items] || "[]")
    34:       raise "must be an array" unless @old_search_condition_items.is_a?(Array)
    35:       @old_search_condition_items.each {|id| raise "must be an positive integer" unless id.is_a?(Integer) && id > 0}
    36:     rescue StandardError # ActiveSupport::JSON::ParseError
    37:       @old_search_condition_items = []
    38:     end
    39:     begin
    40:       # WARNING: must be replaced by ActiveSupport::JSON.decode with Rails 2.0.x
    41:       @new_search_condition_items = eval(params[:new_search_condition_items] || "[]")
    42:       raise "must be an array" unless @new_search_condition_items.is_a?(Array)
    43:       @new_search_condition_items.each {|id| raise "must be an positive integer" unless id.is_a?(Integer) && id > 0}
    44:     rescue StandardError # ActiveSupport::JSON::ParseError
    45:       @new_search_condition_items = []
    46:     end
    47:     begin
    48:       # WARNING: must be replaced by ActiveSupport::JSON.decode with Rails 2.0.x
    49:       @order_search_condition_items = eval(params[:order_search_condition_items] || "[]")
    50:       raise "must be an array" unless @order_search_condition_items.is_a?(Array)
    51:       @order_search_condition_items.each {|id| raise "must be a string" unless id.is_a?(String)}
    52:     rescue StandardError # ActiveSupport::JSON::ParseError
    53:       @order_search_condition_items = []
    54:     end
    55:     proc = lambda do |item, prefix|
    56:       if ( (item_id           = params["#{prefix}_item_id".to_sym]) &&
    57:            (condition_value   = params["#{prefix}_condition_value".to_sym]) &&
    58:            (condition_pattern = params["#{prefix}_condition_pattern".to_sym]) &&
    59:            (order_by          = params["#{prefix}_order_by".to_sym]) )
    60:         item.item_id             = item_id
    61:         item.condition_value     = condition_value
    62:         item.condition_pattern   = condition_pattern
    63:         item.order_by            = order_by
    64:         item.save!
    65:       end
    66:     end
    67:     SearchConditionItem.transaction do
    68:       items = []
    69:       @search_condition.search_condition_items.each do |item|
    70:         if @old_search_condition_items.include?(item.id)
    71:           # remove the old item
    72:           item.destroy
    73:         elsif k = @order_search_condition_items.index("item_#{item.id}")
    74:           # update the item
    75:           proc.call(item, "item_#{item.id}")
    76:           items[k] = item
    77:         end
    78:       end
    79:       @new_search_condition_items.each do |n|
    80:         if k = @order_search_condition_items.index("newbie_#{n}")
    81:           # add a new item
    82:           item = SearchConditionItem.new(:search_condition_id => @search_condition.id)
    83:           proc.call(item, "newbie_#{n}")
    84:           items[k] = item
    85:         end
    86:       end
    87:       # sort items
    88:       items.each_with_index {|item, i| item.insert_at(i + 1) if item}
    89:     end
    90:     x_close_or_redirect_to :controller => "product", :action => "list", :list => @display.id, :id => @display.product_id
    91:   end

[Validate]