ct_table_for 0.1.14.beta → 0.1.15.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/ct_table_for/application_helper.rb +33 -18
- data/lib/ct_table_for/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47d43adfaf238986ed6bc4a3179a2c1d88754ac7bdac76514b94425e189e3a4a
|
4
|
+
data.tar.gz: edfb06df4f5c923a5982dda3121639006c749f23ea06b28bbc1a72d29786d0d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb1cbb2e933b3af1be135e9ec7ae13a93abcb442fe7820bfb28e73e3bbe800937d9282d64beb2a0dcd2dbb8caf0ba791a861a2e75602570dbb5ef78b41b7b4b2
|
7
|
+
data.tar.gz: 2e8fedb77519ce6ace6e965863889ae052e97bf725e096a11c16d8e82fbaacdfeae432f44c4bb8f8e6340d1f1e37858193036ab5ccbd044a2165d8bd8fe834bb
|
@@ -176,29 +176,19 @@ module CtTableFor
|
|
176
176
|
html << %Q{<td data-link-enabled="false">}
|
177
177
|
html << %Q{<div class="btn-group btn-group-sm" role="group" aria-label="#{I18n.t(:actions, scope: [:table_for]).capitalize}">}
|
178
178
|
nesting = (options[:actions][:premodel] || []) + [record]
|
179
|
-
buttons
|
180
|
-
buttons.each do |action|
|
179
|
+
buttons = options[:actions][:buttons].map{ |b| b.split("|")}
|
180
|
+
buttons.each do |action, *extras|
|
181
181
|
return "" if defined?(CanCanCan) and cannot?(action, record)
|
182
|
-
label = I18n.t(action.to_sym, scope: [:table_for, :buttons]).capitalize
|
183
|
-
custom_action_class = %Q{#{CtTableFor.table_for_default_action_base_class} #{options.dig(:btn_class, action.to_sym) || CtTableFor.table_for_action_class[action.to_sym]}}
|
184
182
|
case action.to_sym
|
185
183
|
when :show
|
186
|
-
|
187
|
-
label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{CtTableFor.table_for_action_icons[:show]}"></i>}
|
188
|
-
end
|
189
|
-
html << link_to(label.html_safe, polymorphic_path(nesting), class: custom_action_class)
|
184
|
+
html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, polymorphic_path(nesting), class: class_for_action(action, options))
|
190
185
|
when :edit
|
191
|
-
|
192
|
-
label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{CtTableFor.table_for_action_icons[:edit]}"></i>}
|
193
|
-
end
|
194
|
-
html << link_to(label.html_safe, edit_polymorphic_path(nesting), class: custom_action_class)
|
186
|
+
html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, edit_polymorphic_path(nesting), class: class_for_action(action, options))
|
195
187
|
when :destroy
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
html <<
|
200
|
-
method: :delete, class: custom_action_class,
|
201
|
-
data: { confirm: I18n.t('table_for.messages.are_you_sure').capitalize })
|
188
|
+
html << link_to(label_for_action(action, options[:actions][:icons]).html_safe, polymorphic_path(nesting),
|
189
|
+
method: :delete, class: class_for_action(action, options), data: { confirm: I18n.t('table_for.messages.are_you_sure').capitalize })
|
190
|
+
when :custom
|
191
|
+
html << button_for_custom_action(record, options, extras)
|
202
192
|
else
|
203
193
|
# TODO:
|
204
194
|
# nesting_custom = nesting + btn_options[0]
|
@@ -211,6 +201,27 @@ module CtTableFor
|
|
211
201
|
html.html_safe
|
212
202
|
end
|
213
203
|
|
204
|
+
def label_for_action action, icons = true
|
205
|
+
label = I18n.t(action.to_sym, scope: [:table_for, :buttons]).capitalize
|
206
|
+
if icons != false
|
207
|
+
label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{CtTableFor.table_for_action_icons[action.to_sym]}"></i>}
|
208
|
+
end
|
209
|
+
label
|
210
|
+
end
|
211
|
+
|
212
|
+
def class_for_action action, options
|
213
|
+
%Q{#{CtTableFor.table_for_default_action_base_class} #{options.dig(:btn_class, action.to_sym) || CtTableFor.table_for_action_class[action.to_sym]}}
|
214
|
+
end
|
215
|
+
|
216
|
+
def button_for_custom_action record, options, extras
|
217
|
+
parsed_extras = parse_extras(extras)
|
218
|
+
if options[:actions][:icons] != false
|
219
|
+
label = %Q{<i class="#{CtTableFor.table_for_icon_font_base_class} #{CtTableFor.table_for_icon_font_base_class}-#{parsed_extras[:icon]}"></i>}
|
220
|
+
end
|
221
|
+
custom_action_class = %Q{#{CtTableFor.table_for_default_action_base_class} #{parsed_extras[:class]}}
|
222
|
+
link_to(label.html_safe, polymorphic_path([parsed_extras[:link], record]), class: custom_action_class, title: parsed_extras[:title])
|
223
|
+
end
|
224
|
+
|
214
225
|
def uri?(string)
|
215
226
|
# http://ruby-doc.org/stdlib-2.4.0/libdoc/uri/rdoc/URI.html
|
216
227
|
uri = URI.parse(string)
|
@@ -220,5 +231,9 @@ module CtTableFor
|
|
220
231
|
rescue URI::InvalidURIError
|
221
232
|
false
|
222
233
|
end
|
234
|
+
|
235
|
+
def parse_extras(extras)
|
236
|
+
Hash[extras.collect { |extra| [extra.split(":").first, extra.split(":").last] } ].with_indifferent_access
|
237
|
+
end
|
223
238
|
end
|
224
239
|
end
|
data/lib/ct_table_for/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ct_table_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agustí B.R.
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|