module LookingForHelper # # = Looking For Helper # # Creates a link tag to open LookingFor search form with the given options. # # ==== Signatures # # looking_for(object_name, method_names, link_body, options = {}, html_options = {}) # # * object_name - A model name, for example 'Item' or a collection in a one-to-many association (for example 'user.items' if user has many items). # * method_names - An array of method names for build the results columns (for example [:id, :code, :description] if id, code, description are attributues of object_name) # * link_body - The link body # # ==== options # # * :fill - Fill html input with value from database ( db_field => input_tag_id ) when a row is selected. # * :width - Width of dialog, optional, default 500px. # * :height - Height of dialog, optional, default 300px. # # ==== html_options # # Like html_options in link_to helper but :remote will be always true. # # ==== Examples # # <%= looking_for 'Item', # [:id,:code,:description], # 'search', # { :fill => {:id => :item_id, # :code => :item_code, # :description => :item_description}, # :width => 550, # :height => 360}, # :id => 'looking_for_items' %> def looking_for(*args) opt = args[3] || {} opt[:controller] = :looking_for opt[:action] = :search opt[:width] ||= 500 opt[:height] ||= 300 opt[:object_name] = args.first opt[:method_names] = args[1] html_opt = args[4] || {} html_opt[:remote] = true link_to args[2], opt, html_opt end end