effective_resources 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 242ed65ef4c998474921ac8dfac92d10e378278f
|
4
|
+
data.tar.gz: 47a06cd06ed40ec273e0b39a6c891b7ee7ffdbea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1976ae2d176a347561a8e46be0d0d807bc76d0b28051cbc366e1df787597e84d3c86fe4dab9bc9a50e4401a164cfe36189f4754919ae0a6c75da355ea7572907
|
7
|
+
data.tar.gz: d60fb69be39ab249983e1f0c0de0be33d08c8bdeecc7349492f702285b938500638b6de3a6362b62e28e31323ace75d57fad8b5c7636e0f0551b09c3640540de
|
@@ -7,8 +7,8 @@ module Effective
|
|
7
7
|
def member_actions
|
8
8
|
@_effective_member_actions ||= {
|
9
9
|
'Save' => { action: :save, data: { disable_with: 'Saving...' }},
|
10
|
-
'
|
11
|
-
'
|
10
|
+
'Continue' => { action: :save, data: { disable_with: 'Saving...' }},
|
11
|
+
'Add New' => { action: :save, data: { disable_with: 'Saving...' }}
|
12
12
|
}
|
13
13
|
end
|
14
14
|
end
|
@@ -262,7 +262,18 @@ module Effective
|
|
262
262
|
self.class.member_actions.select do |commit, args|
|
263
263
|
(args.key?(:if) ? obj.instance_exec(&args[:if]) : true) &&
|
264
264
|
(args.key?(:unless) ? !obj.instance_exec(&args[:unless]) : true)
|
265
|
-
end.
|
265
|
+
end.sort do |(commit_x, x), (commit_y, y)|
|
266
|
+
danger = (x[:class].to_s.index('danger') || -1) <=> (y[:class].to_s.index('danger') || -1)
|
267
|
+
danger = nil if danger == 0
|
268
|
+
|
269
|
+
save_action = (x[:action] == :save ? 0 : -1) <=> (y[:action] == :save ? 0 : -1)
|
270
|
+
save_action = nil if save_action == 0
|
271
|
+
|
272
|
+
danger || save_action || 0
|
273
|
+
end.inject({}) do |h, (commit, args)|
|
274
|
+
Rails.logger.info commit
|
275
|
+
h[commit] = args.except(:action, :if, :unless, :redirect); h
|
276
|
+
end
|
266
277
|
end
|
267
278
|
|
268
279
|
protected
|
@@ -3,18 +3,41 @@ module EffectiveResourcesHelper
|
|
3
3
|
def simple_form_submit(form, options = {class: 'form-actions'}, &block)
|
4
4
|
resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
5
5
|
|
6
|
+
# Apply btn-primary to the first item, only if the class isn't already present
|
6
7
|
actions = if controller.respond_to?(:member_actions_for)
|
7
|
-
controller.member_actions_for(form.object)
|
8
|
+
controller.member_actions_for(form.object).transform_values.with_index do |opts, index|
|
9
|
+
if opts[:class].present?
|
10
|
+
opts
|
11
|
+
else
|
12
|
+
opts[:class] = "btn #{index == 0 ? 'btn-primary' : 'btn-default'}"
|
13
|
+
end
|
14
|
+
|
15
|
+
opts
|
16
|
+
end
|
17
|
+
|
8
18
|
else
|
9
19
|
{}.tap do |actions|
|
10
|
-
actions['Save'] = { data: { disable_with: 'Saving...' }}
|
11
|
-
actions['
|
12
|
-
actions['
|
20
|
+
actions['Save'] = { class: 'btn btn-primary', data: { disable_with: 'Saving...' }}
|
21
|
+
actions['Continue'] = { class: 'btn btn-default', data: { disable_with: 'Saving...' }} if resource.index_path(check: true)
|
22
|
+
actions['Add New'] = { class: 'btn btn-default', data: { disable_with: 'Saving...' }} if resource.new_path(check: true)
|
13
23
|
end
|
14
24
|
end
|
15
25
|
|
16
26
|
content_tag(:div, class: options[:class]) do
|
17
|
-
|
27
|
+
buttons = actions.group_by { |(_, args)| args[:class] }.flat_map do |_, action|
|
28
|
+
action.map { |action| form.button(:submit, *action) } + ['']
|
29
|
+
end
|
30
|
+
|
31
|
+
# I think this is a bug. I can't override default button class when passing my own class: variable. it merges them.
|
32
|
+
if (btn_class = SimpleForm.button_class).present?
|
33
|
+
buttons = buttons.map { |button| button.sub(btn_class, '') }
|
34
|
+
end
|
35
|
+
|
36
|
+
if block_given?
|
37
|
+
buttons = [capture(&block), ''] + buttons
|
38
|
+
end
|
39
|
+
|
40
|
+
result = buttons.join(' ').html_safe
|
18
41
|
end
|
19
42
|
end
|
20
43
|
|