Module: ApplicationHelper
- Defined in:
- app/helpers/application_helper.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
Constant Summary collapse
- STYLES =
{ large: "180x180#", medium: "50x50#", small: "25x25#", thumb: "16x16#" }.freeze
Instance Method Summary collapse
-
#address_field(form, attribute, extra_styles) ⇒ Object
Render a text field that is part of compound address.
- #ai_prompt_link(prompt) ⇒ Object
-
#arrow_for(id) ⇒ Object
—————————————————————————-.
-
#avatar_for(model, args = {}) ⇒ Object
Entities can have associated avatars or gravatars.
-
#col(title, value = nil, last = false, email = false, &_block) ⇒ Object
Create a column in the ‘asset_attributes’ table.
-
#confirm_delete(model, params = {}) ⇒ Object
—————————————————————————-.
- #entity_filter_checkbox(name, value, count) ⇒ Object
- #exposed ⇒ Object
- #generate_js_for_popups(related, *assets) ⇒ Object
-
#get_browser_timezone_offset ⇒ Object
Ajax helper to pass browser timezone offset to the server.
-
#get_default_permissions_intro(access, text) ⇒ Object
Returns default permissions intro.
-
#get_icon(name) ⇒ Object
—————————————————————————- Translate List name to FontAwesome icon text.
- #group_options ⇒ Object
-
#hidden ⇒ Object
—————————————————————————-.
-
#hidden_if(you_ask) ⇒ Object
—————————————————————————-.
- #invisible ⇒ Object
-
#invisible_if(you_ask) ⇒ Object
—————————————————————————-.
-
#jumpbox(current) ⇒ Object
—————————————————————————-.
-
#link_to_cancel(url, params = {}) ⇒ Object
—————————————————————————-.
-
#link_to_close(url) ⇒ Object
—————————————————————————-.
-
#link_to_delete(record, options = {}) ⇒ Object
—————————————————————————-.
-
#link_to_discard(object) ⇒ Object
—————————————————————————-.
-
#link_to_edit(record, options = {}) ⇒ Object
—————————————————————————-.
-
#link_to_email(email, length = nil, &_block) ⇒ Object
Bcc: to dropbox address if the dropbox has been set up.
-
#link_to_inline(id, url, options = {}) ⇒ Object
—————————————————————————-.
-
#link_to_phone(number) ⇒ Object
Format a phone number as a tel: hyperlink.
-
#links_to_export(action = :index) ⇒ Object
Helper to display links to supported data export formats.
- #list_of_entities ⇒ Object
-
#load_select_popups_for(related, *assets) ⇒ Object
—————————————————————————-.
-
#one_submit_only(_form = '') ⇒ Object
—————————————————————————-.
-
#options_menu_item(option, key, url = send("redraw_#{controller.controller_name}_path")) ⇒ Object
—————————————————————————-.
-
#paginate(options = {}) ⇒ Object
—————————————————————————- Ajaxification FTW! e.g.
-
#phone_field_with_pattern(form, method, options = {}) ⇒ Object
Render a phone field with an optional pattern for international format.
-
#rating_select(name, options = {}) ⇒ Object
We need this because standard Rails [select] turns ★ into ★ —————————————————————————-.
-
#redraw(option, value, url = send("redraw_#{controller.controller_name}_path")) ⇒ Object
Ajax helper to refresh current index page once the user selects an option.
-
#refresh_sidebar(action = nil) ⇒ Object
Reresh sidebar using the action view within the current controller.
-
#refresh_sidebar_for(view, action = nil) ⇒ Object
Refresh sidebar using the action view within an arbitrary controller.
-
#section(related, assets) ⇒ Object
—————————————————————————-.
-
#section_title(id, hidden = true, text = nil, info_text = nil) ⇒ Object
—————————————————————————- Combines the ‘subtitle’ helper with the small info text on the same line.
-
#show_flash(options = { sticky: false }) ⇒ Object
Show existing flash or embed hidden paragraph ready for flash —————————————————————————-.
-
#shown_on_landing_page? ⇒ Boolean
Return true if: - it’s an Ajax request made from the asset landing page (i.e. create opportunity from a contact landing page) OR - we’re actually showing asset landing page.
-
#size_from_style!(options) ⇒ Object
Convert STYLE symbols to ‘w x h’ format for Gravatar and Rails e.g.
-
#spacer(width = 10) ⇒ Object
—————————————————————————-.
-
#styles_for(*models) ⇒ Object
—————————————————————————-.
-
#subtitle(id, hidden = true, text = id.to_s.split("_").last.capitalize) ⇒ Object
—————————————————————————-.
- #subtitle_link(id, text, hidden) ⇒ Object
-
#tabless_layout? ⇒ Boolean
—————————————————————————-.
- #tabs(tabs = nil) ⇒ Object
-
#template_for_current_view ⇒ Object
—————————————————————————- Get template in current context with current view name.
-
#timeago(time, options = {}) ⇒ Object
—————————————————————————- Generate the html for $.timeago function <span class=“timeago” datetime=“2008-07-17T09:24:17Z”>July 17, 2008</span>.
- #user_options ⇒ Object
-
#view_buttons ⇒ Object
—————————————————————————- Generate buttons for available views given the current context.
- #visible ⇒ Object
-
#web_presence_icons(person) ⇒ Object
Display web presence mini-icons for Contact or Lead.
Instance Method Details
#address_field(form, attribute, extra_styles) ⇒ Object
Render a text field that is part of compound address.
401 402 403 404 405 406 407 |
# File 'app/helpers/application_helper.rb', line 401 def address_field(form, attribute, extra_styles) hint = "#{t(attribute)}..." form.text_field(attribute, style: "margin-top: 6px; #{extra_styles}", placeholder: hint) end |
#ai_prompt_link(prompt) ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 |
# File 'app/helpers/application_helper.rb', line 377 def ai_prompt_link(prompt) return unless Setting[:about_my_business].present? || Setting[:how_i_plan_to_use_ffcrm].present? full_prompt = [Setting[:about_my_business], Setting[:how_i_plan_to_use_ffcrm], prompt].compact.compact_blank.join(". ") link_to(t(:ai_prompt_link), "https://chat.openai.com/?model=gpt-4o&prompt=#{URI.encode_uri_component(full_prompt)}", target: "_blank", title: "#{t(:ai_prompt_link_tooltip)}: #{prompt}", rel: "noopener noreferrer", class: "ai-prompt-link") end |
#arrow_for(id) ⇒ Object
101 102 103 |
# File 'app/helpers/application_helper.rb', line 101 def arrow_for(id) content_tag(:span, "▷".html_safe, id: "#{id}_arrow", class: :arrow) end |
#avatar_for(model, args = {}) ⇒ Object
Entities can have associated avatars or gravatars. Only calls Gravatar in production env. Gravatar won’t serve default images if they are not public: en.gravatar.com/site/implement/images
365 366 367 368 369 370 371 372 373 374 375 |
# File 'app/helpers/application_helper.rb', line 365 def avatar_for(model, args = {}) args = { class: 'gravatar', size: :large }.merge(args) args = size_from_style!(args) if model.respond_to?(:avatar) && model.avatar.present? size = args[:size].split('x').map(&:to_i) # convert '75x75' into [75, 75] image_tag model.avatar.image.variant(resize_to_limit: size), args else gravatar_image_tag(model.email, args) end end |
#col(title, value = nil, last = false, email = false, &_block) ⇒ Object
Create a column in the ‘asset_attributes’ table. If a block is given, render it inside the td
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'app/helpers/application_helper.rb', line 477 def col(title, value = nil, last = false, email = false, &_block) last_class = (last ? 'last' : nil) out = content_tag(:th, title, class: last_class) if block_given? out << content_tag(:td, class: last_class) do yield end else # Parse and format urls as links. fmt_value = (value.to_s || "").gsub("\n", "<br />") fmt_value = if email link_to_email(fmt_value) else fmt_value.gsub(%r{((http|ftp|https)://[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/\+#]*[\w\-\@?^=%&/\+#])?)}, "<a href=\"\\1\">\\1</a>") end out << content_tag(:td, fmt_value, class: last_class) end out end |
#confirm_delete(model, params = {}) ⇒ Object
239 240 241 242 243 244 245 246 |
# File 'app/helpers/application_helper.rb', line 239 def confirm_delete(model, params = {}) question = %(<span class="warn">#{t(:confirm_delete, model.class.to_s.downcase)}</span>) yes = link_to(t(:yes_button), params[:url] || model, method: :delete) no = link_to_function(t(:no_button), "$('#menu').html($('#confirm').html());") text = "$('#confirm').html( $('#menu').html() );\n" text += "$('#menu').html('#{question} #{yes} : #{no}');" text.html_safe end |
#entity_filter_checkbox(name, value, count) ⇒ Object
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'app/helpers/application_helper.rb', line 457 def entity_filter_checkbox(name, value, count) checked = (session["#{controller_name}_filter"].present? ? session["#{controller_name}_filter"].split(",").include?(value.to_s) : count.to_i.positive?) url = url_for(action: :filter) onclick = %{ var query = $('#query').val(), values = []; $('input[name="#{h name}[]"]').filter(':checked').each(function () { values.push(this.value); }); $('#loading').show(); $.post('#{url}', {#{h name}: values.join(','), query: query}, function () { $('#loading').hide(); }); }.html_safe check_box_tag("#{name}[]", value, checked, id: value, onclick: onclick) end |
#exposed ⇒ Object
211 212 213 |
# File 'app/helpers/application_helper.rb', line 211 def exposed { style: "display:block;" } end |
#generate_js_for_popups(related, *assets) ⇒ Object
73 74 75 76 77 |
# File 'app/helpers/application_helper.rb', line 73 def generate_js_for_popups(, *assets) assets.map do |asset| render(partial: "shared/select_popup", locals: { related: , popup: asset }) end.join end |
#get_browser_timezone_offset ⇒ Object
Ajax helper to pass browser timezone offset to the server.
340 341 342 |
# File 'app/helpers/application_helper.rb', line 340 def get_browser_timezone_offset raw "$.get('#{timezone_path}', {offset: (new Date()).getTimezoneOffset()});" unless session[:timezone_offset] end |
#get_default_permissions_intro(access, text) ⇒ Object
Returns default permissions intro.
391 392 393 394 395 396 397 |
# File 'app/helpers/application_helper.rb', line 391 def (access, text) case access when "Private" then t(:permissions_intro_private, text) when "Public" then t(:permissions_intro_public, text) when "Shared" then t(:permissions_intro_shared, text) end end |
#get_icon(name) ⇒ Object
Translate List name to FontAwesome icon text
555 556 557 558 559 560 561 562 563 564 565 |
# File 'app/helpers/application_helper.rb', line 555 def get_icon(name) case name when "tasks" then "fa-check-square-o" when "campaigns" then "fa-bar-chart-o" when "leads" then "fa-tasks" when "accounts" then "fa-users" when "contacts" then "fa-user" when "opportunities" then "fa-money" when "team" then "fa-globe" end end |
#group_options ⇒ Object
449 450 451 |
# File 'app/helpers/application_helper.rb', line 449 def Group.all.map { |g| [g.name, g.id] } end |
#hidden ⇒ Object
207 208 209 |
# File 'app/helpers/application_helper.rb', line 207 def hidden { style: "display:none;" } end |
#hidden_if(you_ask) ⇒ Object
229 230 231 |
# File 'app/helpers/application_helper.rb', line 229 def hidden_if(you_ask) you_ask ? hidden : exposed end |
#invisible ⇒ Object
215 216 217 |
# File 'app/helpers/application_helper.rb', line 215 def invisible { style: "visibility:hidden;" } end |
#invisible_if(you_ask) ⇒ Object
234 235 236 |
# File 'app/helpers/application_helper.rb', line 234 def invisible_if(you_ask) you_ask ? invisible : visible end |
#jumpbox(current) ⇒ Object
193 194 195 196 197 198 199 |
# File 'app/helpers/application_helper.rb', line 193 def jumpbox(current) tabs = %i[campaigns accounts leads contacts opportunities] current = tabs.first unless tabs.include?(current) tabs.map do |tab| link_to_function(t("tab_#{tab}"), "crm.jumper('#{tab}')", "html-data" => tab, class: (tab == current ? 'selected' : '')) end.join(" | ").html_safe end |
#link_to_cancel(url, params = {}) ⇒ Object
139 140 141 142 143 144 |
# File 'app/helpers/application_helper.rb', line 139 def link_to_cancel(url, params = {}) url = params[:url] if params[:url] link_to(t(:cancel), url + "#{url.include?('?') ? '&' : '?'}cancel=true", remote: true) end |
#link_to_close(url) ⇒ Object
147 148 149 150 151 152 |
# File 'app/helpers/application_helper.rb', line 147 def link_to_close(url) link_to("x", url + "#{url.include?('?') ? '&' : '?'}cancel=true", remote: true, class: "close", title: t(:close_form)) end |
#link_to_delete(record, options = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'app/helpers/application_helper.rb', line 117 def link_to_delete(record, = {}) confirm = [:confirm] || t(:confirm_delete, record.class.to_s.downcase) link_to(t(:delete) + "!", [:url] || url_for(record), method: :delete, remote: true, data: { confirm: confirm }) end |
#link_to_discard(object) ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'app/helpers/application_helper.rb', line 128 def link_to_discard(object) current_url = (request.xhr? ? request.referer : request.fullpath) parent, parent_id = current_url.scan(%r{/(\w+)/(\d+)}).flatten link_to(t(:discard), url_for(controller: parent, action: :discard, id: parent_id, attachment: object.class.name, attachment_id: object.id), method: :post, remote: true) end |
#link_to_edit(record, options = {}) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/application_helper.rb', line 106 def link_to_edit(record, = {}) object = record.is_a?(Array) ? record.last : record name = (params[:klass_name] || object.class.name).underscore.downcase link_to(t(:edit), [:url] || polymorphic_url(record, action: :edit), remote: true, onclick: "this.href = this.href.split('?')[0] + '?previous='+encodeURI(crm.find_form('edit_#{j name}'));".html_safe) end |
#link_to_email(email, length = nil, &_block) ⇒ Object
Bcc: to dropbox address if the dropbox has been set up.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/helpers/application_helper.rb', line 156 def link_to_email(email, length = nil, &_block) name = (length ? truncate(email, length: length) : email) bcc = Setting.email_dropbox mailto = if bcc && bcc[:address].present? "#{email}?bcc=#{bcc[:address]}" else email end if block_given? link_to("mailto:#{mailto}", title: email) do yield end else link_to(h(name), "mailto:#{mailto}", title: email) end end |
#link_to_inline(id, url, options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/application_helper.rb', line 89 def link_to_inline(id, url, = {}) text = [:text] || t(id, default: id.to_s.titleize) = ([:related] ? "&related=#{[:related]}" : '') link_to(text, url + "#{url.include?('?') ? '&' : '?'}cancel=false" + , remote: true, onclick: "this.href = this.href.replace(/cancel=(true|false)/,'cancel='+ ($('##{id}').css('display') != 'none'));", class: [:class]) end |
#link_to_phone(number) ⇒ Object
Format a phone number as a tel: hyperlink.
175 176 177 178 179 180 |
# File 'app/helpers/application_helper.rb', line 175 def link_to_phone(number) return nil if number.blank? sanitized_number = number.gsub(/[^0-9+]/, '') link_to number, "tel:#{sanitized_number}" end |
#links_to_export(action = :index) ⇒ Object
Helper to display links to supported data export formats.
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'app/helpers/application_helper.rb', line 421 def links_to_export(action = :index) token = current_user.authentication_token url_params = { action: action } url_params[:id] = params[:id] unless params[:id].blank? url_params[:query] = params[:query] unless params[:query].blank? url_params[:q] = params[:q] unless params[:q].blank? url_params[:view] = @view unless @view.blank? # tasks url_params[:id] = params[:id] unless params[:id].blank? exports = %w[xls csv].map do |format| link_to(format.upcase, url_params.merge(format: format), title: I18n.t(:"to_#{format}")) unless action.to_s == "show" end feeds = %w[rss atom].map do |format| link_to(format.upcase, url_params.merge(format: format, authentication_credentials: token), title: I18n.t(:"to_#{format}")) end links = ['perm'].map do |format| link_to(format.upcase, url_params, title: I18n.t(:"to_#{format}")) end (exports + feeds + links).compact.join(' | ') end |
#list_of_entities ⇒ Object
453 454 455 |
# File 'app/helpers/application_helper.rb', line 453 def list_of_entities ENTITIES + ['Task'] end |
#load_select_popups_for(related, *assets) ⇒ Object
66 67 68 69 70 71 |
# File 'app/helpers/application_helper.rb', line 66 def load_select_popups_for(, *assets) js = generate_js_for_popups(, *assets) content_for(:javascript_epilogue) do raw "$(function() { #{js} });" end end |
#one_submit_only(_form = '') ⇒ Object
224 225 226 |
# File 'app/helpers/application_helper.rb', line 224 def one_submit_only(_form = '') { onsubmit: "$('#'+this.id+' input[type=submit]').prop('disabled', true)".html_safe } end |
#options_menu_item(option, key, url = send("redraw_#{controller.controller_name}_path")) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'app/helpers/application_helper.rb', line 324 def (option, key, url = send("redraw_#{controller.controller_name}_path")) name = t("option_#{key}") "{ name: \"#{j name.titleize}\", on_select: function() {" + %{ if ($('##{option}').html() != '#{j name}') { $('##{option}').html('#{j name}'); $('#loading').show(); $.get('#{url}', {#{option}: '#{key}', query: $('#query').val()}, function () { $('#loading').hide(); }); } } + "}}" end |
#paginate(options = {}) ⇒ Object
Ajaxification FTW! e.g. collection = Opportunity.my(current_user).scope
options = { renderer: {...} , params: {...}
571 572 573 574 575 576 |
# File 'app/helpers/application_helper.rb', line 571 def paginate( = {}) collection = .delete(:collection) = { params: { action: 'index' } }.merge() if controller.action_name == 'filter' = { renderer: RemoteLinkPaginationHelper::LinkRenderer }.merge() will_paginate(collection, ) end |
#phone_field_with_pattern(form, method, options = {}) ⇒ Object
Render a phone field with an optional pattern for international format.
184 185 186 187 188 189 190 |
# File 'app/helpers/application_helper.rb', line 184 def phone_field_with_pattern(form, method, = {}) if Setting.enforce_international_phone_format [:pattern] ||= '\+[0-9]{1,3}\s?[0-9]{1,14}' [:placeholder] ||= '+1 123 456 7890' end form.phone_field(method, ) end |
#rating_select(name, options = {}) ⇒ Object
We need this because standard Rails [select] turns ★ into &#9733;
81 82 83 84 85 86 |
# File 'app/helpers/application_helper.rb', line 81 def (name, = {}) stars = Hash[(1..5).map { |star| [star, "★" * star] }].sort = %(<option value="0"#{[:selected].to_i.zero? ? ' selected="selected"' : ''}>#{t :select_none}</option>) += stars.map { |star| %(<option value="#{star.first}"#{[:selected] == star.first ? ' selected="selected"' : ''}>#{star.last}</option>) }.join select_tag name, .html_safe, end |
#redraw(option, value, url = send("redraw_#{controller.controller_name}_path")) ⇒ Object
Ajax helper to refresh current index page once the user selects an option.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'app/helpers/application_helper.rb', line 307 def redraw(option, value, url = send("redraw_#{controller.controller_name}_path")) if value.is_a?(Array) param = value.first value = value.last end %{ if ($('##{option}').html() != '#{j value}') { $('##{option}').html('#{j value}'); $('#loading').show(); $.post('#{url}', {#{option}: '#{j(param || value)}'}, function () { $('#loading').hide(); }); } } end |
#refresh_sidebar(action = nil) ⇒ Object
Reresh sidebar using the action view within the current controller.
255 256 257 |
# File 'app/helpers/application_helper.rb', line 255 def (action = nil) (controller.controller_name, action) end |
#refresh_sidebar_for(view, action = nil) ⇒ Object
Refresh sidebar using the action view within an arbitrary controller.
261 262 263 264 265 |
# File 'app/helpers/application_helper.rb', line 261 def (view, action = nil) text = "" text += "$('#sidebar').html('#{j render(partial: 'layouts/sidebar', locals: { view: view, action: action })}');" text.html_safe end |
#section(related, assets) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/application_helper.rb', line 51 def section(, assets) asset = assets.to_s.singularize create_id = "create_#{asset}" select_id = "select_#{asset}" create_url = controller.send(:"new_#{asset}_path") html = tag(:br) html << content_tag(:div, link_to(t(select_id), "#", id: select_id), class: "subtitle_tools") html << content_tag(:div, " | ".html_safe, class: "subtitle_tools") html << content_tag(:div, link_to_inline(create_id, create_url, related: dom_id(), text: t(create_id)), class: "subtitle_tools") html << content_tag(:div, t(assets), class: :subtitle, id: "create_#{asset}_title") html << content_tag(:div, "", class: :remote, id: create_id, style: "display:none;") end |
#section_title(id, hidden = true, text = nil, info_text = nil) ⇒ Object
Combines the ‘subtitle’ helper with the small info text on the same line.
499 500 501 502 503 504 505 |
# File 'app/helpers/application_helper.rb', line 499 def section_title(id, hidden = true, text = nil, info_text = nil) text = id.to_s.split("_").last.capitalize if text.nil? content_tag("div", class: "subtitle show_attributes") do content = subtitle_link(id, text, hidden) content << content_tag("small", info_text.to_s, class: "subtitle_inline_info", id: "#{id}_intro", style: hidden ? "" : "display:none;") end end |
#show_flash(options = { sticky: false }) ⇒ Object
Show existing flash or embed hidden paragraph ready for flash
27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/application_helper.rb', line 27 def show_flash( = { sticky: false }) %i[error warning info notice alert].each do |type| next unless flash[type] html = content_tag(:div, h(flash[type]), id: "flash") flash[type] = nil return html << content_tag(:script, "crm.flash('#{type}', #{[:sticky]})".html_safe, type: "text/javascript") end content_tag(:p, nil, id: "flash", style: "display:none;") end |
#shown_on_landing_page? ⇒ Boolean
Return true if:
- it's an Ajax request made from the asset landing page (i.e. create opportunity
from a contact landing page) OR
- we're actually showing asset landing page.
414 415 416 417 |
# File 'app/helpers/application_helper.rb', line 414 def shown_on_landing_page? !!((request.xhr? && request.referer =~ %r{/\w+/\d+}) || (!request.xhr? && request.fullpath =~ %r{/\w+/\d+})) end |
#size_from_style!(options) ⇒ Object
Convert STYLE symbols to ‘w x h’ format for Gravatar and Rails e.g. size_from_style(:size => :large) -> ‘75x75’ Allow options to contain :width and :height override keys
350 351 352 353 354 355 356 357 358 359 |
# File 'app/helpers/application_helper.rb', line 350 def size_from_style!() if [:width] && [:height] [:size] = %i[width height].map { |d| [d] }.join("x") .delete(:width) .delete(:height) elsif STYLES.keys.include?([:size]) [:size] = STYLES[[:size]].sub(/\#\z/, '') end end |
#spacer(width = 10) ⇒ Object
249 250 251 |
# File 'app/helpers/application_helper.rb', line 249 def spacer(width = 10) image_tag "1x1.gif", width: width, height: 1, alt: nil end |
#styles_for(*models) ⇒ Object
202 203 204 |
# File 'app/helpers/application_helper.rb', line 202 def styles_for(*models) render partial: "shared/inline_styles", locals: { models: models } end |
#subtitle(id, hidden = true, text = id.to_s.split("_").last.capitalize) ⇒ Object
46 47 48 |
# File 'app/helpers/application_helper.rb', line 46 def subtitle(id, hidden = true, text = id.to_s.split("_").last.capitalize) content_tag("div", subtitle_link(id, text, hidden), class: "subtitle") end |
#subtitle_link(id, text, hidden) ⇒ Object
38 39 40 41 42 43 |
# File 'app/helpers/application_helper.rb', line 38 def subtitle_link(id, text, hidden) link_to("<small>#{hidden ? '▷' : '▽'}</small> #{sanitize text}".html_safe, url_for(controller: :home, action: :toggle, id: id), remote: true, onclick: "crm.flip_subtitle(this)") end |
#tabless_layout? ⇒ Boolean
20 21 22 23 |
# File 'app/helpers/application_helper.rb', line 20 def tabless_layout? %w[sessions passwords registrations confirmations].include?(controller.controller_name) || ((controller.controller_name == "users") && %w[create new].include?(controller.action_name)) end |
#tabs(tabs = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/application_helper.rb', line 9 def tabs(tabs = nil) tabs ||= controller_path.match?(/admin/) ? FatFreeCRM::Tabs.admin : FatFreeCRM::Tabs.main if tabs @current_tab ||= tabs.first[:text] # Select first tab by default. tabs.each { |tab| tab[:active] = (@current_tab == tab[:text] || @current_tab == tab[:url][:controller]) } else raise FatFreeCRM::MissingSettings, "Tab settings are missing, please run <b>rake ffcrm:setup</b> command." end end |
#template_for_current_view ⇒ Object
Get template in current context with current view name
509 510 511 512 513 |
# File 'app/helpers/application_helper.rb', line 509 def template_for_current_view FatFreeCRM::ViewFactory.template_for_current_view(controller: controller.controller_name, action: show_or_index_action, name: current_view_name) end |
#timeago(time, options = {}) ⇒ Object
Generate the html for $.timeago function <span class=“timeago” datetime=“2008-07-17T09:24:17Z”>July 17, 2008</span>
545 546 547 548 549 550 551 |
# File 'app/helpers/application_helper.rb', line 545 def timeago(time, = {}) return unless time [:class] ||= "timeago" [:title] = time.getutc.iso8601 content_tag(:span, I18n.l(time), ) end |
#user_options ⇒ Object
445 446 447 |
# File 'app/helpers/application_helper.rb', line 445 def User.all.map { |u| [u.full_name, u.id] } end |
#view_buttons ⇒ Object
Generate buttons for available views given the current context
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'app/helpers/application_helper.rb', line 517 def views = FatFreeCRM::ViewFactory.views_for(controller: controller.controller_name, action: show_or_index_action) return nil unless views.size > 1 lis = ''.html_safe content_tag :ul, class: 'format-buttons' do views.collect do |view| classes = if (current_view_name == view.name) || (current_view_name.nil? && view.template.nil?) # nil indicates default template. "#{h view.name}-button active" else "#{h view.name}-button" end lis << content_tag(:li) do url = show_or_index_action == "index" ? send("redraw_#{controller.controller_name}_path") : send("#{controller.controller_name.singularize}_path") link_to('#', title: t(view.name, default: h(view.title)), "data-view": h(view.name), "data-url": h(url), "data-context": show_or_index_action, class: classes) do icon = view.icon || 'fa-bars' content_tag(:i, nil, class: "fa #{h icon}") end end end lis end end |
#visible ⇒ Object
219 220 221 |
# File 'app/helpers/application_helper.rb', line 219 def visible { style: "visibility:visible;" } end |
#web_presence_icons(person) ⇒ Object
Display web presence mini-icons for Contact or Lead.
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 303 |
# File 'app/helpers/application_helper.rb', line 269 def web_presence_icons(person) sites = [] icon_for_site = { facebook: "facebook", linkedin: "linkedin", twitter: "twitter", blog: "external-link", zoom: "video-camera", teams: "users", signal: "comment", instagram: "instagram", mastodon: "retweet", bluesky: "cloud" } %i[blog linkedin facebook twitter zoom teams signal instagram mastodon bluesky].each do |site| next unless person.respond_to?(site) url = person.send(site) next if url.blank? url = "http://" + url unless url.match?(%r{^https?://}) sites << if icon_for_site[site] link_to(content_tag(:i, "", { class: "fa fa-#{icon_for_site[site]}" }), h(url), "data-popup": true, title: t(:open_in_window, h(url))) else link_to(image_tag("#{site}.gif", size: "15x15"), h(url), "data-popup": true, title: t(:open_in_window, h(url))) end end if person.is_a?(Contact) sites << link_to(content_tag(:i, "", { class: "fa fa-address-card" }), contact_path(person, format: :vcf), title: "VCard") elsif person.is_a?(Lead) sites << link_to(content_tag(:i, "", { class: "fa fa-address-card" }), lead_path(person, format: :vcf), title: "VCard") end content_tag(:span, class: "web-presence-icons") { safe_join(sites, "\n") } end |