Module: BMC::ButtonHelper
- Included in:
- AllHelpers
- Defined in:
- app/helpers/bmc/button_helper.rb
Class Attribute Summary collapse
- .confirm_attribute ⇒ Object
- .default_size ⇒ Object
- .default_style ⇒ Object
- .method_attribute ⇒ Object
Instance Method Summary collapse
-
#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.
- #bs_button_to(url) ⇒ Object
- #copy_button(url, **options) ⇒ Object
- #delete_button(url, **options) ⇒ Object
- #download_button(url, **options) ⇒ Object
- #edit_button(url, **options) ⇒ Object
- #export_button(url, **options) ⇒ Object
- #import_button(url, **options) ⇒ Object
- #new_button(url = url_for(action: :new), **options) ⇒ Object
- #print_button(**options) ⇒ Object
- #read_button(url, **options) ⇒ Object
Class Attribute Details
.confirm_attribute ⇒ Object
13 14 15 |
# File 'app/helpers/bmc/button_helper.rb', line 13 def confirm_attribute @confirm_attribute ||= :"data-turbo-confirm" end |
.default_size ⇒ Object
5 6 7 |
# File 'app/helpers/bmc/button_helper.rb', line 5 def default_size @default_size ||= :sm end |
.default_style ⇒ Object
9 10 11 |
# File 'app/helpers/bmc/button_helper.rb', line 9 def default_style @default_style ||= :outline_primary end |
.method_attribute ⇒ Object
17 18 19 |
# File 'app/helpers/bmc/button_helper.rb', line 17 def method_attribute @method_attribute ||= :"data-turbo-method" 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
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 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/bmc/button_helper.rb', line 22 def ( # 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, ** ) text = ta(action) if text.nil? && action content = fa_s(icon).concat(" ").concat(tag.span(text, class: "text")) if method != :get if helper == :link_to [BMC::ButtonHelper.method_attribute] = method [:rel] = "nofollow" elsif helper == :button_to [:method] = method end confirm = true if confirm.nil? end unless [:class] [:class] = [ "btn", "btn-#{btn_size}", "btn-#{btn_style.to_s.tr('_', '-')}", ("link-#{action}" if action), *add_class, ] end [:title] = title unless confirm.nil? confirm = ta(:confirm) if confirm == true [BMC::ButtonHelper.confirm_attribute] = confirm end public_send(helper, content, url, .sort.to_h) end |
#bs_button_to(url) ⇒ Object
70 71 72 |
# File 'app/helpers/bmc/button_helper.rb', line 70 def (url, **) (url, helper: :button_to, **) end |
#copy_button(url, **options) ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'app/helpers/bmc/button_helper.rb', line 160 def (url, **) = { :icon => :copy, :action => :copy, }.merge() (url, **) end |
#delete_button(url, **options) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'app/helpers/bmc/button_helper.rb', line 102 def (url, **) = { :icon => :trash, :action => :delete, :btn_style => :danger, :method => :delete, }.merge() (url, **) end |
#download_button(url, **options) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'app/helpers/bmc/button_helper.rb', line 123 def (url, **) = { :icon => :cloud_download_alt, :action => :download, :target => :_blank, }.merge() (url, **) end |
#edit_button(url, **options) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'app/helpers/bmc/button_helper.rb', line 93 def (url, **) = { :icon => :pencil_alt, :action => :edit, }.merge() (url, **) end |
#export_button(url, **options) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/bmc/button_helper.rb', line 133 def (url, **) ext = url.split(".").last if ext.length <= 4 text = "#{ta(:export)} (#{ext.upcase})" else text = ta(:export) end = { :icon => :download, :action => :export, :text => text, }.merge() (url, **) end |
#import_button(url, **options) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'app/helpers/bmc/button_helper.rb', line 151 def (url, **) = { :icon => :upload, :action => :import, }.merge() (url, **) end |
#new_button(url = url_for(action: :new), **options) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/bmc/button_helper.rb', line 74 def (url = url_for(action: :new), **) = { :icon => :plus, :action => :new, :btn_style => :success, }.merge() (url, **) end |
#print_button(**options) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/bmc/button_helper.rb', line 113 def (**) = { :icon => :print, :action => :print, :onclick => "print(); return false;", }.merge() ("#", **) end |
#read_button(url, **options) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/helpers/bmc/button_helper.rb', line 84 def (url, **) = { :icon => :info_circle, :action => :read, }.merge() (url, **) end |