module ResolveHelper # some useful methods started out as helper methods, but now are in the # Request model. We delegate them for convenience and backwards compat. delegate :get_service_type, :failed_service_dispatches, :service_type_in_progress?, :service_types_in_progress?, :any_services_in_progress?, :title_level_citation?, :to => :@user_request #backwards compat, should be called title_level_citation? delegated # to @user_request above, but some alias title_level_request? title_level_citation? # Will render an Umlaut HTML section. See SectionRenderer. # Argument can be: # 1. An already initialized SectionRenderer # 2. :id => X, will load Section description hash from the resolve_sections # configuration, finding description hash with :div_id == X. # 3. A complete section description hash. Ordinarily only used when that # complete hash was previously looked up from resolve_sections config. # # For documentation of possible values in the section descripton hash, # see SectionRenderer. def render_section(arguments = {}) if arguments.kind_of?( SectionRenderer ) presenter = arguments else presenter = SectionRenderer.new(@user_request, arguments ) end render(:partial => "section_display", :locals => {:presenter => presenter } ) end def app_name return umlaut_config.app_name end # size can be 'small', 'medium', or 'large. # returns a ServiceResponse object, or nil. def cover_image_response(size='medium') cover_images = get_service_type('cover_image') cover_images.each do |service_response| return service_response if service_response.service_data[:size] == size end return nil end # Did this come from citation linker style entry? # We check the referrer. def user_entered_citation?(uml_request) return false unless uml_request && uml_request.referrer_id id = uml_request.referrer_id return id == 'info:sid/sfxit.com:citation' || id == umlaut_config.lookup("rfr_ids.citation") || id == umlaut_config.lookup('rfr_ids.opensearch') end def display_not_found_warning?(uml_request) metadata = uml_request.referent.metadata display_manually_entered_typo_warning = umlaut_config.lookup!("entry_not_in_kb_warning", false) return (metadata['genre'] != 'book' && metadata['object_id'].blank? && user_entered_citation?(@user_request) && display_manually_entered_typo_warning) end # Generate content in an expand-contract block, with a heading that # you can click on to show/hide it. Actual content in block. # Example, in view: # <% expand_contract_section("My Content", "div_id_to_use") do %> # this will be hidden and shown # <% end %> def expand_contract_section(arg_heading, id, options={}, &block) expanded = (params["umlaut.show_#{id}"] == "true") || options[:initial_expand] || false icon = image_tag( ( expanded ? "list_open.png" : "list_closed.png"), :alt => "", :class => "toggle_icon", :border => "0") heading = content_tag(:span,( expanded ? "Hide " : "Show "), :class=>'expand_contract_action_label') + arg_heading link_params = params.merge('umlaut.request_id' => @user_request.id, "umlaut.show_#{id}" => (! expanded).to_s , # Need to zero out format-related params for when we're coming # from a partial html api request, so the link we generate # is not to format json/xml/etc. :format => nil, 'umlaut.response_format' => nil, 'umlaut.jsonp'=>nil, # In Rails3, an :anchor param will actually be used for #fragmentIdentifier # on end of url :anchor => "#{id}_toggle_link" ) # Make sure a self-referencing link from partial_html_sections # really goes to full HTML view. link_params[:action] = "index" if link_params[:action] == "partial_html_sections" return content_tag(:div, :class => "expand_contract_section") do link_to( icon + heading, link_params, :id => "#{id}_toggle_link", :class => "expand_contract_toggle" ) + "\n" + content_tag(:div, :id => id, :class => "expand_contract_content", :style => ("display: none;" unless expanded), &block) end end # Code-generating helper to add a "More" link to a list, with a maximum # number of items to show before 'more'. AJAXy show, with unobtrusive # degredation when no javascript. # Based on the idea here for a helper that takes a block. Uses # expand_contract_section for actual hidden overflow. Will split list # into two different