app/presentation/section_renderer.rb in umlaut-3.3.1 vs app/presentation/section_renderer.rb in umlaut-4.0.0.beta1

- old
+ new

@@ -61,10 +61,12 @@ # # * this section is assumed to contain responses of type # ServiceTypeValue["fulltext"] # # * The section will be displayed with stock heading block including a title +# from Rails i18n under key `umlaut.display_sections.#{section_id}.title`, +# or if not there then # constructed from the display_name of ServiceTypeValue["fulltext"], or # in general the display_name of the first ServiceTypeValue included # in this section. # # * The section will include a stock 'spinner' if there are potential background @@ -100,15 +102,22 @@ # # Note that a custom partial needs to be supplied if there are no service_type_values supplied. # # === Customizing heading display # -# You can supply a title for the section that's different than what would +# Using Rails i18n, you can supply a title for the section that's different than what would # be guessed from it's ServiceTypeValues. You can also supply a prompt. # -# {:div_id =>"excerpts", :section_title=>"Lots of good stuff", :section_prompt => "Limited previes and excerpts."} +# {:div_id =>"excerpts"} # +# In your config/locales/en.yml (or other language): +# umlaut: +# display_sections: +# excerpts: +# title: "Really great Excerpts" +# prompt: "Click on them to see them, far out!" +# # You can also suppress display of the stock section heading at all: # {:show_heading => false, ...} # # This may be becuase you don't want a heading, or because you are supplying # a custom partial that will take care of the heading in a custom way. @@ -118,13 +127,20 @@ # You can also suppress display of the stock spinner, because you don't # want a spinner, or because your custom partial will be taking care of it. # {:show_spinner => false, ...} # # By default, the spinner displays what type of thing it's waiting on, guessing -# from the ServiceTypeValue configured. If you want to specify this item name: -# {:item_name_plural => "Related Items", ...} +# from the ServiceTypeValue configured. If you want to specify this item name, +# use Rails i18n under the section_id in config/locales/en.yml, generally +# using a plural name: # +# umlaut: +# display_sections: +# excerpts: +# load_more_item_name: "amazing excerpts" +# +# # === Customizing visibility of section # # By default, a section will simply be displayed regardless of whether # there are any actual responses to display. However, the 'visibility' # argument can be used to customize this in many ways. @@ -229,19 +245,16 @@ # resolve_views finding one with :div_id == id # * [div_id] The id of the <div> the section lives in. Also used # generally as unique ID for the section. # * [service_type_values] ServiceTypeValue's that this section contains. # defaults to [ServiceTypeValue[div_id]] - # * [section_title] Title for the section. Defaults to + # * [section_title] (DEPRECATED, use Rails i18n) Title for the section. Defaults to # service_type_values.first.display_name # * [section_prompt] Prompt. Default nil. # * [show_heading] Show the heading section at all. Default true. # * [show_spinner] Show a stock spinner for bg action for service_type_values. # default true. - # * [item_name_plural] Pluralized name of the objects included, used in - # spinner message. Default - # service_type_values.first.display_name_pluralize # * [visibilty] What logic to use to decide whether to show the section at # all. true|false|:any_services|:in_progress|:responses_exist|:complete_with_responses|(lambda object) # * [list_visible_limit] Use list_with_limit to limit initially displayed # items to value. Default nil, meaning don't use # list_with_limit. @@ -285,11 +298,11 @@ def responses unless (@responses) @responses = {} service_type_values.each do |st| @responses[st.name] = @umlaut_request.get_service_type(st) - end + end end @responses end # All the values from #responses, flattened into a simple Array. @@ -321,15 +334,19 @@ # A hash suitable to be passed to Rails render(), to render # a spinner for this section. Called by section_display partial, # nobody else should need to call it. def spinner_render_hash + custom_item_name = I18n.t("load_more_item_name", :scope => "umlaut.display_sections.#{self.div_id}", :default => "") + custom_item_name = nil if custom_item_name.blank? + { :partial => "background_progress", :locals =>{ :svc_types => service_type_values, :div_id => "progress_#{@section_id}", :current_set_empty => responses_empty?, - :item_name => @options[:item_name_plural]} + :item_name => custom_item_name + } } end def show_partial_only? @options[:show_partial_only] @@ -395,24 +412,61 @@ # do any services exist which even potentially generate our types, even # if they've completed without doing so?. def any_services? nil != @umlaut_request.dispatched_services.to_a.find do |ds| - ! (service_type_values & ds.service.service_types_generated ).empty? + ! (service_type_values & ds.can_generate_service_types ).empty? end end def list_visible_limit @options[:list_visible_limit] end + # Display title of the section can come from several places, in order + # of precedence: + # * 1. (DEPRECATED) :section_title key in config hash. Prefer i18n instead. + # * 2. Rails i18n, under key 'umlaut.display_sections.#{section_id}.title' + # * 3. If not given, as a default we use the display_name of the first ServiceTypeValue + # object included in this section's results. + # If still blank after all those lookups, then no section title. Set a section title + # to the empty string in i18n to force no section title. def section_title - @options[:section_title] + section_title = nil + + if @options.has_key? :section_title + # deprecation warning? Not sure the right way to do that. + section_title = @options[:section_title] + else + section_title = I18n.t("title", :scope => "umlaut.display_sections.#{self.div_id}", + :default => Proc.new { + # Look up from service_type name if possible as default + if (service_type_values.length > 0) + service_type_values.first.display_name_pluralize.titlecase + else + "" + end + }) + end + + section_title = nil if section_title.blank? + return section_title end + # Optional section prompt, from Rails i18n key `umlaut.display_sections.#{section_div_id}.prompt` + # Deprecated legacy, you can force with :section_prompt key in section config hash. def section_prompt - @options[:section_prompt] + prompt = nil + + if @options.has_key?(:section_prompt) + prompt = @options[:section_prompt] + else + prompt = I18n.t("prompt", :scope => "umlaut.display_sections.#{self.div_id}", :default => "") + end + + prompt = nil if prompt.blank? + return prompt end # For a given resonse type section, returns a string that will change # if the rendered HTML has changed, HTTP etag style. # @@ -448,18 +502,10 @@ :show_partial_only => false, :partial_locals => {}}.merge!(arguments) # service type value default to same name as section_id - @options[:service_type_values] ||= [@section_id] - - - # Fill in calculatable-defaults - if (service_type_values.length > 0) - @options = {:section_title => - service_type_values.first.display_name - }.merge(@options) - end + @options[:service_type_values] ||= [@section_id] # Partials to display. Default to _standard_response_item item partial. if ( @options[:partial] == true) @options[:partial] = @section_id end