mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-22 08:46:11 +01:00
58 lines
No EOL
2.1 KiB
Text
58 lines
No EOL
2.1 KiB
Text
# Please insert these into your ApplicationHelper
|
|
|
|
# Replacement for Rails' default submit_tag helper
|
|
# using HTML button element rather than HTML input element
|
|
def submit_tag(text, options = {})
|
|
content_tag :button, text, options.merge(:type => :submit)
|
|
end
|
|
|
|
# Replacement for Rails' default button_to helper
|
|
# using HTML button element rather than HTML input element
|
|
def button_to(name, options = {}, html_options = {})
|
|
html_options = html_options.stringify_keys
|
|
convert_boolean_attributes!(html_options, %w( disabled ))
|
|
|
|
method_tag = ''
|
|
if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s)
|
|
method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
|
|
end
|
|
|
|
form_method = method.to_s == 'get' ? 'get' : 'post'
|
|
|
|
request_token_tag = ''
|
|
if form_method == 'post' && protect_against_forgery?
|
|
request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
|
|
end
|
|
|
|
if confirm = html_options.delete("confirm")
|
|
html_options["onclick"] = "return #{confirm_javascript_function(confirm)};"
|
|
end
|
|
|
|
url = options.is_a?(String) ? options : self.url_for(options)
|
|
name ||= url
|
|
|
|
html_options.merge!("type" => "submit", "value" => name)
|
|
|
|
"<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button_to\"><div>" +
|
|
method_tag + content_tag("button", name, html_options) + request_token_tag + "</div></form>"
|
|
end
|
|
|
|
# Replacement for Rails' default button_to_function helper
|
|
# using HTML button element rather than HTML input element
|
|
def button_to_function(name, *args, &block)
|
|
html_options = args.extract_options!
|
|
function = args[0] || ''
|
|
|
|
html_options.symbolize_keys!
|
|
function = update_page(&block) if block_given?
|
|
content_tag(:button, name, html_options.merge({
|
|
:onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
|
|
}))
|
|
end
|
|
|
|
# Replacement for Rails' default label helper
|
|
# using String#titleize rather than String#humanize
|
|
def label(object_name, method, text = nil, options = {})
|
|
text ||= method.to_s[].titleize
|
|
super
|
|
end |