-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.rb
50 lines (42 loc) · 2.18 KB
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module SimpleWorkflow::Helper
def image_button_to(image_source, title, options, html_options = {})
image_submit_tag image_source, {:class => 'image-submit', :alt => title, :title => title,
:id => "#{title}_#{options[:id]}", :name => title,
:onclick => "form.action='#{url_for(options)}'"}.update(html_options)
end
def detour_to(title, options, html_options = nil)
link_to title, with_detour(options), html_options
end
def with_detour(options, back_options = {})
detour_options = {:detour => (params.merge(back_options)).reject { |k, v| [:detour, :return_from_detour].include? k.to_sym }}
url = url_for(options) if options.respond_to? :to_param
return url + (url =~ /\?/ ? '&' : '?') + detour_options[:detour].map{|k,v| "detour[#{k}]=#{v}"}.join('&')
end
def image_detour_to(image_source, title, url_options, image_options = nil, link_options = nil)
image_options ||= {:class => 'image-submit'}
image_options.update :alt => title, :title => title
detour_to image_tag(image_source, image_options), url_options, link_options
end
def image_link_to(image_source, title, url_options, image_options = nil, post = false)
image_options ||= {:class => 'image-submit'}
image_options.update :alt => title, :title => title
link_to image_tag(image_source, image_options), url_options, post ? {:method => :post} : nil
end
def image_link_to_remote(image_source, title, link_options, image_options = nil, post = false)
image_options ||= {:class => 'image-submit'}
image_options.update :alt => title, :title => title
with_params = link_options.delete(:with)
link_to_remote image_tag(image_source, image_options), :url => link_options, :with => with_params, :html => post ? {:method => :post} : {}
end
def detour?
not session[:detours].nil?
end
def back_or_link_to(title, options = nil, html_options = nil)
if session[:detours]
options = {:return_from_detour => true}.update(session[:detours].last)
options[:id] ||= nil
logger.debug "linked return from detour: #{options.inspect}"
end
link_to(title, options, html_options) if options
end
end