effective_resources 2.23.0 → 2.24.0

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
  SHA256:
3
- metadata.gz: b5203021d6f8cd741603bcf0459f4277f6227c56fde16fd21fb99cae45564667
4
- data.tar.gz: 505149510d60183e7b0935a043f6be30d96dbb79099225a89c6fdc136ad1100d
3
+ metadata.gz: d92db06b508d630c29e392525580e558bc4fa5505358a04dcc371397ef0c6bc3
4
+ data.tar.gz: e808c12ee8b6e047409ec0c5fb4855db64abfe79f15b35769f324b0202ad97e8
5
5
  SHA512:
6
- metadata.gz: 5efcc14c75d711551ae84574fd1bb64970273a170c7135a645af656b55be45ea8b71520827950933b13d636a32c51c5b0a4a58326666bbcf8722394ae086b6ad
7
- data.tar.gz: ca89163745a47fe5be4342149df505800565cf6afc6991a9d765de4099d8b2efe17f570f27026eadaa5f7c6629edcd6d7f25c4f0ba5e6a13ea6b840f52c49f15
6
+ metadata.gz: 17830298a77d5f208d346b7a154da717c3670803d9868c803fa08f57f1fb37a0ebcab523a476970be3e90fbdc35fb3df2d4cf2508ddb5f48f7956d8767991b0a
7
+ data.tar.gz: c03f3f837d93e5c4ed6506f6110cdc737aa3643c1ec0fd88f93168d4dc7f06650253eb9daf09b55e3a949f1f8835926575e6fae98d8a36b55a0834c2569316c5
@@ -69,7 +69,7 @@ module Effective
69
69
 
70
70
  def build_wizard_resource
71
71
  resource = resource_scope.new
72
- resource.strict_loading!(false) if resource.respond_to?(:strict_loading!)
72
+ (resource.strict_loading!(false) rescue false) if resource.respond_to?(:strict_loading!)
73
73
  resource
74
74
  end
75
75
 
@@ -1,7 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module EffectiveActsAsEmailFormHelper
3
+ module EffectiveResourcesEmailHelper
4
+ def mailer_froms_collection(froms: nil)
5
+ froms ||= EffectiveResources.mailer_froms
6
+
7
+ froms.map do |from|
8
+ html = content_tag(:span, escape_once(from))
9
+ [from, from, 'data-html': html]
10
+ end
11
+ end
4
12
 
13
+ # acts_as_email_form
5
14
  def email_form_fields(form, action = nil, skip: true, to: nil, variables: nil, partial: nil)
6
15
  raise('expected a form') unless form.respond_to?(:object)
7
16
 
@@ -41,13 +50,38 @@ module EffectiveActsAsEmailFormHelper
41
50
  render(partial: (partial || 'effective/acts_as_email_form/fields'), locals: locals)
42
51
  end
43
52
 
44
- def mailer_froms_collection(froms: nil)
45
- froms ||= EffectiveResources.mailer_froms
53
+ # acts_as_email_notification
54
+ def email_notification_fields(form, action, partial: nil, variables: nil)
55
+ raise('expected a form') unless form.respond_to?(:object)
46
56
 
47
- froms.map do |from|
48
- html = content_tag(:span, escape_once(from))
49
- [from, from, 'data-html': html]
57
+ resource = form.object
58
+
59
+ # Intended for acts_as_email_notification
60
+ raise('expected an acts_as_email_notification resource') unless resource.class.respond_to?(:acts_as_email_notification?)
61
+
62
+ # Load the template.
63
+ email_template = if action.present? && defined?(EffectiveEmailTemplates)
64
+ action.kind_of?(Effective::EmailTemplate) ? action : Effective::EmailTemplate.where(template_name: action).first!
50
65
  end
