effective_resources 1.8.13 → 1.8.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/effective/crud_controller/respond.rb +10 -1
- data/app/controllers/concerns/effective/wizard_controller.rb +2 -2
- data/app/controllers/concerns/effective/wizard_controller/actions.rb +1 -1
- data/app/controllers/concerns/effective/wizard_controller/before_actions.rb +2 -2
- data/app/controllers/concerns/effective/wizard_controller/save.rb +1 -1
- data/app/helpers/effective_acts_as_email_form_helper.rb +32 -0
- data/app/helpers/effective_resources_helper.rb +1 -2
- data/app/helpers/effective_resources_wizard_helper.rb +1 -1
- data/app/models/concerns/acts_as_email_form.rb +74 -0
- data/app/models/concerns/acts_as_wizard.rb +5 -0
- data/app/models/effective/resources/init.rb +14 -2
- data/app/views/effective/acts_as_email_form/_fields.html.haml +33 -0
- data/lib/effective_resources/engine.rb +1 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 180638d525bdd6d499cddd67f09595509685ebbfdc59e69ea16d89fdef6ff1fa
|
4
|
+
data.tar.gz: e9687c798dceef560a070a4631876ca17b401cf2e7d993c7df98dbe5af5febc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41b62506a91d29ebe9049ce5de063e18412ba60cf4d63636e2cbe245d2b972a8a767d4645d2f42f5b4923b73eb867b4ea0ed508bda1ab55747d68f46dc1db4af
|
7
|
+
data.tar.gz: de31440669699862980273c6b1ce68b786057d200b524ec1ad0a54a09d73b8fbae9bfb372918b263fe8bc23254329ca15feb305adab7a683d86833738d0c5f6c
|
@@ -15,7 +15,16 @@ module Effective
|
|
15
15
|
|
16
16
|
format.js do
|
17
17
|
flash[:success] ||= resource_flash(:success, resource, action)
|
18
|
-
|
18
|
+
|
19
|
+
if params[:_datatable_action]
|
20
|
+
redirect_to(resource_redirect_path(resource, action))
|
21
|
+
else
|
22
|
+
render(
|
23
|
+
(template_present?(action) ? action : :member_action),
|
24
|
+
locals: { action: action, remote_form_redirect: resource_redirect_path(resource, action)}
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
19
28
|
end
|
20
29
|
end
|
21
30
|
elsif template_present?(action)
|
@@ -46,9 +46,9 @@ module Effective
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def resource_wizard_step_title(step)
|
49
|
+
def resource_wizard_step_title(resource, step)
|
50
50
|
return if step == 'wicked_finish'
|
51
|
-
|
51
|
+
resource.wizard_step_title(step)
|
52
52
|
end
|
53
53
|
|
54
54
|
def resource_wizard_steps
|
@@ -8,7 +8,7 @@ module Effective
|
|
8
8
|
self.resource ||= resource_scope.new
|
9
9
|
EffectiveResources.authorize!(self, :new, resource)
|
10
10
|
|
11
|
-
redirect_to resource_wizard_path(:new, resource_wizard_steps.first)
|
11
|
+
redirect_to resource_wizard_path(:new, resource.first_uncompleted_step || resource_wizard_steps.first)
|
12
12
|
end
|
13
13
|
|
14
14
|
def show
|
@@ -49,7 +49,7 @@ module Effective
|
|
49
49
|
Rails.logger.info " Unable to visit step :#{step}. Last can_visit_step? is :#{next_step}. Change the acts_as_wizard model's can_visit_step?(step) function to change this."
|
50
50
|
end
|
51
51
|
|
52
|
-
flash[:success] = "You have been redirected to the #{resource_wizard_step_title(next_step)} step."
|
52
|
+
flash[:success] = "You have been redirected to the #{resource_wizard_step_title(resource, next_step)} step."
|
53
53
|
redirect_to wizard_path(next_step)
|
54
54
|
end
|
55
55
|
|
@@ -66,7 +66,7 @@ module Effective
|
|
66
66
|
# before_action :assign_page_title, only: [:show, :update]
|
67
67
|
# Assign page title
|
68
68
|
def assign_page_title
|
69
|
-
@page_title ||= resource_wizard_step_title(step)
|
69
|
+
@page_title ||= resource_wizard_step_title(resource, step)
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
@@ -9,7 +9,7 @@ module Effective
|
|
9
9
|
if save_resource(resource, action)
|
10
10
|
flash[:success] ||= options.delete(:success) || resource_flash(:success, resource, action)
|
11
11
|
|
12
|
-
@skip_to ||= next_step
|
12
|
+
@skip_to ||= resource.required_steps.find { |s| s == next_step } || resource.first_uncompleted_step
|
13
13
|
@redirect_to ||= resource_wizard_path(resource, @skip_to) if was_new_record
|
14
14
|
|
15
15
|
redirect_to(@redirect_to || wizard_path(@skip_to))
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EffectiveActsAsEmailFormHelper
|
4
|
+
|
5
|
+
def email_form_fields(form, action = nil, skip: true, to: nil, variables: nil, partial: nil)
|
6
|
+
raise('expected a form') unless form.respond_to?(:object)
|
7
|
+
|
8
|
+
resource = form.object
|
9
|
+
raise('expected an acts_as_email_form resource') unless resource.class.respond_to?(:acts_as_email_form?)
|
10
|
+
|
11
|
+
# Load the template.
|
12
|
+
email_template = if action.present? && resource.email_form_effective_email_templates?
|
13
|
+
Effective::EmailTemplate.where(template_name: action).first!
|
14
|
+
end
|
15
|
+
|
16
|
+
# These defaults are only used when there is no email_template
|
17
|
+
email_defaults = form.object.email_form_defaults(action) unless email_template.present?
|
18
|
+
|
19
|
+
locals = {
|
20
|
+
form: form,
|
21
|
+
email_to: to,
|
22
|
+
email_skip: skip,
|
23
|
+
email_action: (action || true),
|
24
|
+
email_defaults: email_defaults,
|
25
|
+
email_template: email_template,
|
26
|
+
email_variables: variables
|
27
|
+
}
|
28
|
+
|
29
|
+
render(partial: (partial || 'effective/acts_as_email_form/fields'), locals: locals)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -116,7 +116,6 @@ module EffectiveResourcesHelper
|
|
116
116
|
locals = {
|
117
117
|
resource: resource,
|
118
118
|
effective_resource: effective_resource,
|
119
|
-
formats: [:html],
|
120
119
|
format_block: (block if block_given?),
|
121
120
|
namespace: namespace,
|
122
121
|
actions: actions,
|
@@ -133,7 +132,7 @@ module EffectiveResourcesHelper
|
|
133
132
|
spacer_template: spacer_template
|
134
133
|
)
|
135
134
|
else
|
136
|
-
render(partial, locals)
|
135
|
+
render(partial: partial, formats: [:html], locals: locals)
|
137
136
|
end
|
138
137
|
end
|
139
138
|
|
@@ -20,7 +20,7 @@ module EffectiveResourcesWizardHelper
|
|
20
20
|
def render_wizard_sidebar_item(resource, nav_step, index = nil)
|
21
21
|
# From Controller
|
22
22
|
current = (nav_step == step)
|
23
|
-
title = resource_wizard_step_title(nav_step)
|
23
|
+
title = resource_wizard_step_title(resource, nav_step)
|
24
24
|
|
25
25
|
# From Model
|
26
26
|
disabled = !resource.can_visit_step?(nav_step)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# ActsAsEmailForm
|
2
|
+
# Adds an email_form_skip, email_form_from, email_form_subject, email_form_body attr_accessors
|
3
|
+
# And some helpful methods to render and validate a Email to Send form
|
4
|
+
# That should work with or without effective_email_templates to send an email on a model
|
5
|
+
|
6
|
+
module ActsAsEmailForm
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module Base
|
10
|
+
def acts_as_email_form
|
11
|
+
include ::ActsAsEmailForm
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
included do
|
16
|
+
# Yes, we are submitting an email form
|
17
|
+
attr_accessor :email_form_action
|
18
|
+
|
19
|
+
# Skip sending the email entirely
|
20
|
+
attr_accessor :email_form_skip
|
21
|
+
|
22
|
+
# The email From / Subject / Body fields
|
23
|
+
attr_accessor :email_form_from
|
24
|
+
attr_accessor :email_form_subject
|
25
|
+
attr_accessor :email_form_body
|
26
|
+
|
27
|
+
effective_resource do
|
28
|
+
email_form_action :string, permitted: true
|
29
|
+
email_form_skip :boolean, permitted: true
|
30
|
+
|
31
|
+
email_form_from :string, permitted: true
|
32
|
+
email_form_subject :string, permitted: true
|
33
|
+
email_form_body :text, permitted: true
|
34
|
+
end
|
35
|
+
|
36
|
+
with_options(if: -> { email_form_action.present? && !email_form_skip? }) do
|
37
|
+
validates :email_form_from, presence: true
|
38
|
+
validates :email_form_subject, presence: true
|
39
|
+
validates :email_form_body, presence: true
|
40
|
+
|
41
|
+
validate(unless: -> { email_form_from.blank? }) do
|
42
|
+
self.errors.add(:email_form_from, 'must be a valid email address') unless email_form_from.include?('@')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if defined?(EffectiveEmailTemplates)
|
47
|
+
validates :email_form_subject, liquid: true, if: -> { email_form_effective_email_templates? }
|
48
|
+
validates :email_form_body, liquid: true, if: -> { email_form_effective_email_templates? }
|
49
|
+
end
|
50
|
+
|
51
|
+
def email_form_params
|
52
|
+
{ from: email_form_from, subject: email_form_subject, body: email_form_body }.compact
|
53
|
+
end
|
54
|
+
|
55
|
+
def email_form_skip?
|
56
|
+
EffectiveResources.truthy?(email_form_skip)
|
57
|
+
end
|
58
|
+
|
59
|
+
def email_form_effective_email_templates?
|
60
|
+
!!defined?(EffectiveEmailTemplates)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Only considered when not using an effective email template
|
64
|
+
def email_form_defaults(action)
|
65
|
+
{ from: nil, subject: nil, body: nil }
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
module ClassMethods
|
71
|
+
def acts_as_email_form?; true; end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -43,6 +43,7 @@ module ActsAsWizard
|
|
43
43
|
wizard_steps[current_step.to_sym] ||= Time.zone.now
|
44
44
|
end
|
45
45
|
|
46
|
+
# Use can_visit_step? required_steps and wizard_step_title(step) to control the wizard behaviour
|
46
47
|
def can_visit_step?(step)
|
47
48
|
can_revisit_completed_steps(step)
|
48
49
|
end
|
@@ -52,6 +53,10 @@ module ActsAsWizard
|
|
52
53
|
self.class.const_get(:WIZARD_STEPS).keys
|
53
54
|
end
|
54
55
|
|
56
|
+
def wizard_step_title(step)
|
57
|
+
self.class.const_get(:WIZARD_STEPS).fetch(step)
|
58
|
+
end
|
59
|
+
|
55
60
|
def first_completed_step
|
56
61
|
required_steps.find { |step| has_completed_step?(step) }
|
57
62
|
end
|
@@ -78,8 +78,20 @@ module Effective
|
|
78
78
|
# acpa/admin/shirts
|
79
79
|
(names.length).downto(1).each do |n|
|
80
80
|
names.combination(n).to_a.each do |pieces|
|
81
|
-
|
82
|
-
|
81
|
+
klass = begin
|
82
|
+
klass_pieces = pieces.map { |piece| piece.classify } * '::'
|
83
|
+
klass_pieces.safe_constantize
|
84
|
+
end
|
85
|
+
|
86
|
+
klass ||= if pieces.length > 1
|
87
|
+
klass_pieces = ([pieces.first.classify] + pieces[1..-1].map { |piece| piece.classify }) * '::'
|
88
|
+
klass_pieces.safe_constantize
|
89
|
+
end
|
90
|
+
|
91
|
+
klass ||= if pieces.length > 1
|
92
|
+
klass_pieces = ([pieces.first.classify.pluralize] + pieces[1..-1].map { |piece| piece.classify }) * '::'
|
93
|
+
klass_pieces.safe_constantize
|
94
|
+
end
|
83
95
|
|
84
96
|
if klass.present? && klass.class != Module
|
85
97
|
@namespaces ||= (names - pieces)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
= form.hidden_field :email_form_action, value: email_action
|
2
|
+
|
3
|
+
- if email_skip
|
4
|
+
= form.check_box :email_form_skip, label: 'Do not send email'
|
5
|
+
|
6
|
+
= form.hide_if :email_form_skip, true do
|
7
|
+
- if email_to.present? && form.respond_to?(:static_field)
|
8
|
+
= form.static_field :email_form_to, label: 'To', value: (email_to.respond_to?(:email) ? email_to.email : email_to)
|
9
|
+
|
10
|
+
- if form.object.errors.present?
|
11
|
+
= form.text_field :email_form_from, label: 'From'
|
12
|
+
= form.text_field :email_form_subject, label: 'Subject'
|
13
|
+
= form.text_area :email_form_body, label: 'Body', rows: 10
|
14
|
+
|
15
|
+
- elsif email_template.present?
|
16
|
+
-# email_template is an Effective::EmailTemplate
|
17
|
+
= form.text_field :email_form_from, label: 'From', value: email_template.from
|
18
|
+
= form.text_field :email_form_subject, label: 'Subject', value: email_template.subject
|
19
|
+
= form.text_area :email_form_body, label: 'Body', value: email_template.body, rows: 10
|
20
|
+
|
21
|
+
- else
|
22
|
+
= form.text_field :email_form_from, label: 'From', value: (email_defaults[:from] || '')
|
23
|
+
= form.text_field :email_form_subject, label: 'Subject', value: (email_defaults[:subject] || '')
|
24
|
+
= form.text_area :email_form_body, label: 'Body', rows: 10, value: (email_defaults[:body] || '')
|
25
|
+
|
26
|
+
- if email_variables.present?
|
27
|
+
%p The available variables are:
|
28
|
+
|
29
|
+
%ul
|
30
|
+
- email_variables.each do |variable|
|
31
|
+
%li {{ #{variable} }}
|
32
|
+
|
33
|
+
%small.text-muted Only a developer can add additional variables
|
@@ -23,6 +23,7 @@ module EffectiveResources
|
|
23
23
|
initializer 'effective_resources.active_record' do |app|
|
24
24
|
ActiveSupport.on_load :active_record do
|
25
25
|
ActiveRecord::Base.extend(ActsAsArchived::Base)
|
26
|
+
ActiveRecord::Base.extend(ActsAsEmailForm::Base)
|
26
27
|
ActiveRecord::Base.extend(ActsAsTokened::Base)
|
27
28
|
ActiveRecord::Base.extend(ActsAsSlugged::Base)
|
28
29
|
ActiveRecord::Base.extend(ActsAsStatused::Base)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -133,10 +133,12 @@ files:
|
|
133
133
|
- app/controllers/concerns/effective/wizard_controller/before_actions.rb
|
134
134
|
- app/controllers/concerns/effective/wizard_controller/save.rb
|
135
135
|
- app/controllers/concerns/effective/wizard_controller/wicked_overrides.rb
|
136
|
+
- app/helpers/effective_acts_as_email_form_helper.rb
|
136
137
|
- app/helpers/effective_resources_helper.rb
|
137
138
|
- app/helpers/effective_resources_private_helper.rb
|
138
139
|
- app/helpers/effective_resources_wizard_helper.rb
|
139
140
|
- app/models/concerns/acts_as_archived.rb
|
141
|
+
- app/models/concerns/acts_as_email_form.rb
|
140
142
|
- app/models/concerns/acts_as_slugged.rb
|
141
143
|
- app/models/concerns/acts_as_statused.rb
|
142
144
|
- app/models/concerns/acts_as_tokened.rb
|
@@ -177,6 +179,7 @@ files:
|
|
177
179
|
- app/views/application/show.html.haml
|
178
180
|
- app/views/application/show.js.erb
|
179
181
|
- app/views/application/update.js.erb
|
182
|
+
- app/views/effective/acts_as_email_form/_fields.html.haml
|
180
183
|
- app/views/effective/resource/_actions.html.haml
|
181
184
|
- app/views/effective/resource/_actions_dropleft.html.haml
|
182
185
|
- app/views/effective/resource/_actions_glyphicons.html.haml
|