# encoding : utf-8 module BeautifulHelper def visible_column(model_name, field_name, display_default = 'table-cell', other_css = "") return ('style="display:' + ((session[:fields][model_name.to_sym].to_a.include?(field_name)) ? display_default : 'none') + ';' + other_css + '"').html_safe end def dropdown_submenu(link_caption, &block) the_link = link_to((link_caption + ' ').html_safe, "#", :class => "dropdown-toggle", "data-toggle" => "dropdown") contents = (block_given?) ? content_tag_string(:ul, capture(&block), :class => "dropdown-menu") : '' content_tag_string :li, the_link + contents, :class => "dropdown" end def sorting_header(model_name, attribute_name, namespace) attr = nil sort = nil if not params[:sorting].blank? then attr = params[:sorting][:attribute] sort = params[:sorting][:sorting] end attr = attr.to_s.downcase sortstr = sort.to_s.downcase opposite_sortstr = "" csort = '' # if attribute_name == attr then if sortstr == "asc" then csort = '' opposite_sortstr = "desc" elsif sortstr == "desc" then csort = '' opposite_sortstr = "asc" end else opposite_sortstr = "asc" end default_caption = attribute_name.capitalize if is_belongs_to_column?(default_caption) then default_caption = get_belongs_to_model(default_caption) end cap = attribute_name cap = "number-attr" if attribute_name == "number" caption = t(cap, :default => default_caption).capitalize strpath = model_name.pluralize + "_url" strpath = namespace + '_' + strpath if not namespace.blank? return link_to( "#{csort} #{caption}".html_safe, eval(strpath) + "?" + CGI.unescape({:sorting => {:attribute => attribute_name.downcase,:sorting => opposite_sortstr}}.to_query) ).html_safe end def ransack_field(path_of_model, attribute_name, f, caption = nil) model_path = path_of_model.split("/") model_name = model_path.last model_path.delete(model_path.first) model_name_for_ransack = model_path.join("_") ar_model = model_name.classify.constantize default_caption = caption if default_caption.blank? then default_caption = attribute_name.capitalize if is_belongs_to_column?(default_caption) then default_caption = get_belongs_to_model(default_caption) end end name_field = attribute_name name_field_bk = attribute_name label_field = attribute_name if is_belongs_to_column?(name_field_bk) then label_field = get_belongs_to_model(attribute_name) end name_field = model_name_for_ransack + "_" + name_field unless model_name_for_ransack.blank? cap = label_field cap = "number-attr" if label_field == "number" response = '