66
+
67
+ raise('expected an Effective::EmailTemplate') unless email_template.kind_of?(Effective::EmailTemplate)
68
+
69
+ locals = {
70
+ form: form,
71
+
72
+ email_from: email_template.try(:from),
73
+ email_subject: email_template.try(:subject),
74
+ email_body: email_template.try(:body),
75
+ email_cc: email_template.try(:cc),
76
+ email_bcc: email_template.try(:bcc),
77
+ email_content_type: email_template.try(:content_type),
78
+
79
+ email_template: email_template,
80
+ email_variables: variables
81
+ }
82
+
83
+ render(partial: (partial || 'effective/acts_as_email_notification/fields'), locals: locals)
51
84
  end
52
85
 
86
+
53
87
  end
@@ -49,24 +49,24 @@ module ActsAsEmailForm
49
49
  validates :email_form_subject, liquid: true
50
50
  validates :email_form_body, liquid: true
51
51
  end
52
+ end
52
53
 
53
- def email_form_params
54
- { from: email_form_from, subject: email_form_subject, body: email_form_body }.compact
55
- end
56
-
57
- def email_form_skip?
58
- EffectiveResources.truthy?(email_form_skip)
59
- end
54
+ module ClassMethods
55
+ def acts_as_email_form?; true; end
56
+ end
60
57
 
61
- # Only considered when not using an effective email template
62
- def email_form_defaults(action)
63
- { from: nil, subject: nil, body: nil, content_type: 'text/plain' }
64
- end
58
+ # Instance methods
59
+ def email_form_params
60
+ { from: email_form_from, subject: email_form_subject, body: email_form_body }.compact
61
+ end
65
62
 
63
+ def email_form_skip?
64
+ EffectiveResources.truthy?(email_form_skip)
66
65
  end
67
66
 
68
- module ClassMethods
69
- def acts_as_email_form?; true; end
67
+ # Only considered when not using an effective email template
68
+ def email_form_defaults(action)
69
+ { from: nil, subject: nil, body: nil, content_type: 'text/plain' }
70
70
  end
71
71
 
72
72
  end
@@ -0,0 +1,82 @@
1
+ # ActsAsEmailNotification
2
+ # Used for email notification resources that are initialized from an effective_email_template but save their own liquid template content.
3
+ # Effective::EventNotification, Effective::PollNotification, Effective::Notification
4
+
5
+ module ActsAsEmailNotification
6
+ extend ActiveSupport::Concern
7
+
8
+ module Base
9
+ def acts_as_email_notification
10
+ include ::ActsAsEmailNotification
11
+ end
12
+ end
13
+
14
+ included do
15
+ if respond_to?(:effective_resource)
16
+ effective_resource do
17
+ from :string
18
+ cc :string
19
+ bcc :string
20
+
21
+ subject :string
22
+ body :text
23
+
24
+ content_type :string
25
+ end
26
+ end
27
+
28
+ validates :from, presence: true, email: true
29
+ validates :cc, email_cc: true
30
+ validates :bcc, email_cc: true
31
+
32
+ validates :subject, presence: true
33
+ validates :body, presence: true
34
+
35
+ validates :content_type, presence: true, inclusion: { in: ['text/plain', 'text/html'] }
36
+
37
+ validates :email_template, presence: true
38
+
39
+ with_options(if: -> { defined?(EffectiveEmailTemplates) }) do
40
+ validates :body, liquid: true
41
+ validates :subject, liquid: true
42
+ end
43
+
44
+ validate(if: -> { email_notification_html? && body.present? }) do
45
+ errors.add(:body, 'expected html tags in body') if email_notification_body_plain?
46
+ end
47
+
48
+ validate(if: -> { email_notification_plain? && body.present? }) do
49
+ errors.add(:body, 'unexpected html tags found in body') if email_notification_body_html?
50
+ end
51
+ end
52
+
53
+ module ClassMethods
54
+ def acts_as_email_notification?; true; end
55
+ end
56
+
57
+ def email_notification_params
58
+ { from: from, cc: cc.presence, bcc: bcc.presence, subject: subject, body: body, content_type: content_type }
59
+ end
60
+
61
+ def email_notification_html?
62
+ content_type == 'text/html'
63
+ end
64
+
65
+ def email_notification_plain?
66
+ content_type == 'text/plain'
67
+ end
68
+
69
+ def email_notification_body_html?
70
+ body.present? && (body.include?('</p>') || body.include?('</div>'))
71
+ end
72
+
73
+ def email_notification_body_plain?
74
+ body.present? && !(body.include?('</p>') || body.include?('</div>'))
75
+ end
76
+
77
+ # To be overrided
78
+ def email_template
79
+ nil
80
+ end
81
+
82
+ end
@@ -4,24 +4,35 @@
4
4
  = form.check_box :email_form_skip, label: 'Do not send email'
