foreman/app/helpers/layout_helper.rb @ 9d43fc71
55ed30c7 | Ohad Levy | module LayoutHelper
|
|
d17ecbc9 | Amos Benari | def title(page_title, page_header = nil)
|
|
017e1049 | Ohad Levy | content_for(:title, page_title.to_s)
|
|
f4459c11 | David Davis | @page_header ||= page_header || @content_for_title || page_title.to_s
|
|
55ed30c7 | Ohad Levy | end
|
|
5f029ed6 | Daniel Lobato | def title_actions(*elements)
|
|
017e1049 | Ohad Levy | content_for(:title_actions) { elements.join(" ").html_safe }
|
|
05ab4c16 | Ohad Levy | end
|
|
5f029ed6 | Daniel Lobato | def button_group(*elements)
|
|
9d43fc71 | Michael Moll | content_tag(:div, :class => "btn-group") { elements.join(" ").html_safe }
|
|
e4b5713e | Amos Benari | end
|
|
5f029ed6 | Daniel Lobato | def search_bar(*elements)
|
|
017e1049 | Ohad Levy | content_for(:search_bar) { elements.join(" ").html_safe }
|
|
05ab4c16 | Ohad Levy | end
|
|
833e2aef | Amir Fefer | def mount_breadcrumbs(options = {}, &block)
|
|
b9aa6bda | Marek Hulan | options = BreadcrumbsOptions.new(@page_header, controller, action_name, block_given? ? yield : options)
|
|
9738aa6e | Amir Fefer | ||
833e2aef | Amir Fefer | mount_react_component("BreadcrumbBar", "#breadcrumb", options.bar_props.to_json)
|
|
9738aa6e | Amir Fefer | end
|
|
833e2aef | Amir Fefer | def breadcrumbs(options = {}, &block)
|
|
9738aa6e | Amir Fefer | content_for(:breadcrumbs) do
|
|
833e2aef | Amir Fefer | mount_breadcrumbs(options, &block)
|
|
9738aa6e | Amir Fefer | end
|
|
end
|
|||
55ed30c7 | Ohad Levy | def stylesheet(*args)
|
|
c873b3cd | Joseph Magen | content_for(:stylesheets) { stylesheet_link_tag(*args.push("data-turbolinks-track" => true)) }
|
|
55ed30c7 | Ohad Levy | end
|
|
def javascript(*args)
|
|||
c873b3cd | Joseph Magen | content_for(:javascripts) { javascript_include_tag(*args.push("data-turbolinks-track" => true)) }
|
|
55ed30c7 | Ohad Levy | end
|
|
05ab4c16 | Ohad Levy | ||
09ce8a63 | Ori Rabin | # The target should have class="collapse [out|in]" out means collapsed on load and in means expanded.
|
|
# Target must also have a unique id.
|
|||
aa50ab15 | alongoldboim | def collapsing_header(title, target, collapsed = '')
|
|
content_tag(:h2, :class => "expander #{collapsed}", :data => {:toggle => 'collapse', :target => target}) do
|
|||
09ce8a63 | Ori Rabin | content_tag(:span, '', :class => 'caret') + title
|
|
bf4a13d3 | Walden Raines | end
|
|
05ab4c16 | Ohad Levy | end
|
|
5f029ed6 | Daniel Lobato | def base_errors_for(obj)
|
|
85021506 | Michael Moll | if obj.errors[:base].present?
|
|
ede5687c | Ohad Levy | alert :header => _("Unable to save"),
|
|
:class => 'alert-danger base in fade',
|
|||
:text => obj.errors[:base].map { |e| '<li>'.html_safe + e + '</li>'.html_safe }.join.html_safe
|
|||
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
5f029ed6 | Daniel Lobato | def popover(title, msg, options = {})
|
|
ae23d007 | Ori Rabin | options[:icon] ||= 'info'
|
|
options[:kind] ||= 'pficon'
|
|||
content_tag(:a, icon_text(options[:icon], title, :kind => options[:kind]), { :rel => "popover",
|
|||
:data => { :content => msg,
|
|||
:"original-title" => title,
|
|||
:trigger => "focus",
|
|||
:container => 'body',
|
|||
:html => true },
|
|||
:role => 'button',
|
|||
:tabindex => '-1' }.deep_merge(options))
|
|||
2b54d6ef | Ohad Levy | end
|
|
4f7a4d0b | David Davis | def icon_text(i, text = "", opts = {})
|
|
f4459c11 | David Davis | opts[:kind] ||= "glyphicon"
|
|
9d43fc71 | Michael Moll | (content_tag(:span, "", :class => "#{opts[:kind] + ' ' + opts[:kind]}-#{i} #{opts[:class]}", :title => opts[:title]) + " " + text).html_safe
|
|
dec6f148 | Amos Benari | end
|
|
5f029ed6 | Daniel Lobato | def alert(opts = {})
|
|
9d43fc71 | Michael Moll | opts[:close] = true if opts[:close].nil?
|
|
bfbf7ed8 | Lukas Zapletal | opts[:header] ||= _("Warning!")
|
|
16b9f09b | Ohad Levy | opts[:text] ||= _("Alert")
|
|
9d43fc71 | Michael Moll | html_class = "alert #{opts[:class]} "
|
|
html_class += 'alert-dismissable' if opts[:close]
|
|||
de9e7ada | Marek Hulan | content_tag :div, :class => html_class, :id => opts[:id] do
|
|
f262f77a | Ohad Levy | result = "".html_safe
|
|
result += alert_close if opts[:close]
|
|||
aa50ab15 | alongoldboim | result += alert_header(opts[:header], opts[:class])
|
|
5a573456 | Tomer Brisker | result += content_tag(:span, opts[:text], :class => 'text')
|
|
aa50ab15 | alongoldboim | result += alert_actions(opts[:actions]) if opts[:actions].present?
|
|
f262f77a | Ohad Levy | result
|
|
end
|
|||
end
|
|||
aa50ab15 | alongoldboim | def alert_header(text, html_class = nil)
|
|
case html_class
|
|||
when /alert-success/
|
|||
3cd8c84b | Michael Moll | icon = icon_text("ok", "", :kind => "pficon")
|
|
aa50ab15 | alongoldboim | text ||= _("Notice")
|
|
when /alert-warning/
|
|||
3cd8c84b | Michael Moll | icon = icon_text("warning-triangle-o", "", :kind => "pficon")
|
|
aa50ab15 | alongoldboim | text ||= _("Warning")
|
|
when /alert-info/
|
|||
icon = icon_text("info", "", :kind => "pficon")
|
|||
text ||= _("Notice")
|
|||
when /alert-danger/
|
|||
icon = icon_text("error-circle-o", "", :kind => "pficon")
|
|||
text ||= _("Error")
|
|||
end
|
|||
f4459c11 | David Davis | header = icon.to_s
|
|
0300fadf | Daniel Lobato | header += content_tag(:strong, text + ' ') if text.present?
|
|
aa50ab15 | alongoldboim | header.html_safe
|
|
f262f77a | Ohad Levy | end
|
|
6e916e52 | Shlomi Zadok | def alert_close(data_dismiss = 'alert')
|
|
"<button type='button' class='close' data-dismiss='#{data_dismiss}' aria-hidden='true'>×</button>".html_safe
|
|||
f262f77a | Ohad Levy | end
|
|
60fe43b2 | Ondrej Prazak | def trunc_with_tooltip(text, length = 32, tooltip_text = "", shorten = true)
|
|
text = text.to_s.empty? ? tooltip_text.to_s : text.to_s
|
|||
tooltip_text = tooltip_text.to_s.empty? ? text : tooltip_text.to_s
|
|||
da9865b8 | Michael Moll | options = (shorten && (text.size < length)) ? {} : { :'data-original-title' => tooltip_text, :rel => 'twipsy' }
|
|
60fe43b2 | Ondrej Prazak | if shorten
|
|
content_tag(:span, truncate(text, :length => length), options).html_safe
|
|||
else
|
|||
content_tag(:span, text, options).html_safe
|
|||
end
|
|||
adb487e0 | Ori Rabin | end
|
|
aa50ab15 | alongoldboim | def alert_actions(actions)
|
|
content_tag :div, :class => 'alert-actions' do
|
|||
'<hr>'.html_safe + actions
|
|||
end
|
|||
end
|
|||
2ac8d7ba | Tomer Brisker | def modal_close(text = _('Close'))
|
|
button_tag(text, :class => 'btn btn-default', :data => { :dismiss => 'modal' })
|
|||
6e916e52 | Shlomi Zadok | end
|
|
0f383a25 | Ohad Levy | ||
42117380 | Tomer Brisker | def last_days(days)
|
|
content_tag(:h6, n_("last %s day", "last %s days", days) % days, :class => 'ca')
|
|||
end
|
|||
887e2fd9 | Tomer Brisker | ||
8b8be6e4 | Tomer Brisker | def fullscreen_button(element = "$(this).prev()")
|
|
b3ac878a | Tomer Brisker | button_tag(:type => 'button', :class => 'btn btn-default btn-md btn-fullscreen', :onclick => "set_fullscreen(#{element})", :title => _("Full screen")) do
|
|
ae23d007 | Ori Rabin | icon_text('expand', '', :kind => 'fa')
|
|
8b8be6e4 | Tomer Brisker | end
|
|
end
|
|||
e4ae4a69 | Ori Rabin | def fullscreen_input(element = "$(this).closest('.input-group').find('input,textarea')")
|
|
b3ac878a | Tomer Brisker | content_tag(:span, fullscreen_button(element), :class => 'input-group-btn')
|
|
end
|
|||
6bbf5085 | Ori Rabin | def new_child_fields_template(form_builder, association, options = { })
|
|
f4459c11 | David Davis | unless options[:object].present?
|
|
6bbf5085 | Ori Rabin | association_object = form_builder.object.class.reflect_on_association(association)
|
|
options[:object] = association_object.klass.new(association_object.foreign_key => form_builder.object.id)
|
|||
end
|
|||
options[:partial] ||= association.to_s.singularize
|
|||
options[:form_builder_local] ||= :f
|
|||
options[:form_builder_attrs] ||= {}
|
|||
content_tag(:div, :class => "#{association}_fields_template form_template", :style => "display: none;") do
|
|||
form_builder.fields_for(association, options[:object], :child_index => "new_#{association}") do |f|
|
|||
2ac8d7ba | Tomer Brisker | render(:partial => options[:partial], :layout => options[:layout],
|
|
6bbf5085 | Ori Rabin | :locals => { options[:form_builder_local] => f }.merge(options[:form_builder_attrs]))
|
|
end
|
|||
end
|
|||
end
|
|||
5a8f4579 | Amir Fefer | def render_if_partial_exists(path, f)
|
|
render path, :f => f if lookup_context.exists?(path, [], true)
|
|||
end
|
|||
13a7bf0d | amirfefer | def per_page(collection)
|
|
53b80ce3 | Amir Fefer | per_page = params[:per_page] ? params[:per_page].to_i : Setting[:entries_per_page]
|
|
[per_page, collection.total_entries].min
|
|||
13a7bf0d | amirfefer | end
|
|
887e2fd9 | Tomer Brisker | private
|
|
8d7ea035 | alongoldboim | def table_css_classes(classes = '')
|
|
f7a762ec | Ohad Levy | "table table-bordered table-striped table-hover " + classes
|
|
8d7ea035 | alongoldboim | end
|
|
55ed30c7 | Ohad Levy | end
|