Module: SimpleWorkflow::Helper

Included in:
ActionController::Base, ApplicationHelper
Defined in:
lib/simple_workflow/helper.rb

Instance Method Summary collapse

Instance Method Details



64
65
66
67
68
69
70
71
# File 'lib/simple_workflow/helper.rb', line 64

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

#detour?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/simple_workflow/helper.rb', line 60

def detour?
  not session[:detours].nil?
end

#detour_to(title, options, html_options = nil, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_workflow/helper.rb', line 8

def detour_to(title, options, html_options = nil, &block)
  if block
    html_options = options
    options = title
    link_with_detour = link_to(with_detour(options), html_options, &block)
  else
    link_with_detour = link_to title, with_detour(options), html_options
  end
  if link_with_detour.size > 4096 # URL maximum size overflow
    if block
      link_with_detour = link_to(options, html_options, &block)
    else
      link_with_detour = link_to title, with_detour(options), html_options
    end
  end
  link_with_detour
end

#image_button_to(image_source, title, options, html_options = {}) ⇒ Object



2
3
4
5
6
# File 'lib/simple_workflow/helper.rb', line 2

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

#image_detour_to(image_source, title, url_options, image_options = nil, link_options = nil) ⇒ Object



32
33
34
35
36
# File 'lib/simple_workflow/helper.rb', line 32

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


38
39
40
41
42
43
44
45
46
47
# File 'lib/simple_workflow/helper.rb', line 38

def image_link_to(image_source, title, url_options, image_options = nil, link_options = nil)
  if link_options == true
    link_options = {:method => :post}
  elsif link_options == false
    link_options = nil
  end
  image_options ||= {:class => 'image-submit'}
  image_options.update :alt => title, :title => title
  link_to image_tag(image_source, image_options), url_options, link_options
end


49
50
51
52
53
54
55
56
57
58
# File 'lib/simple_workflow/helper.rb', line 49

def image_link_to_remote(image_source, title, link_options, image_options = nil, html_options = {})
  if html_options == true
    html_options = {:method => :post}
  elsif html_options == false
    html_options = {}
  end
  image_options ||= {:class => 'image-submit'}
  image_options.update :alt => title, :title => title
  link_to image_tag(image_source, image_options), link_options, html_options.merge(:remote => true)
end

#with_detour(options, back_options = nil) ⇒ Object



26
27
28
29
30
# File 'lib/simple_workflow/helper.rb', line 26

def with_detour(options, back_options = nil)
  detour = back_options || params.reject { |k, v| [:detour, :return_from_detour].include? k.to_sym }
  url = url_for(options)
  return url + (url =~ /\?/ ? '&' : '?') + detour.to_param('detour')
end