Module: ModalHelper

Defined in:
app/helpers/modal_helper.rb

Instance Method Summary collapse

Instance Method Details

#close_button(dismiss) ⇒ Object



36
37
38
39
# File 'app/helpers/modal_helper.rb', line 36

def close_button(dismiss)
  #It doesn't seem to like content_tag, so we do this instead.
  raw("<button class=\"close\" data-dismiss=\"#{dismiss}\" aria-hidden=\"true\">&times;</button>")
end


28
29
30
# File 'app/helpers/modal_helper.rb', line 28

def modal_body(options, &block)
   :div, options[:content], :class => 'modal-body', :style => options[:style], &block
end


53
54
55
56
57
# File 'app/helpers/modal_helper.rb', line 53

def modal_cancel_button(content, options)
  default_opts = { :class => "btn bootstrap-modal-cancel-button" }

   "a", content, default_opts.merge(options)
end

modals have a header, a body, a footer for options.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/modal_helper.rb', line 4

def modal_dialog(options = {}, &block)
  options = {:id => 'modal', :size => '', :show_close => true, :dismiss => true}.merge options
   :div, :class => "bootstrap-modal modal fade", :id => options[:id] do
     :div, :class => "modal-dialog #{options['size']}" do
       :div, :class => "modal-content" do
        modal_header(options[:header], &block) +
        modal_body(options[:body], &block) +
        modal_footer(options[:footer], &block)
      end
    end
  end
end


32
33
34
# File 'app/helpers/modal_helper.rb', line 32

def modal_footer(options, &block)
   :div, options[:content], :class => 'modal-footer', &block
end


17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/modal_helper.rb', line 17

def modal_header(options, &block)
   :div, :class => 'modal-header' do
    if options[:show_close]
      close_button(options[:dismiss]) +
      (:h4, options[:title], :class => 'modal-title', &block)
    else
      (:h4, options[:title], :class => 'modal-title', &block)
    end
  end
end


41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/modal_helper.rb', line 41

def modal_toggle(content_or_options = nil, options, &block)
  if block_given?
    options = content_or_options if content_or_options.is_a?(Hash)
    default_options = { :class => 'btn btn-default', "data-toggle" => "modal", "href" => options[:dialog] }.merge(options)

     :a, nil, default_options, true, &block
  else
    default_options = { :class => 'btn btn-default', "data-toggle" => "modal", "href" => options[:dialog] }.merge(options)
     :a, content_or_options, default_options, true
  end
end