Module: ApplicationHelper
- Defined in:
- frontend/app/helpers/application_helper.rb,
public/app/helpers/application_helper.rb
Instance Method Summary collapse
-
#add_new_event_url(record) ⇒ Object
-
#bootstrap_class_for(flash_type) ⇒ Object
-
#button_confirm_action(label, target, opts = {}) ⇒ Object
-
#button_delete_action(url, opts = {}) ⇒ Object
-
#button_delete_multiple_action(target_action) ⇒ Object
-
#button_edit_multiple_action(target_controller, target_action = :batch, opts = {}) ⇒ Object
-
#button_get_selector(label, target, opts = {}) ⇒ Object
-
#clean_mixed_content(content) ⇒ Object
-
#current_repo ⇒ Object
-
#current_user ⇒ Object
-
#display_audit_info(hash, opts = {}) ⇒ Object
-
#edit_mode? ⇒ Boolean
-
#export_csv(search_data) ⇒ Object
-
#flash_messages(opts = {}) ⇒ Object
-
#full_mode? ⇒ Boolean
-
#get_subject_icon_class(obj) ⇒ Object
ANW-521: given an object, if it is a subject, return the class needed to display the correct icon in the interface.
-
#has_agent_subrecords?(agent) ⇒ Boolean
-
#has_permission_for_controller?(session, name) ⇒ Boolean
-
#include_controller_js ⇒ Object
-
#include_theme_css ⇒ Object
-
#inline? ⇒ Boolean
-
#job_types ⇒ Object
-
#link_to_help(opts = {}) ⇒ Object
-
#link_to_merge_params(label, new_params, html_options = {}) ⇒ Object
Merge new_params into params and generate a link.
-
#proxy_localhost? ⇒ Boolean
-
#render_aspace_partial(args) ⇒ Object
See: ApplicationController#render_aspace_partial.
-
#render_token(opts) ⇒ Object
-
#set_title(title) ⇒ Object
-
#setup_context(options) ⇒ Object
-
#show_external_ids? ⇒ Boolean
-
#supported_locales_default ⇒ Object
-
#supported_locales_options ⇒ Object
-
#wrap_with_tooltip(text, i18n_path, classes) ⇒ Object
Instance Method Details
#add_new_event_url(record) ⇒ Object
329 330 331 332 333 334 335 |
# File 'frontend/app/helpers/application_helper.rb', line 329 def add_new_event_url(record) if record.jsonmodel_type == "agent" url_for(:controller => :events, :action => :new, :agent_uri => record.uri, :event_type => "${event_type") else url_for(:controller => :events, :action => :new, :record_uri => record.uri, :record_type => record.jsonmodel_type, :event_type => "${event_type}") end end |
#bootstrap_class_for(flash_type) ⇒ Object
5 6 7 |
# File 'public/app/helpers/application_helper.rb', line 5 def bootstrap_class_for flash_type { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type.to_sym] || flash_type.to_s end |
#button_confirm_action(label, target, opts = {}) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'frontend/app/helpers/application_helper.rb', line 195 def (label, target, opts = {}) btn_opts = { :"data-target" => target, :method => :post, :class => "btn", :"data-confirmation" => true, :"data-authenticity_token" => form_authenticity_token, :type => "button" }.merge(opts) (label, btn_opts) end |
#button_delete_action(url, opts = {}) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 |
# File 'frontend/app/helpers/application_helper.rb', line 220 def (url, opts = {}) (opts[:label] || I18n.t("actions.delete"), url, { :class => "btn btn-sm btn-danger delete-record", :"data-title" => I18n.t("actions.delete_confirm_title"), :"data-message" => I18n.t("actions.delete_confirm_message"), :"data-confirm-btn-label" => "#{I18n.t("actions.delete")}", :"data-confirm-btn-class" => "btn-danger" }.merge(opts)) end |
#button_delete_multiple_action(target_action) ⇒ Object
233 234 235 236 237 238 239 240 241 242 |
# File 'frontend/app/helpers/application_helper.rb', line 233 def (target_action) (url_for(:controller => :batch_delete, :action => target_action), { :class => "btn btn-sm btn-danger multiselect-enabled", :"data-multiselect" => "#tabledSearchResults", :"data-title" => I18n.t("actions.delete_multiple_confirm_title"), :"data-message" => I18n.t("actions.delete_multiple_confirm_message"), :"data-confirm-btn-label" => "#{I18n.t("actions.delete_multiple")}", :disabled => "disabled" }) end |
#button_edit_multiple_action(target_controller, target_action = :batch, opts = {}) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'frontend/app/helpers/application_helper.rb', line 244 def (target_controller, target_action = :batch, opts = {} ) label = opts[:label] || I18n.t("actions.edit_batch") btn_opts = { :"data-target" => url_for(:controller => target_controller, :action => target_action), :class => "btn btn-sm btn-default multiselect-enabled edit-batch", :method => "post", :type => "button", :"data-multiselect" => "#tabledSearchResults", :"data-confirmation" => true, :"data-title" => I18n.t("actions.edit_multiple_confirm_title"), :"data-message" => I18n.t("actions.edit_multiple_confirm_message"), :"data-confirm-btn-label" => "#{I18n.t("actions.edit_multiple")}", :"data-authenticity_token" => form_authenticity_token, :disabled => "disabled" }.merge(opts) (label, btn_opts) end |
#button_get_selector(label, target, opts = {}) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 |
# File 'frontend/app/helpers/application_helper.rb', line 208 def (label, target, opts = {}) btn_opts = { :"data-target" => target, :method => :post, :class => "btn", :"data-confirmation" => true, :"data-authenticity_token" => form_authenticity_token, :type => "button" }.merge(opts) (label, btn_opts) end |
#clean_mixed_content(content) ⇒ Object
319 320 321 322 323 |
# File 'frontend/app/helpers/application_helper.rb', line 319 def clean_mixed_content(content) content = content.to_s return content if content.blank? MixedContentParser::parse(content, url_for(:root), { :wrap_blocks => false } ).to_s.html_safe end |
#current_repo ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'frontend/app/helpers/application_helper.rb', line 151 def current_repo return nil if session[:repo].blank? return @current_repo if @current_repo != nil @current_repo = false MemoryLeak::Resources.get(:repository).each do |repo| @current_repo = repo if repo['uri'] === session[:repo] end @current_repo end |
#current_user ⇒ Object
170 171 172 |
# File 'frontend/app/helpers/application_helper.rb', line 170 def current_user session[:user] end |
#display_audit_info(hash, opts = {}) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'frontend/app/helpers/application_helper.rb', line 263 def display_audit_info(hash, opts = {}) fmt = opts[:format] || 'wide' ark_url = nil if AppConfig[:arks_enabled] && hash['ark_name'] # watch out! hash might be from a jsonmodel or from a solr result # don't blame me, i'm just trying to fit in around here ark_url = if hash["ark_name"].is_a?(Array) hash["ark_name"].first else hash["ark_name"]["current"] end end html = "<div class='audit-display-#{fmt}'><small>" if hash['create_time'] and hash['user_mtime'] if fmt == 'wide' html << "<strong>#{I18n.t("search_results.created")} #{hash['created_by']}</strong>" html << " #{Time.parse(hash['create_time']).getlocal}" html << ' | ' html << "<strong>#{I18n.t("search_results.modified")} #{hash['last_modified_by']}</strong>" html << " #{Time.parse(hash['user_mtime']).getlocal}" html << ' | ' html << "<label for=\"uri\"><strong>URI:</strong> </label>" html << "<input type=\"text\" id=\"uri\" readonly=\"1\" value=\"#{hash['uri']}\" size=\"#{hash['uri'].length}\" style=\"background: #f1f1f1 !important; border: none !important; font-family: monospace;\"/>" if !ark_url.nil? html << ' | ' html << "<label for=\"ark\"><strong>ARK:</strong> </label>" html << "<input type=\"text\" id=\"ark\" readonly=\"1\" value=\"#{ark_url}\" size=\"#{ark_url.length}\" style=\"background: #f1f1f1 !important; border: none !important; font-family: monospace;\"/>" end else html << "<dl>" html << "<dt>#{I18n.t("search_results.created")} #{hash['created_by']}</dt>" html << "<dd>#{Time.parse(hash['create_time']).getlocal}</dd>" html << "<dt>#{I18n.t("search_results.modified")} #{hash['last_modified_by']}</dt>" html << "<dd>#{Time.parse(hash['user_mtime']).getlocal}</dd>" html << "</dl>" end end html << "</small></div><div class='clearfix'></div>" html.html_safe end |
#edit_mode? ⇒ Boolean
142 143 144 |
# File 'frontend/app/helpers/application_helper.rb', line 142 def edit_mode? ['edit', 'update'].include?(controller.action_name) end |
#export_csv(search_data) ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'frontend/app/helpers/application_helper.rb', line 341 def export_csv(search_data) results = search_data["results"] headers = results.inject([]) { |h, r| h | r.keys } headers.delete("json") CSV.generate do |csv| csv << headers results.each do |result| data = [] headers.each do |h| unless result.include?(h) data << nil next end v = result[h] v = v.join(";") if v.is_a?(Array) v = v.to_s v.gsub!('\"', '""') v.delete!("\n") v.delete!(",") data << v end csv << data end end end |
#flash_messages(opts = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'public/app/helpers/application_helper.rb', line 9 def (opts = {}) flash.each do |msg_type, | concat(content_tag(:div, , class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible", role: 'alert') do concat(content_tag(:button, class: 'close', data: { dismiss: 'alert' }) do concat content_tag(:span, '×'.html_safe, 'aria-hidden' => true) concat content_tag(:span, 'Close', class: 'sr-only') end) concat (.is_a?(Array) ? .join('<br/>').html_safe : .html_safe) end) end nil end end |
#full_mode? ⇒ Boolean
424 425 426 |
# File 'frontend/app/helpers/application_helper.rb', line 424 def full_mode? user_can?("show_full_agents") || user_can?("administer_system") end |
#get_subject_icon_class(obj) ⇒ Object
ANW-521: given an object, if it is a subject, return the class needed to display the correct icon in the interface
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'frontend/app/helpers/application_helper.rb', line 381 def get_subject_icon_class(obj) if obj['_resolved'] if obj['_resolved']['jsonmodel_type'] && obj['_resolved']['jsonmodel_type'] == "subject" term_type = obj['_resolved']['terms'][0]["term_type"] rescue nil case term_type when "cultural_context" return "subject_type_cultural_context" when "function" return "subject_type_function" when "genre_form" return "subject_type_genre_form" when "geographic" return "subject_type_geographic" when "occupation" return "subject_type_occupation" when "style_period" return "subject_type_style_period" when "technique" return "subject_type_technique" when "temporal" return "subject_type_temporal" when "topical" return "subject_type_topical" when "uniform_title" return "subject_type_uniform_title" end end end end |
#has_agent_subrecords?(agent) ⇒ Boolean
428 429 430 431 432 433 434 |
# File 'frontend/app/helpers/application_helper.rb', line 428 def has_agent_subrecords?(agent) # agent_person has all agent subrecord types so is ideal for finding any potential subrecord JSONModel(:agent_person).properties_by_tag('agent_subrecord').map(&:first).map(&:to_sym).find do |subrecord| return unless agent.methods.include?(subrecord) agent.send(subrecord).length.positive? end end |
#has_permission_for_controller?(session, name) ⇒ Boolean
305 306 307 308 309 310 |
# File 'frontend/app/helpers/application_helper.rb', line 305 def (session, name) controller_class_name = "#{name}_controller".classify controller_class = Kernel.const_get(controller_class_name) controller_class.can_access?(self, :index) end |
#include_controller_js ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'frontend/app/helpers/application_helper.rb', line 5 def include_controller_js scripts = "" scripts += javascript_include_tag "#{controller.controller_name}" if File.exist?("#{Rails.root}/app/assets/javascripts/#{controller_name}.js") || File.exist?("#{Rails.root}/app/assets/javascripts/#{controller_name}.js.erb") scripts += javascript_include_tag "#{controller.controller_name}.#{controller.action_name}" if File.exist?("#{Rails.root}/app/assets/javascripts/#{controller_name}.#{controller.action_name}.js") || File.exist?("#{Rails.root}/app/assets/javascripts/#{controller_name}.#{controller.action_name}.js.erb") if ["new", "create", "edit", "update"].include?(controller.action_name) scripts += javascript_include_tag "#{controller.controller_name}.crud" if File.exist?("#{Rails.root}/app/assets/javascripts/#{controller_name}.crud.js") || File.exist?("#{Rails.root}/app/assets/javascripts/#{controller_name}.crud.js.erb") end if ["batch_create"].include?(controller.action_name) scripts += javascript_include_tag "#{controller.controller_name}.batch" if File.exist?("#{Rails.root}/app/assets/javascripts/#{controller_name}.batch.js") || File.exist?("#{Rails.root}/app/assets/javascripts/#{controller_name}.batch.js.erb") end if ["defaults", "update_defaults"].include?(controller.action_name) ctrl_name = controller.controller_name == 'archival_objects' ? 'resources' : controller.controller_name scripts += javascript_include_tag "#{ctrl_name}.crud" if File.exist?("#{Rails.root}/app/assets/javascripts/#{ctrl_name}.crud.js") || File.exist?("#{Rails.root}/app/assets/javascripts/#{ctrl_name}.crud.js.erb") end scripts.html_safe end |
#include_theme_css ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'frontend/app/helpers/application_helper.rb', line 30 def include_theme_css begin css = "" css += stylesheet_link_tag("themes/#{ArchivesSpace::Application.config.frontend_theme}/bootstrap", :media => "all") css += stylesheet_link_tag("themes/#{ArchivesSpace::Application.config.frontend_theme}/application", :media => "all") css.html_safe rescue # On app startup in dev mode, the above call triggers the LESS stylesheets # to compile, and there seems to be a problem with two threads doing this # concurrently. If things go badly, just retry. Rails.logger.warn("Retrying include_theme_css: #{$!}") sleep 1 retry end end |
#inline? ⇒ Boolean
146 147 148 |
# File 'frontend/app/helpers/application_helper.rb', line 146 def inline? params[:inline] === "true" end |
#job_types ⇒ Object
165 166 167 |
# File 'frontend/app/helpers/application_helper.rb', line 165 def job_types MemoryLeak::Resources.get(:job_types) end |
#link_to_help(opts = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'frontend/app/helpers/application_helper.rb', line 109 def link_to_help(opts = {}) return if not ArchivesSpaceHelp.enabled? return if opts.has_key?(:topic) and not ArchivesSpaceHelp.topic?(opts[:topic]) href = (opts.has_key? :topic) ? ArchivesSpaceHelp.url_for_topic(opts[:topic]) : ArchivesSpaceHelp.base_url label = opts[:label] || I18n.t("help.icon") label_text = "<span class='sr-only'> Visit the " + I18n.t("help.help_center") + "</span>" title = (opts.has_key? :topic) ? I18n.t("help.topics.#{opts[:topic]}", :default => I18n.t("help.default_tooltip", :default => "")) : I18n.t("help.default_tooltip", :default => "") x_padding = session[:user].nil? ? "px-4" : "px-3" klass = (opts.has_key? :class) ? opts[:class] : "" style = (opts.has_key? :style) ? opts[:style] : "" link_to( label.html_safe + label_text.html_safe, href, { :target => "_blank", :title => title, :class => "context-help has-tooltip #{x_padding} #{klass}", :style => style, "data-placement" => "bottom", "data-toggle" => "tooltip", "data-boundary" => "viewport" }.merge(opts[:link_opts] || {}) ) end |
#link_to_merge_params(label, new_params, html_options = {}) ⇒ Object
Merge new_params into params and generate a link.
Intended to avoid security issues associated with passing user-generated
params
as the opts
for link_to (which allows them to set the host,
controller, etc.)
374 375 376 377 378 |
# File 'frontend/app/helpers/application_helper.rb', line 374 def link_to_merge_params(label, new_params, = {}) link_to(label, params.except(:controller, :action).to_unsafe_h.merge(new_params), ) end |
#proxy_localhost? ⇒ Boolean
325 326 327 |
# File 'frontend/app/helpers/application_helper.rb', line 325 def proxy_localhost? AppConfig[:public_proxy_url] =~ /localhost/ end |
#render_aspace_partial(args) ⇒ Object
See: ApplicationController#render_aspace_partial
314 315 316 317 |
# File 'frontend/app/helpers/application_helper.rb', line 314 def render_aspace_partial(args) defaults = {:formats => [:html], :handlers => [:erb]} return render(defaults.merge(args)) end |
#render_token(opts) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'frontend/app/helpers/application_helper.rb', line 88 def render_token(opts) link_opts = {:class => "btn btn-mini"} link_opts.merge!({:target => "_blank"}) if opts[:inside_token_editor] || opts[:inside_linker_browse] popover_url = url_for :controller => :resolver, :action => :resolve_readonly popover_url += "?uri=#{opts[:uri]}" popover_content = link_to I18n.t("actions.view"), popover_url, link_opts html = "<div class='" html += "token " if not opts[:inside_token_editor] html += "#{opts[:type]} has-popover' data-toggle='popover' data-trigger='#{opts[:trigger] || "custom"}' data-html='true' data-placement='#{opts[:placement] || "bottom"}' data-content=\"#{CGI.escape_html(popover_content)}\" tabindex='1'>" if opts[:icon_class] html += "<span class='icon-token #{opts[:icon_class]}'></span>" else html += "<span class='icon-token'></span>" end html += clean_mixed_content(opts[:label]) html += "</div>" html.html_safe end |
#set_title(title) ⇒ Object
49 50 51 |
# File 'frontend/app/helpers/application_helper.rb', line 49 def set_title(title) @title = title end |
#setup_context(options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'frontend/app/helpers/application_helper.rb', line 53 def setup_context() = [:trail] || [] if .has_key? :object object = [:object] type = [:type] || object["jsonmodel_type"] controller = [:controller] || type.to_s.pluralize title = ([:title] || object["title"] || object["username"]).to_s .push([I18n.t("#{controller.to_s.singularize}._plural"), {:controller => controller, :action => :index}]) if object.id .push([title, {:controller => controller, :action => :show}]) .last.last[:id] = object.id unless object['username'] if ["edit", "update"].include? action_name .push([I18n.t("actions.edit")]) set_title("#{I18n.t("#{type}._plural")} | #{title} | #{I18n.t("actions.edit")}") else set_title("#{I18n.t("#{type}._plural")} | #{title}") end else # new object .push([[:title] || "#{I18n.t("#{type}.new_title")}"]) set_title("#{I18n.t("#{controller.to_s.singularize}._plural")} | #{options[:title] || I18n.t("actions.new_prefix")}") end elsif .has_key? :title set_title([:title]) .push([[:title]]) end render_aspace_partial(:partial =>"shared/breadcrumb", :layout => false , :locals => { :trail => }).to_s if [:suppress_breadcrumb] != true end |
#show_external_ids? ⇒ Boolean
337 338 339 |
# File 'frontend/app/helpers/application_helper.rb', line 337 def show_external_ids? AppConfig[:show_external_ids] == true end |
#supported_locales_default ⇒ Object
414 415 416 417 418 |
# File 'frontend/app/helpers/application_helper.rb', line 414 def supported_locales_default { default: user_prefs.key?('locale') ? user_prefs['locale'] : I18n.default_locale.to_s } end |
#supported_locales_options ⇒ Object
420 421 422 |
# File 'frontend/app/helpers/application_helper.rb', line 420 def I18n.supported_locales.map { |k, v| [t("enumerations.language_iso639_2.#{v}"), k] } end |
#wrap_with_tooltip(text, i18n_path, classes) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'frontend/app/helpers/application_helper.rb', line 175 def wrap_with_tooltip(text, i18n_path, classes) tooltip = I18n.t_raw(i18n_path, :default => '') if tooltip.empty? return text else = {} [:title] = tooltip ["data-placement"] = "bottom" ["data-html"] = true ["data-delay"] = 500 ["data-trigger"] = "manual" ["data-boundary"] = "viewport" ["data-template"] = '<div class="tooltip archivesspace-help"><div class="arrow"></div><div class="tooltip-inner"></div></div>' [:class] = " has-tooltip #{classes}" content_tag(:span, text, ) end end |