5
5
 
6
6
  = form.hide_if :email_form_skip, true do
7
- - errors = form.object.errors.present?
8
-
9
7
  - if email_to.present?
10
8
  = form.static_field :email_form_to, label: 'To', value: (email_to.try(:email) || email_to)
11
9
 
12
- = form.select :email_form_from, mailer_froms_collection(), label: 'From', value: (email_from unless errors)
13
- = form.text_field :email_form_subject, label: 'Subject', value: (email_subject unless errors)
14
-
15
- - if email_content_type == 'text/html'
16
- = form.article_editor :email_form_body, label: 'Body', mode: :email, value: (email_body unless errors)
17
- - else
18
- = form.text_area :email_form_body, label: 'Body', rows: 10, value: (email_body unless errors)
10
+ - # With errors
11
+ - if form.object.errors.present?
12
+ = form.select :email_form_from, mailer_froms_collection(), label: 'From'
13
+ = form.text_field :email_form_subject, label: 'Subject'
14
+
15
+ - if email_content_type == 'text/html'
16
+ = form.article_editor :email_form_body, label: 'Body', mode: :email
17
+ - else
18
+ = form.text_area :email_form_body, label: 'Body', rows: 10
19
+
20
+ - # With no errors
21
+ - if form.object.errors.blank?
22
+ = form.select :email_form_from, mailer_froms_collection(), label: 'From', value: email_from
23
+ = form.text_field :email_form_subject, label: 'Subject', value: email_subject
24
+
25
+ - if email_content_type == 'text/html'
26
+ = form.article_editor :email_form_body, label: 'Body', mode: :email, value: email_body
27
+ - else
28
+ = form.text_area :email_form_body, label: 'Body', rows: 10, value: email_body
19
29
 
20
30
  - if email_variables.present?
21
- %p The available variables are:
31
+ = card do
32
+ %p The available variables are:
22
33
 
