Module: ToolButtonsHelper

Defined in:
app/helpers/tool_buttons_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_button(url, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/tool_buttons_helper.rb', line 24

def add_button( url, options = {} )

  # label for the button = icon + "add"
  label = tool_icon( "plus black" ) + " " + t( :add )

  # default options
  options = { 
    :class => 'add_button tool show_only_in_edit_mode btn btn-default',
    :remote => true
  }.merge( options )
  
  # create the link_to tag
  link_to( label, url.to_s, options )

end

#cancel_button(options = {}) ⇒ Object



49
50
51
52
# File 'app/helpers/tool_buttons_helper.rb', line 49

def cancel_button( options = {} )
  tool_button( :cancel, "remove black", "", 
               :title => t(:cancel) )
end

#edit_button(options = {}) ⇒ Object



40
41
42
# File 'app/helpers/tool_buttons_helper.rb', line 40

def edit_button( options = {} )
  tool_button :edit, "edit black", t(:edit), options
end

#remove_button(object, options = {}) ⇒ Object

options:

- show_only_in_edit_mode, default: true
- confirm, confirm message, e.g. "are you sure?", default: nil


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/tool_buttons_helper.rb', line 7

def remove_button(object, options = {})
  options[:show_only_in_edit_mode] = true if options[:show_only_in_edit_mode].nil?
  
  show_only_in_edit_mode_class = options[:show_only_in_edit_mode] ? "show_only_in_edit_mode" : ""
  title = t(:remove)
  title += ": " + object.title if object.respond_to?(:title) && object.title.present?
  link_to( tool_icon( "trash white" ),
           object,
           method: 'delete',
           :class => "remove_button tool #{show_only_in_edit_mode_class} btn btn-danger btn-sm",
           :title => title,
           :remote => true,
           'aria-label' => I18n.t(:remove),
           :confirm => options[:confirm]
         )
end

#save_button(options = {}) ⇒ Object



44
45
46
47
# File 'app/helpers/tool_buttons_helper.rb', line 44

def save_button( options = {} )
  tool_button( :save, "ok white", "", 
               :class => "save_button button btn btn-primary", :title => t(:save) )
end