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: 060fa4ec7b7a834895eb20614d580d1bdd7ed0da
4
- data.tar.gz: 23a2c6b34612eab663d670af3704e4fae6c56f8a
3
+ metadata.gz: 242ed65ef4c998474921ac8dfac92d10e378278f
4
+ data.tar.gz: 47a06cd06ed40ec273e0b39a6c891b7ee7ffdbea
5
5
  SHA512:
6
- metadata.gz: 052ba0b9bb23756a8562b2218174b769223076f9a5e78d3b59a1cf202f4e616cce988bb2924aa8a32b22ec1ab8b78dc05374bef019aa682c26c662cbeb5c24f8
7
- data.tar.gz: e46b35c8bb32e8c5d47a52d7f1239e7d127c58a6c29457c99c203c5e0186cd973caec3df4f7ee8135b9550bcddb34ea490eed2c4afb3c30d4994416b89362a2d
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
- 'Save and Continue' => { action: :save, data: { disable_with: 'Saving...' }},
11
- 'Save and Add New' => { action: :save, data: { disable_with: 'Saving...' }}
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.inject({}) { |h, (commit, args)| h[commit] = args.except(:action, :if, :unless, :redirect); h }
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['Save and Continue'] = { data: { disable_with: 'Saving...' }} if resource.index_path(check: true)
12
- actions['Save and Add New'] = { data: { disable_with: 'Saving...' }} if resource.new_path(check: true)
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
- (actions.map { |action| form.button(:submit, *action.to_a) } + [(capture(&block) if block_given?)]).compact.join(' ').html_safe
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('&nbsp;').html_safe
18
41
  end
19
42
  end
20
43
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.6.3'.freeze
2
+ VERSION = '0.6.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect