state_machine_buttons 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/state_machine_buttons/renderer.rb +6 -6
- data/lib/state_machine_buttons/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef89473af1ebcc8e04611cea16c599851dbfad64
|
4
|
+
data.tar.gz: 0dc344776c9fc577d3b026969373646fec2db86e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9ae8dd74b32b9e52d3046abc3d4dc454600e9be8f928dd325d77e8341bdbd8abd23fac6108e0bdc900e1654667ea7474fe776155c85c33b9e991d95136b7d49
|
7
|
+
data.tar.gz: de51605c9467dd1bed27c3ea94acaf4f7802b75ca2c7cc3abc1d5ff43dfe966bcbf39b254e4ec8e40a96f774c9f3e3c1b96d0cbdbbc54984c61011da0a84f0ba
|
@@ -2,29 +2,29 @@
|
|
2
2
|
|
3
3
|
module StateMachineButtons
|
4
4
|
module Renderer
|
5
|
-
def state_events_buttons(object, state_method: :state, route_method: nil, parameters: {}, without: nil, namespace: nil)
|
5
|
+
def state_events_buttons(object, state_method: :state, route_method: nil, parameters: {}, without: nil, namespace: nil, model_param_name: nil)
|
6
6
|
model_name = object.model.model_name.name.underscore
|
7
|
+
model_param_name ||= model_name
|
7
8
|
excepted_actions = without.is_a?(Array) ? without.map(&:to_sym) : [without.to_sym] if without
|
8
9
|
transitions = object.model.send("#{state_method}_transitions").reject do |t|
|
9
10
|
excepted_actions.present? && excepted_actions.include?(t.event)
|
10
11
|
end
|
11
12
|
content_tag(:div, class: 'btn-group-vertical') do
|
12
13
|
transitions.each do |event|
|
13
|
-
button event: event, model_name: model_name, object: object, state_method: state_method, route_method: route_method, namespace: namespace, parameters: parameters
|
14
|
+
button event: event, model_name: model_name, object: object, state_method: state_method, route_method: route_method, namespace: namespace, parameters: parameters, model_param_name: model_param_name
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
|
20
|
-
def button(event:, model_name:, object:, state_method:, route_method:, namespace:, parameters:)
|
21
|
+
def button(event:, model_name:, object:, state_method:, route_method:, namespace:, parameters:, model_param_name:)
|
21
22
|
route_method ||= "#{namespace.present? ? "#{namespace}_": ""}#{model_name.gsub('/', '_')}_path"
|
22
|
-
href = send route_method, object.model, parameters.merge(
|
23
|
+
href = send route_method, object.model, parameters.merge(model_param_name => { state_method => event.to })
|
23
24
|
concat(
|
24
25
|
link_to(
|
25
26
|
href,
|
26
|
-
|
27
|
-
class: "btn btn-sm btn-xs",
|
27
|
+
class: "btn btn-sm btn-xs btn-#{object.send("#{state_method}_button_color", event.event)}",
|
28
28
|
method: :patch
|
29
29
|
) do
|
30
30
|
t("state_machines.#{model_name}.#{state_method}.events.#{event.event}")
|