Module: BMC::ButtonHelper

Included in:
AllHelpers
Defined in:
app/helpers/bmc/button_helper.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_sizeObject



5
6
7
# File 'app/helpers/bmc/button_helper.rb', line 5

def default_size
  @default_size ||= :sm
end

.default_styleObject



9
10
11
# File 'app/helpers/bmc/button_helper.rb', line 9

def default_style
  @default_style ||= :outline_primary
end

Instance Method Details

#bs_button(url, method: :get, confirm: nil, text: nil, icon:, action: nil, title: text, btn_size: BMC::ButtonHelper.default_size, btn_style: BMC::ButtonHelper.default_style, add_class: [], helper: :link_to, **options) ⇒ Object

rubocop:disable Metrics/ParameterLists



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
47
48
49
50
51
52
53
54
55
# File 'app/helpers/bmc/button_helper.rb', line 14

def bs_button( # rubocop:disable Metrics/ParameterLists
  url,
  method: :get,
  confirm: nil,
  text: nil,
  icon:,
  action: nil,
  title: text,
  btn_size: BMC::ButtonHelper.default_size,
  btn_style: BMC::ButtonHelper.default_style,
  add_class: [],
  helper: :link_to,
  **options
)
  text = ta(action) if text.nil? && action

  content = fa_s(icon).concat(" ").concat(tag.span(text, class: "text"))

  if method != :get
    options[:method] = method
    confirm = true if confirm.nil?
  end

  unless options[:class]
    options[:class] = [
      "btn",
      "btn-#{btn_size}",
      "btn-#{btn_style.to_s.tr('_', '-')}",
      ("link-#{action}" if action),
      *add_class,
    ]
  end

  options[:title] = title

  unless confirm.nil?
    confirm = ta(:confirm) if confirm == true
    options.deep_merge!(data: {confirm: confirm})
  end

  public_send(helper, content, url, options.sort.to_h)
end

#bs_button_to(url, **options) ⇒ Object



57
58
59
# File 'app/helpers/bmc/button_helper.rb', line 57

def bs_button_to(url, **options)
  bs_button(url, helper: :button_to, **options)
end

#copy_button(url, **options) ⇒ Object



147
148
149
150
151
152
153
154
# File 'app/helpers/bmc/button_helper.rb', line 147

def copy_button(url, **options)
  options = {
    :icon   => :copy,
    :action => :copy,
  }.merge(options)

  bs_button(url, **options)
end

#delete_button(url, **options) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'app/helpers/bmc/button_helper.rb', line 89

def delete_button(url, **options)
  options = {
    :icon      => :trash,
    :action    => :delete,
    :btn_style => :danger,
    :method    => :delete,
  }.merge(options)

  bs_button(url, **options)
end

#download_button(url, **options) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'app/helpers/bmc/button_helper.rb', line 110

def download_button(url, **options)
  options = {
    :icon   => :cloud_download_alt,
    :action => :download,
    :target => :_blank,
  }.merge(options)

  bs_button(url, **options)
end

#edit_button(url, **options) ⇒ Object



80
81
82
83
84
85
86
87
# File 'app/helpers/bmc/button_helper.rb', line 80

def edit_button(url, **options)
  options = {
    :icon   => :pencil_alt,
    :action => :edit,
  }.merge(options)

  bs_button(url, **options)
end

#export_button(url, **options) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/helpers/bmc/button_helper.rb', line 120

def export_button(url, **options)
  ext = url.split(".").last

  if ext.length <= 4
    text = "#{ta(:export)} (#{ext.upcase})"
  else
    text = ta(:export)
  end

  options = {
    :icon   => :download,
    :action => :export,
    :text   => text,
  }.merge(options)

  download_button(url, **options)
end

#import_button(url, **options) ⇒ Object



138
139
140
141
142
143
144
145
# File 'app/helpers/bmc/button_helper.rb', line 138

def import_button(url, **options)
  options = {
    :icon   => :upload,
    :action => :import,
  }.merge(options)

  bs_button(url, **options)
end

#new_button(url = url_for(action: :new), **options) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'app/helpers/bmc/button_helper.rb', line 61

def new_button(url = url_for(action: :new), **options)
  options = {
    :icon      => :plus,
    :action    => :new,
    :btn_style => :success,
  }.merge(options)

  bs_button(url, **options)
end


100
101
102
103
104
105
106
107
108
# File 'app/helpers/bmc/button_helper.rb', line 100

def print_button(**options)
  options = {
    :icon    => :print,
    :action  => :print,
    :onclick => "print(); return false;",
  }.merge(options)

  bs_button("#", **options)
end

#read_button(url, **options) ⇒ Object



71
72
73
74
75
76
77
78
# File 'app/helpers/bmc/button_helper.rb', line 71

def read_button(url, **options)
  options = {
    :icon   => :info_circle,
    :action => :read,
  }.merge(options)

  bs_button(url, **options)
end