23
- %ul
24
- - email_variables.each do |variable|
25
- %li {{ #{variable} }}
34
+ %ul
35
+ - email_variables.each do |variable|
36
+ %li {{ #{variable} }}
26
37
 
27
- %small.text-muted Please contact us to add additional variables
38
+ %small.text-muted Please contact us to add additional variables
@@ -0,0 +1,53 @@
1
+ - if email_template.present?
2
+ %p The following #{link_to(email_template, effective_email_templates.edit_admin_email_template_path(email_template), target: '_blank')} email will be sent:
3
+
4
+ = form.hidden_field :content_type, value: email_content_type
5
+
6
+ - uid = effective_bootstrap_unique_id
7
+ - expanded = form.object.cc.present? || form.object.bcc.present?
8
+
9
+ - if form.object.new_record? && form.object.errors.blank?
10
+ .row
11
+ .col-md-10
12
+ = form.select :from, mailer_froms_collection(), label: 'From', value: email_from
13
+ .col-md-2.my-4
14
+ %a{href: "#acts-as-email-notification-collapse-#{uid}", 'data-toggle': 'collapse', role: 'button', 'aria-expanded': expanded, 'aria-controls': "acts-as-email-notification-collapse-#{uid}"} more...
15
+
16
+ .collapse{id: "acts-as-email-notification-collapse-#{uid}", class: ('show' if expanded)}
17
+ = form.text_field :cc, label: 'CC', value: email_cc
18
+ = form.text_field :bcc, label: 'BCC', value: email_bcc
19
+
20
+ = form.text_field :subject, label: 'Subject', value: email_subject
21
+
22
+ - if email_content_type == 'text/html'
23
+ = form.article_editor :body, label: 'Body', mode: :email, value: email_body
24
+ - else
25
+ = form.text_area :body, label: 'Body', rows: 10, value: email_body
26
+
27
+ - else
28
+ .row
29
+ .col-md-10
30
+ = form.select :from, mailer_froms_collection(), label: 'From'
31
+ .col-md-2.my-4
32
+ %a{href: "#acts-as-email-notification-collapse-#{uid}", 'data-toggle': 'collapse', role: 'button', 'aria-expanded': expanded, 'aria-controls': "acts-as-email-notification-collapse-#{uid}"} more...
33
+
34
+ .collapse{id: "acts-as-email-notification-collapse-#{uid}", class: ('show' if expanded)}
35
+ = form.text_field :cc, label: 'CC'
36
+ = form.text_field :bcc, label: 'BCC'
37
+
38
+ = form.text_field :subject, label: 'Subject'
39
+
40
+ - if email_content_type == 'text/html'
41
+ = form.article_editor :body, label: 'Body', mode: :email
42
+ - else
43
+ = form.text_area :body, label: 'Body', rows: 10
44
+
45
+ - if email_variables.present?
46
+ = card do
47
+ %p The available variables are:
48
+
49
+ %ul
50
+ - email_variables.each do |variable|
51
+ %li {{ #{variable} }}
52
+
53
+ %small.text-muted Please contact us to add additional variables
@@ -24,6 +24,7 @@ module EffectiveResources
24
24
  app.config.to_prepare do
25
25
  ActiveRecord::Base.extend(ActsAsArchived::Base)
26
26
  ActiveRecord::Base.extend(ActsAsEmailForm::Base)
27
+ ActiveRecord::Base.extend(ActsAsEmailNotification::Base)
27
28
  ActiveRecord::Base.extend(ActsAsTokened::Base)
28
29
  ActiveRecord::Base.extend(ActsAsSlugged::Base)
29
30
  ActiveRecord::Base.extend(ActsAsStatused::Base)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.23.0'.freeze
2
+ VERSION = '2.24.0'.freeze
3
3
  end
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: 2.23.0
4
+ version: 2.24.0
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: 2024-06-20 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -194,13 +194,14 @@ files:
194
194
  - app/controllers/concerns/effective/wizard_controller/permitted_params.rb
195
195
  - app/controllers/concerns/effective/wizard_controller/save.rb
196
196
  - app/controllers/concerns/effective/wizard_controller/wicked_overrides.rb
197
- - app/helpers/effective_acts_as_email_form_helper.rb
197
+ - app/helpers/effective_resources_email_helper.rb
198
198
  - app/helpers/effective_resources_helper.rb
199
199
  - app/helpers/effective_resources_private_helper.rb
200
200
  - app/helpers/effective_resources_wizard_helper.rb
201
201
  - app/mailers/concerns/effective_mailer.rb
202
202
  - app/models/concerns/acts_as_archived.rb
203
203
  - app/models/concerns/acts_as_email_form.rb
204
+ - app/models/concerns/acts_as_email_notification.rb
204
205
  - app/models/concerns/acts_as_paginable.rb
205
206
  - app/models/concerns/acts_as_purchasable_wizard.rb
206
207
  - app/models/concerns/acts_as_slugged.rb
@@ -256,6 +257,7 @@ files:
256
257
  - app/views/application/show.js.erb
257
258
  - app/views/application/update.js.erb
258
259
  - app/views/effective/acts_as_email_form/_fields.html.haml
260
+ - app/views/effective/acts_as_email_notification/_fields.html.haml
259
261
  - app/views/effective/acts_as_wizard/_wizard_step.html.haml
260
262
  - app/views/effective/resource/_actions.html.haml
261
263
  - app/views/effective/resource/_actions_dropleft.html.haml