foreman/app/helpers/layout_helper.rb @ f8d94608
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)
|
|
82e47ae0 | Amos Benari | @page_header = page_header || @content_for_title || page_title.to_s
|
|
55ed30c7 | Ohad Levy | end
|
|
05ab4c16 | Ohad Levy | def title_actions *elements
|
|
017e1049 | Ohad Levy | content_for(:title_actions) { elements.join(" ").html_safe }
|
|
05ab4c16 | Ohad Levy | end
|
|
e4b5713e | Amos Benari | def button_group *elements
|
|
content_tag(:div,:class=>"btn-group") { elements.join(" ").html_safe }
|
|||
end
|
|||
05ab4c16 | Ohad Levy | 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)
|
|
content_for(:head) { stylesheet_link_tag(*args) }
|
|||
end
|
|||
def javascript(*args)
|
|||
content_for(:head) { javascript_include_tag(*args) }
|
|||
end
|
|||
05ab4c16 | Ohad Levy | ||
def text_f(f, attr, options = {})
|
|||
field(f, attr, options) do
|
|||
f.text_field attr, options
|
|||
end
|
|||
end
|
|||
f8d94608 | Amos Benari | def line_count (f, attr)
|
|
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
|
|
05ab4c16 | Ohad Levy | f.text_area attr, options
|
|
end
|
|||
end
|
|||
def password_f(f, attr, options = {})
|
|||
field(f, attr, options) do
|
|||
f.password_field attr, options
|
|||
end
|
|||
end
|
|||
def checkbox_f(f, attr, options = {})
|
|||
f8d94608 | Amos Benari | text = options.delete(:help_text)
|
|
inline = options.delete(:help_inline)
|
|||
05ab4c16 | Ohad Levy | field(f, attr, options) do
|
|
dd42df0a | Ohad Levy | label_tag('', :class=>'checkbox') do
|
|
f8d94608 | Amos Benari | help_inline = inline.blank? ? '' : content_tag(:span, inline, :class => "help-inline")
|
|
f.check_box(attr, options) + " #{text} " + help_inline.html_safe
|
|||
dd42df0a | Ohad Levy | end
|
|
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
def multiple_checkboxes(f, attr, obj, klass, options = {})
|
|||
field(f, attr, options) do
|
|||
1b3cbe60 | Amos Benari | authorized_edit_habtm obj, klass, options[:prefix]
|
|
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
dd42df0a | Ohad Levy | def radio_button_f(f, attr, options = {})
|
|
text = options.delete(:text)
|
|||
value = options.delete(:value)
|
|||
label_tag('', :class=>"radio inline") do
|
|||
f.radio_button(attr, value, options) + " #{text} "
|
|||
end
|
|||
end
|
|||
05ab4c16 | Ohad Levy | def select_f(f, attr, array, id, method, select_options = {}, html_options = {})
|
|
field(f, attr, html_options) do
|
|||
f.collection_select attr, array, id, method, select_options, html_options
|
|||
end
|
|||
end
|
|||
def selectable_f(f, attr, array, select_options = {}, html_options = {})
|
|||
field(f, attr, html_options) do
|
|||
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
|
|||
05ab4c16 | Ohad Levy | def field(f, attr, options = {})
|
|
dd42df0a | Ohad Levy | error = f.object.errors[attr] if f.object.respond_to?(:errors)
|
|
0345ef19 | Amos Benari | inline = options.delete(:help_inline)
|
|
inline = error.to_sentence.html_safe unless error.empty?
|
|||
dd42df0a | Ohad Levy | help_inline = inline.blank? ? '' : content_tag(:span, inline, :class => "help-inline")
|
|
017e1049 | Ohad Levy | help_block = content_tag(:span, options.delete(:help_block), :class => "help-block")
|
|
82e47ae0 | Amos Benari | content_tag :div, :class => "control-group #{error.empty? ? "" : 'error'}" do
|
|
dd42df0a | Ohad Levy | label_tag(attr, options.delete(:label), :class=>"control-label").html_safe +
|
|
82e47ae0 | Amos Benari | content_tag(:div, :class => "controls") do
|
|
017e1049 | Ohad Levy | yield.html_safe + help_inline.html_safe + help_block.html_safe
|
|
end.html_safe
|
|||
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
dd42df0a | Ohad Levy | def submit_or_cancel f, overwrite = false, args = { }
|
|
args[:cancel_path] ||= eval "#{controller_name}_path"
|
|||
cc68313b | Amos Benari | content_tag(:div, :class => "form-actions") do
|
|
30ae12bf | Ohad Levy | text = overwrite ? "Overwrite" : "Submit"
|
|
dd42df0a | Ohad Levy | options = overwrite ? {:class => "btn btn-danger"} : {:class => "btn btn-primary"}
|
|
link_to("Cancel", args[:cancel_path], :class => "btn") + " " +
|
|||
30ae12bf | Ohad Levy | f.submit(text, options)
|
|
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
def base_errors_for obj
|
|||
017e1049 | Ohad Levy | unless obj.errors[:base].blank?
|
|
82e47ae0 | Amos Benari | content_tag(:div, :class => "alert alert-message alert-block alert-error base in fade") do
|
|
dd42df0a | Ohad Levy | "<a class='close' href='#' data-dismiss='alert'>×</a><h4>Unable to save</h4> ".html_safe + obj.errors[:base].map {|e| "<li>#{e}</li>"}.to_s.html_safe
|
|
05ab4c16 | Ohad Levy | end
|
|
end
|
|||
end
|
|||
2b54d6ef | Ohad Levy | def popover title, msg, options = {}
|
|
995b1748 | Amos Benari | link_to_function icon_text("info-sign"), { :rel => "popover", "data-content" => msg, "data-original-title" => title}.merge(options)
|
|
2b54d6ef | Ohad Levy | end
|
|
017e1049 | Ohad Levy | def will_paginate(collection = nil, options = {})
|
|
82e47ae0 | Amos Benari | options.merge!(:class=>"span7 pagination")
|
|
017e1049 | Ohad Levy | options[:renderer] ||= "WillPaginate::ActionView::BootstrapLinkRenderer"
|
|
options[:inner_window] ||= 2
|
|||
options[:outer_window] ||= 0
|
|||
super collection, options
|
|||
end
|
|||
def page_entries_info(collection, options = {})
|
|||
html = super(collection, options)
|
|||
html += options[:more].html_safe if options[:more]
|
|||
content_tag(
|
|||
:div,content_tag(
|
|||
:ul, content_tag(
|
|||
:li, link_to(html, "#")
|
|||
), :style=>"float: left;"
|
|||
82e47ae0 | Amos Benari | ), :class => "span4 pagination")
|
|
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
|
|||
def icons i
|
|||
content_tag :i, :class=>"icon-#{i}" do
|
|||
yield
|
|||
end
|
|||
017e1049 | Ohad Levy | end
|
|
eb56c27a | Ohad Levy | def icon_text(i, text="", opts = {})
|
|
(content_tag(:i,"", :class=>"icon-#{i} #{opts[:class]}") + " " + text).html_safe
|
|||
dec6f148 | Amos Benari | end
|
|
f262f77a | Ohad Levy | def alert opts = {}
|
|
opts[:close] ||= true
|
|||
opts[:header] ||= "Warning!"
|
|||
opts[:text] ||= "Alert"
|
|||
content_tag :div, :class => "alert #{opts[:class]}" do
|
|||
result = "".html_safe
|
|||
result += alert_close if opts[:close]
|
|||
result += alert_header(opts[:header])
|
|||
result += opts[:text].html_safe
|
|||
result
|
|||
end
|
|||
end
|
|||
def alert_header text
|
|||
"<h4 class='alert-heading'>#{text}</h4>".html_safe
|
|||
end
|
|||
def alert_close
|
|||
"<a class='close' href='#' data-dismiss='alert'>×</a>".html_safe
|
|||
end
|
|||
55ed30c7 | Ohad Levy | end
|