Module: Base::Project::App::Helpers::ButtonHelper

Defined in:
lib/base/project/app/helpers/button_helper.rb

Instance Method Summary collapse

Instance Method Details

#cancel_buttonObject



67
68
69
# File 'lib/base/project/app/helpers/button_helper.rb', line 67

def cancel_button
  round_icon_button(type: :button, icon: 'fa-close', button: 'btn-default', class: 'pull-right', title: 'Cancelar')
end

#command_button(path, row_id, message, additional = { }) ⇒ Object



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
# File 'lib/base/project/app/helpers/button_helper.rb', line 3

def command_button( path, row_id, message, additional = { } )
  options = { remote: false, role: :get, target: '_self', klass: '',
              text: "", confirm: false, data: { } }.merge( additional )

  text             = options[:text]
  role             = options[:role]
  icon             = options[:icon]
  klass            = options[:klass]
  is_remote        = options[:remote]
  html_data        = options[:data]

  data_params = html_data.merge( { toggle: 'tooltip', placement: 'top', 'row-id': row_id, 'original-title': message } )
  data_params[:confirm] = I18n.t('confirmation') if options[:confirm]

  button = command_button_item( klass, icon, text, data_params )

  if path.present?
    link_to(path, remote: is_remote, data: data_params, target: options[:target], method: role) do
      concat( button )
    end

  else
    button
  end
end

#command_button_item(klass, icon, text, data) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/base/project/app/helpers/button_helper.rb', line 29

def command_button_item( klass, icon, text, data )
  text = " #{text}" if text.present?

  button_tag( role: 'button', type: 'button', class: "btn btn-primary #{ klass }", data: data ) do
    ( :span, text, class: icon )
  end
end

#delete_button(path, row_id, message, additional = { }) ⇒ Object



47
48
49
50
# File 'lib/base/project/app/helpers/button_helper.rb', line 47

def delete_button( path, row_id, message, additional = { } )
  options = { role: :delete, icon: 'zmdi zmdi-delete', klass: 'command-delete', confirm: true }.merge( additional )
  command_button( path, row_id, I18n.t('simple_form.delete', message: message), options )
end

#do_filter_buttonObject



62
63
64
65
# File 'lib/base/project/app/helpers/button_helper.rb', line 62

def do_filter_button
   button_tag( t('simple_form.search'), id: 'enable-filter',
               class: 'btn btn-primary pull-right' )
end

#edit_button(path, row_id, message, additional = { }) ⇒ Object



37
38
39
40
# File 'lib/base/project/app/helpers/button_helper.rb', line 37

def edit_button( path, row_id, message, additional = { } )
  options = { role: :get, icon: 'zmdi zmdi-edit' }.merge( additional )
  command_button( path, row_id, I18n.t('simple_form.edit', message: message), options )
end

#new_button(path, message, additional = { }) ⇒ Object



42
43
44
45
# File 'lib/base/project/app/helpers/button_helper.rb', line 42

def new_button( path, message, additional = { } )
  options = { role: :get, icon: 'zmdi zmdi-plus' }.merge( additional )
  command_button( path, 0, I18n.t('simple_form.new', message: message), options )
end

#open_filter_buttonObject



57
58
59
60
# File 'lib/base/project/app/helpers/button_helper.rb', line 57

def open_filter_button
   button_tag( t('simple_form.filter'), id: 'enable-filter',
               class: 'btn btn-regular pull-left' )
end

#round_icon_button(params) ⇒ Object



71
72
73
74
75
76
# File 'lib/base/project/app/helpers/button_helper.rb', line 71

def round_icon_button(params)
  params[:shape] = 'btn-circle'
  params[:text] = ''

  text_icon_button(params)
end

#show_button(path, row_id, message, additional = { }) ⇒ Object



52
53
54
55
# File 'lib/base/project/app/helpers/button_helper.rb', line 52

def show_button( path, row_id, message, additional = { } )
  options = { role: :get, icon: 'zmdi zmdi-search' }.merge( additional )
  command_button( path, row_id, I18n.t('simple_form.show', message: message), options )
end

#text_icon_button(params) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/base/project/app/helpers/button_helper.rb', line 78

def text_icon_button(params)
  params[:size] ||= 'btn-lg'

  content = (:span) do
    concat((:span, '', class: "fa #{params[:icon]}"))
    concat(" #{params[:text]}") if params[:text] && params[:text].length > 0
  end

  button_data = { type: params[:type],
                  class: "btn #{params[:button]} #{params[:shape]} #{params[:size]} #{params[:class]} text-center",
                  title: params[:title],
                  data: {
                    toggle: 'tooltip',
                    placement: 'bottom'
                  }
                }


  button_data[:id] = params[:id] if params[:id]
  button_data[:data] = button_data[:data].merge(params[:data]) if params[:data]

  button_tag(content, button_data)
end