cirandas.net

ref: master

app/helpers/modal_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
module ModalHelper

  def modal_inline_link_to title, url, selector, options = {}
    link_to title, url, modal_options(options.merge(:inline => selector))
  end

  def modal_inline_icon type, title, url, selector, options = {}
    icon_button type, title, url, modal_options(options.merge(:inline => selector))
  end

  def modal_link_to title, url, options = {}
    link_to title, url, modal_options(options)
  end

  def modal_close_link text, options = {}
    link_to text, '#', modal_options(options, :close)
  end

  def modal_close_button(text, options = {})
    button :close, text, '#', modal_options(options, :close).merge(:rel => 'deactivate')
  end

  def modal_button(type, label, url, options = {})
    button type, label, url, modal_options(options)
  end

  def modal_icon_button(type, label, url, options = {})
    icon_button type, label, url, modal_options(options)
  end

  # options must be an HTML options hash as passed to link_to etc.
  #
  # returns a new hash with modal class added. Keeps existing classes.
  def modal_options(options, type=nil)
    inline_selector = options.delete :inline
    options[:onclick] = "return noosfero.modal.inline('#{inline_selector}')" if inline_selector

    classes = if inline_selector then '' else 'modal-toggle' end
    classes += " modal-#{type.to_s}" if type.present?
    classes << " #{options[:class]}" if options.has_key? :class
    options.merge!(:class => classes)

    options
  end

end