foreman/app/helpers/layout_helper.rb @ f92e7cc9
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)
|
|
c6e02bd3 | Joseph Magen | @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)
|
|
8527c9f1 | Amos Benari | 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
|
|
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 | ||
4f7a4d0b | David Davis | def addClass(options = {}, new_class = '')
|
|
bf4a13d3 | Walden Raines | options[:class] = "#{new_class} #{options[:class]}"
|
|
end
|
|||
05ab4c16 | Ohad Levy | def text_f(f, attr, options = {})
|
|
field(f, attr, options) do
|
|||
bf4a13d3 | Walden Raines | addClass options, "form-control"
|
|
aa0ccf33 | Ori Rabin | options[:focus_on_load] ||= attr.to_s == 'name'
|
|
05ab4c16 | Ohad Levy | f.text_field attr, options
|
|
end
|
|||
end
|
|||
4f7a4d0b | David Davis | def line_count(f, attr)
|
|
f8d94608 | Amos Benari | rows = f.object.try(attr).to_s.lines.count rescue 1
|
|
rows == 0 ? 1 : rows
|
|||
end
|
|||
05ab4c16 | Ohad Levy | def textarea_f(f, attr, options = {})
|
|
field(f, attr, options) do
|
|||
f8d94608 | Amos Benari | options[:rows] = line_count(f, attr) if options[:rows] == :auto
|
|
bf4a13d3 | Walden Raines | addClass options, "form-control"
|
|
8b8be6e4 | Tomer Brisker | f.text_area(attr, options)
|
|
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
def password_f(f, attr, options = {})
|
|||
19abc86f | Shlomi Zadok | password_field_tag(:fakepassword, nil, :style => 'display: none') +
|
|
05ab4c16 | Ohad Levy | field(f, attr, options) do
|
|
1614aac7 | Daniel Lobato | options[:autocomplete] ||= 'off'
|
|
0dc8fd72 | amirfefer | options[:placeholder] ||= password_placeholder(f.object, attr)
|
|
1614aac7 | Daniel Lobato | addClass options, 'form-control'
|
|
f.password_field(attr, options) +
|
|||
'<span class="glyphicon glyphicon-warning-sign input-addon"
|
|||
9b79e4f1 | Daniel Lobato | title="'.html_safe + _('Caps lock ON') +
|
|
'" style="display:none"></span>'.html_safe
|
|||
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
4f7a4d0b | David Davis | def checkbox_f(f, attr, options = {}, checked_value = "1", unchecked_value = "0")
|
|
f8d94608 | Amos Benari | text = options.delete(:help_text)
|
|
inline = options.delete(:help_inline)
|
|||
05ab4c16 | Ohad Levy | field(f, attr, options) do
|
|
09ce8a63 | Ori Rabin | help_inline = inline.blank? ? '' : content_tag(:span, inline, :class => "help-inline")
|
|
bf4a13d3 | Walden Raines | f.check_box(attr, options, checked_value, unchecked_value) + " #{text} " + help_inline.html_safe
|
|
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
4f7a4d0b | David Davis | def multiple_checkboxes(f, attr, klass, associations, options = {}, html_options = {})
|
|
14d225cc | Amos Benari | if associations.count > 5
|
|
1f1367d6 | Amos Benari | associated_obj = klass.send(ActiveModel::Naming.plural(associations.first))
|
|
selected_ids = associated_obj.select("#{associations.first.class.table_name}.id").map(&:id)
|
|||
multiple_selects(f, attr, associations, selected_ids, options, html_options)
|
|||
14d225cc | Amos Benari | else
|
|
field(f, attr, options) do
|
|||
410505f4 | Marek Hulan | authorized_edit_habtm klass, associations, options[:prefix], html_options
|
|
14d225cc | Amos Benari | end
|
|
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
671b45e9 | Joseph Mitchell Magen | # add hidden field for options[:disabled]
|
|
4f7a4d0b | David Davis | def multiple_selects(f, attr, associations, selected_ids, options = {}, html_options = {})
|
|
d31eea8c | Amos Benari | options.merge!(:size => "col-md-10")
|
|
887e2fd9 | Tomer Brisker | authorized = authorized_associations(associations).all
|
|
unauthorized = selected_ids.blank? ? [] : selected_ids - authorized.map(&:id)
|
|||
4a28771d | Stephen Benjamin | field(f, attr, options) do
|
|
671b45e9 | Joseph Mitchell Magen | attr_ids = (attr.to_s.singularize+"_ids").to_sym
|
|
1fa008a4 | Joseph Magen | hidden_fields = ''
|
|
html_options["data-useds"] ||= "[]"
|
|||
JSON.parse(html_options["data-useds"]).each do |disabled_value|
|
|||
1f1367d6 | Amos Benari | hidden_fields += f.hidden_field(attr_ids, :multiple => true, :value => disabled_value, :id=>'' )
|
|
671b45e9 | Joseph Mitchell Magen | end
|
|
887e2fd9 | Tomer Brisker | unauthorized.each do |unauthorized_value|
|
|
hidden_fields += f.hidden_field(attr_ids, :multiple => true, :value => unauthorized_value, :id=>'' )
|
|||
end
|
|||
hidden_fields + f.collection_select(attr_ids, authorized.sort_by { |a| a.to_s },
|
|||
4a28771d | Stephen Benjamin | :id, :to_label, options.merge(:selected => selected_ids),
|
|
1f1367d6 | Amos Benari | html_options.merge(:multiple => true))
|
|
671b45e9 | Joseph Mitchell Magen | end
|
|
end
|
|||
dd42df0a | Ohad Levy | def radio_button_f(f, attr, options = {})
|
|
text = options.delete(:text)
|
|||
value = options.delete(:value)
|
|||
bf4a13d3 | Walden Raines | label_tag('', :class=>"radio-inline") do
|
|
99527500 | Jimmi Dyson | f.radio_button(attr, value, options) + " #{text} "
|
|
dd42df0a | Ohad Levy | end
|
|
end
|
|||
05ab4c16 | Ohad Levy | def select_f(f, attr, array, id, method, select_options = {}, html_options = {})
|
|
b8fa2e29 | Ondrej Prazak | array = array.to_a.dup
|
|
04cb74c0 | Shimon Shtein | disable_button = select_options.delete(:disable_button)
|
|
include_blank = select_options.delete(:include_blank)
|
|||
disable_button_enabled = select_options.delete(:disable_button_enabled)
|
|||
user_set = !!select_options.delete(:user_set)
|
|||
if include_blank
|
|||
blank_value = include_blank.is_a?(TrueClass) ? nil : include_blank
|
|||
blank_option = OpenStruct.new({id => '', method => blank_value })
|
|||
baabd5ae | Shimon Shtein | # if the method is to_s, OpenStruct will respond with its own version.
|
|
# in this case, I need to undefine its own alias to to_s, and use the attribute
|
|||
# that was defined in the struct.
|
|||
blank_option.instance_eval('undef to_s') if method.to_s == 'to_s' || id.to_s == 'to_s'
|
|||
04cb74c0 | Shimon Shtein | array.insert(0, blank_option)
|
|
end
|
|||
select_options[:disabled] = '' if select_options[:disabled] == include_blank
|
|||
html_options.merge!(:disabled => true) if disable_button_enabled
|
|||
52667feb | Joseph Magen | html_options.merge!(:size => 'col-md-10') if html_options[:multiple]
|
|
05ab4c16 | Ohad Levy | field(f, attr, html_options) do
|
|
bf4a13d3 | Walden Raines | addClass html_options, "form-control"
|
|
04cb74c0 | Shimon Shtein | ||
collection_select = f.collection_select(attr, array, id, method, select_options, html_options)
|
|||
if disable_button
|
|||
button_part =
|
|||
content_tag :span, class: 'input-group-btn' do
|
|||
content_tag(:button, disable_button, :type => 'button', :href => '#',
|
|||
:name => 'is_overridden_btn',
|
|||
:onclick => "disableButtonToggle(this)",
|
|||
:class => 'btn btn-default btn-can-disable' + (disable_button_enabled ? ' active' : ''),
|
|||
:data => { :toggle => 'button', :explicit => user_set })
|
|||
end
|
|||
input_group collection_select, button_part
|
|||
else
|
|||
collection_select
|
|||
end
|
|||
end
|
|||
end
|
|||
def input_group(*controls)
|
|||
content_tag :div, class: 'input-group' do
|
|||
controls.map { |control_html| concat(control_html) }
|
|||
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
ad998ce7 | Shlomi Zadok | def time_zone_select_f(f, attr, default_timezone, select_options = {}, html_options = {})
|
|
field(f, attr, html_options) do
|
|||
addClass html_options, "form-control"
|
|||
f.time_zone_select(attr, [default_timezone], select_options, html_options)
|
|||
end
|
|||
end
|
|||
05ab4c16 | Ohad Levy | def selectable_f(f, attr, array, select_options = {}, html_options = {})
|
|
52667feb | Joseph Magen | html_options.merge!(:size => 'col-md-10') if html_options[:multiple]
|
|
05ab4c16 | Ohad Levy | field(f, attr, html_options) do
|
|
bf4a13d3 | Walden Raines | addClass html_options, "form-control"
|
|
05ab4c16 | Ohad Levy | f.select attr, array, select_options, html_options
|
|
end
|
|||
end
|
|||
0c87d936 | Ohad Levy | def file_field_f(f, attr, options = {})
|
|
field(f, attr, options) do
|
|||
f.file_field attr, options
|
|||
end
|
|||
end
|
|||
acfbc458 | Marek Hulan | def autocomplete_f(f, attr, options = {})
|
|
field(f, attr, options) do
|
|||
f536685b | Walden Raines | path = options.delete(:path) || send("#{f.object.class.pluralize.underscore}_path") if options[:full_path].nil?
|
|
acfbc458 | Marek Hulan | auto_complete_search(attr,
|
|
f.object.send(attr).try(:squeeze, " "),
|
|||
options.merge(
|
|||
:placeholder => _("Filter") + ' ...',
|
|||
:path => path,
|
|||
f536685b | Walden Raines | :name => "#{f.object_name}[#{attr}]"
|
|
8527c9f1 | Amos Benari | )
|
|
acfbc458 | Marek Hulan | ).html_safe
|
|
end
|
|||
end
|
|||
05ab4c16 | Ohad Levy | def field(f, attr, options = {})
|
|
09ce8a63 | Ori Rabin | table_field = options.delete(:table_field)
|
|
error = f.object.errors[attr] if f && f.object.respond_to?(:errors)
|
|||
89b9ecb0 | Amos Benari | help_inline = help_inline(options.delete(:help_inline), error)
|
|
09ce8a63 | Ori Rabin | size_class = options.delete(:size) || "col-md-4"
|
|
f92e7cc9 | Walden Raines | wrapper_class = options.delete(:wrapper_class) || "form-group"
|
|
label = options[:no_label] ? "" : add_label(options, f, attr)
|
|||
09ce8a63 | Ori Rabin | ||
if table_field
|
|||
b3ac878a | Tomer Brisker | add_help_to_label(size_class, label, help_inline) do
|
|
09ce8a63 | Ori Rabin | yield
|
|
d31eea8c | Amos Benari | end.html_safe
|
|
09ce8a63 | Ori Rabin | else
|
|
help_block = content_tag(:span, options.delete(:help_block), :class => "help-block")
|
|||
content_tag(:div, :class => "clearfix") do
|
|||
f92e7cc9 | Walden Raines | content_tag :div, :class => "#{wrapper_class} #{error.empty? ? "" : 'has-error'}",
|
|
09ce8a63 | Ori Rabin | :id => options.delete(:control_group_id) do
|
|
b3ac878a | Tomer Brisker | input = if options[:fullscreen]
|
|
content_tag(:div, yield.html_safe + fullscreen_input, :class => "input-group")
|
|||
else
|
|||
yield.html_safe
|
|||
end
|
|||
add_help_to_label(size_class, label, help_inline) do
|
|||
input + help_block.html_safe
|
|||
09ce8a63 | Ori Rabin | end
|
|
end.html_safe
|
|||
end
|
|||
end
|
|||
end
|
|||
b3ac878a | Tomer Brisker | def add_help_to_label(size_class, label, help_inline)
|
|
09ce8a63 | Ori Rabin | label.html_safe +
|
|
content_tag(:div, :class => size_class) do
|
|||
yield
|
|||
b3ac878a | Tomer Brisker | end.html_safe + help_inline.html_safe
|
|
09ce8a63 | Ori Rabin | end
|
|
# The target should have class="collapse [out|in]" out means collapsed on load and in means expanded.
|
|||
# Target must also have a unique id.
|
|||
def collapsing_legend(title, target, collapsed = '')
|
|||
content_tag(:legend, :class => "expander #{collapsed}", :data => {:toggle => 'collapse', :target => target}) do
|
|||
content_tag(:span, '', :class => 'caret') + title
|
|||
bf4a13d3 | Walden Raines | end
|
|
05ab4c16 | Ohad Levy | end
|
|
09ce8a63 | Ori Rabin | def check_required options, f, attr
|
|
required = options.delete(:required) # we don't want to use html5 required attr so we delete the option
|
|||
return ' *' if required.nil? ? is_required?(f, attr) : required
|
|||
end
|
|||
def add_label options, f, attr
|
|||
label_size = options.delete(:label_size) || "col-md-2"
|
|||
required_mark = check_required(options, f, attr)
|
|||
label = options[:label] == :none ? '' : options.delete(:label)
|
|||
label ||= ((clazz = f.object.class).respond_to?(:gettext_translation_for_attribute_name) &&
|
|||
s_(clazz.gettext_translation_for_attribute_name attr)) if f
|
|||
label = label.present? ? label_tag(attr, "#{label}#{required_mark}".html_safe, :class => label_size + " control-label") : ''
|
|||
label
|
|||
end
|
|||
2af7c64a | Joseph Magen | def is_required?(f, attr)
|
|
return false unless f && f.object.class.respond_to?(:validators_on)
|
|||
3b87444a | Marek Hulan | f.object.class.validators_on(attr).any? do |validator|
|
|
options = validator.options.keys.map(&:to_s)
|
|||
validator.is_a?(ActiveModel::Validations::PresenceValidator) && !options.include?('if') && !options.include?('unless')
|
|||
end
|
|||
2af7c64a | Joseph Magen | end
|
|
89b9ecb0 | Amos Benari | def help_inline(inline, error)
|
|
help_inline = error.empty? ? inline : error.to_sentence.html_safe
|
|||
case help_inline
|
|||
when blank?
|
|||
""
|
|||
when :indicator
|
|||
bf4a13d3 | Walden Raines | content_tag(:span, image_tag('spinner.gif', :class => 'hide'), :class => "help-block help-inline")
|
|
89b9ecb0 | Amos Benari | else
|
|
bf4a13d3 | Walden Raines | content_tag(:span, help_inline, :class => "help-block help-inline")
|
|
89b9ecb0 | Amos Benari | end
|
|
end
|
|||
5f029ed6 | Daniel Lobato | def form_to_submit_id(f)
|
|
bfee97b6 | Lukas Zapletal | object = f.object.respond_to?(:to_model) ? f.object.to_model : f.object
|
|
b2b7a13b | Daniel Lobato | key = if object.present?
|
|
object.persisted? ? :update : :create
|
|||
else
|
|||
:submit
|
|||
end
|
|||
bfee97b6 | Lukas Zapletal | model = if object.class.respond_to?(:humanize_class_name)
|
|
object.class.humanize_class_name.downcase
|
|||
elsif object.class.respond_to?(:model_name)
|
|||
object.class.model_name.human.downcase
|
|||
else
|
|||
f.object_name.to_s
|
|||
end.gsub(/\W+/, '_')
|
|||
"aid_#{key}_#{model}"
|
|||
end
|
|||
5f029ed6 | Daniel Lobato | def submit_or_cancel(f, overwrite = false, args = { })
|
|
ef4b97d1 | Joseph Mitchell Magen | args[:cancel_path] ||= send("#{controller_name}_path")
|
|
8527c9f1 | Amos Benari | content_tag(:div, :class => "clearfix") do
|
|
content_tag(:div, :class => "form-actions") do
|
|||
text = overwrite ? _("Overwrite") : _("Submit")
|
|||
77c68e43 | Marek Hulan | options = {}
|
|
options[:class] = "btn btn-#{overwrite ? 'danger' : 'primary'} remove_form_templates"
|
|||
8527c9f1 | Amos Benari | options.merge! :'data-id' => form_to_submit_id(f) unless options.has_key?(:'data-id')
|
|
link_to(_("Cancel"), args[:cancel_path], :class => "btn btn-default") + " " +
|
|||
f.submit(text, options)
|
|||
end
|
|||
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
5f029ed6 | Daniel Lobato | def base_errors_for(obj)
|
|
017e1049 | Ohad Levy | unless obj.errors[:base].blank?
|
|
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 = {})
|
|
b3ac878a | Tomer Brisker | options[:icon] ||= 'info-sign'
|
|
content_tag(:a, icon_text(options[:icon], title), { :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
|
|
ede5687c | Ohad Levy | def will_paginate(collection = nil, options = {})
|
|
bf4a13d3 | Walden Raines | options.merge!(:class=>"col-md-7")
|
|
017e1049 | Ohad Levy | options[:renderer] ||= "WillPaginate::ActionView::BootstrapLinkRenderer"
|
|
options[:inner_window] ||= 2
|
|||
options[:outer_window] ||= 0
|
|||
bf4a13d3 | Walden Raines | options[:previous_label] ||= _('«')
|
|
options[:next_label] ||= _('»')
|
|||
017e1049 | Ohad Levy | super collection, options
|
|
end
|
|||
def page_entries_info(collection, options = {})
|
|||
1bf7cc35 | Amos Benari | html = if collection.total_entries == 0
|
|
_("No entries found")
|
|||
else
|
|||
if collection.total_pages < 2
|
|||
n_("Displaying <b>%{count}</b> entry", "Displaying <b>all %{count}</b> entries", collection.total_entries) % {:count => collection.total_entries}
|
|||
else
|
|||
_("Displaying entries <b>%{from} - %{to}</b> of <b>%{count}</b> in total") %
|
|||
{ :from => collection.offset + 1, :to => collection.offset + collection.length, :count => collection.total_entries }
|
|||
end
|
|||
end.html_safe
|
|||
017e1049 | Ohad Levy | html += options[:more].html_safe if options[:more]
|
|
a783d2c8 | ripcurld00d | content_tag(:div, :class => "col-md-5 hidden-xs") do
|
|
content_tag(:div, html, :class => "pull-left pull-bottom darkgray pagination")
|
|||
end
|
|||
end
|
|||
def will_paginate_with_info(collection = nil, options = {})
|
|||
content_tag(:div, :id => "pagination", :class => "row") do
|
|||
page_entries_info(collection, options) +
|
|||
will_paginate(collection, options)
|
|||
bf4a13d3 | Walden Raines | end
|
|
82e47ae0 | Amos Benari | end
|
|
def form_for(record_or_name_or_array, *args, &proc)
|
|||
if args.last.is_a?(Hash)
|
|||
cc68313b | Amos Benari | args.last[:html] = {:class=>"form-horizontal well"}.merge(args.last[:html]||{})
|
|
82e47ae0 | Amos Benari | else
|
|
cc68313b | Amos Benari | args << {:html=>{:class=>"form-horizontal well"}}
|
|
82e47ae0 | Amos Benari | end
|
|
super record_or_name_or_array, *args, &proc
|
|||
end
|
|||
5f029ed6 | Daniel Lobato | def icons(i)
|
|
bf4a13d3 | Walden Raines | content_tag :i, :class=>"glyphicon glyphicon-#{i}" do
|
|
82e47ae0 | Amos Benari | yield
|
|
end
|
|||
017e1049 | Ohad Levy | end
|
|
4f7a4d0b | David Davis | def icon_text(i, text = "", opts = {})
|
|
bc9558f7 | Shlomi Zadok | (content_tag(:i,"", :class=>"glyphicon glyphicon-#{i} #{opts[:class]}", :title => opts[:title]) + " " + text).html_safe
|
|
dec6f148 | Amos Benari | end
|
|
5f029ed6 | Daniel Lobato | def alert(opts = {})
|
|
16b9f09b | Ohad Levy | opts[:close] = true if opts[:close].nil?
|
|
bfbf7ed8 | Lukas Zapletal | opts[:header] ||= _("Warning!")
|
|
16b9f09b | Ohad Levy | opts[:text] ||= _("Alert")
|
|
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]
|
|||
result += alert_header(opts[:header])
|
|||
de9e7ada | Marek Hulan | result += content_tag(:span, opts[:text].html_safe, :class => 'text')
|
|
f262f77a | Ohad Levy | result
|
|
end
|
|||
end
|
|||
5f029ed6 | Daniel Lobato | def alert_header(text)
|
|
8527c9f1 | Amos Benari | "<h4 class='alert-heading'>#{text}</h4>".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
|
|||
options = shorten && (text.size < length) ? {} : { :'data-original-title' => tooltip_text, :rel => 'twipsy' }
|
|||
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
|
|
6e916e52 | Shlomi Zadok | def modal_close(data_dismiss = 'modal', text = _('Close'))
|
|
button_tag(text, :class => 'btn btn-default', :data => { :dismiss => data_dismiss })
|
|||
end
|
|||
0f383a25 | Ohad Levy | ||
def number_f(f, attr, options = {})
|
|||
field(f, attr, options) do
|
|||
addClass options, "form-control"
|
|||
f.number_field attr, options
|
|||
end
|
|||
end
|
|||
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
|
|
8b8be6e4 | Tomer Brisker | icon_text('resize-full')
|
|
end
|
|||
end
|
|||
b3ac878a | Tomer Brisker | def fullscreen_input(element = "$(this).parent().prev()")
|
|
content_tag(:span, fullscreen_button(element), :class => 'input-group-btn')
|
|||
end
|
|||
887e2fd9 | Tomer Brisker | private
|
|
def authorized_associations(associations)
|
|||
cdb70710 | Marek Hulan | if associations.included_modules.include?(Authorizable)
|
|
if associations.respond_to?(:klass)
|
|||
associations.authorized(authorized_associations_permission_name(associations.klass), associations.klass)
|
|||
else
|
|||
associations.authorized(authorized_associations_permission_name(associations), associations)
|
|||
end
|
|||
else
|
|||
associations
|
|||
end
|
|||
end
|
|||
def authorized_associations_permission_name(klass)
|
|||
permission = "view_#{klass.to_s.underscore.pluralize}"
|
|||
unless Permission.where(:name => permission).present?
|
|||
raise Foreman::Exception.new(N_('unknown permission %s'), permission)
|
|||
end
|
|||
permission
|
|||
887e2fd9 | Tomer Brisker | end
|
|
8d7ea035 | alongoldboim | ||
def table_css_classes(classes = '')
|
|||
"table table-bordered table-striped table-condensed " + classes
|
|||
end
|
|||
55ed30c7 | Ohad Levy | end
|