scrivito_crm_form_widget 1.0.0.beta4 → 1.0.0.beta5

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: 837f3a977ac51d6bd0604980465ca6cca0a98db2
4
- data.tar.gz: b530390126b9be97bfa286b6da57e09d4d0b98d5
3
+ metadata.gz: 2e9119d84829ac864fb0e9331e35adea866aa494
4
+ data.tar.gz: 3793bae1eb8586dcb894424677918245801425d1
5
5
  SHA512:
6
- metadata.gz: bbd9937102083a39fbfe6586730ef4e75d64144875dbf001fc2dae922ce1d99988504eb912fdfe27e8ad7ff8e3955b82e7c24ddb1007ba92f3c558c61d3568d4
7
- data.tar.gz: c1b120d9957f2a8210fed86f9e758326c1a76e4513fcfa4b20316ba62d3dd42014e8c40deeb6b91e9218fe61ab97fb05a5aecd2b210e029e86681d443212ceec
6
+ metadata.gz: 6f69d0e62578a3db7e78733f58b6bb10e13dec47800e965bb0314f380515eb6bbbd0b07a76965e37740b4285ad22ffc4e88f7cb1478781d0a50a0926b1b0a1ab
7
+ data.tar.gz: f10fc0046f257339970c36d03cbf3d3a5cda8fb2e52b990bf7ae42e14416596492e34a7851938193738f8e657452021acc240a6b8a93d9ec7d22f34372986390
@@ -1,3 +1,6 @@
1
+ //= require scrivito_advanced_editors
2
+ //= require_self
3
+
1
4
  form .form-group.last {
2
5
  display: none;
3
6
  }
@@ -19,7 +22,8 @@ form.form-horizontal.label-position-top {
19
22
  .form-group {
20
23
  width: 50%;
21
24
  float: left;
22
- margin: 0;
25
+ margin-left: 0;
26
+ margin-right: 0;
23
27
  }
24
28
 
25
29
  .form-submit-button-container {
@@ -28,7 +32,7 @@ form.form-horizontal.label-position-top {
28
32
 
29
33
  .btn {
30
34
  margin-right: 15px;
31
- margin-top: 15px;
35
+ margin-top: 0;
32
36
  }
33
37
  }
34
38
  }
@@ -37,11 +37,19 @@ class CrmFormWidget < Widget
37
37
  end
38
38
 
39
39
  def attributes
40
- activity.attribute_definitions
40
+ @attributes ||= activity.attribute_definitions
41
41
  end
42
42
 
43
43
  def activity
44
- Crm::Type.find(activity_id)
44
+ @activity ||= Crm::Type.find(activity_id)
45
+ end
46
+
47
+ def validate(params)
48
+ errors = []
49
+ attributes.each do |name, options|
50
+ errors << {attribute: name, message: "Attribute #{name} can not be blank.", code: 'blank'} if options[:mandatory] && !params[name].present?
51
+ end
52
+ errors
45
53
  end
46
54
 
47
55
  def activity_id?
@@ -12,10 +12,10 @@ class CrmFormPresenter
12
12
  @params = request.params["crm_form_presenter"]
13
13
  @dynamic_params = set_dynamic_params
14
14
  @access_code = generate_random_string(12)
15
- errors = validate_params
15
+ errors = (request.post? || !@params.nil?) ? validate_params : nil
16
16
 
17
17
  if errors.present?
18
- return {status: "error", message: errors}
18
+ controller.redirect_to("/#{@page.id}", alert: { status: "error", message: errors, widget_id: @widget.id })
19
19
  elsif request.post? && widget.id == @params[:widget_id]
20
20
  request.session['access_via_form'] = @access_code
21
21
  redirect_after_submit(controller, widget, self.submit)
@@ -28,10 +28,12 @@ class CrmFormPresenter
28
28
  else
29
29
  @params.delete('email')
30
30
  end
31
- @params.delete('access_via_form')
32
31
 
33
32
  prepare_contact(@params['custom_email'], @params['custom_last_name'])
34
33
  prepare_activity_params
34
+
35
+ Obj.crm_form_before_send_hook(@params, @activity) if Obj.respond_to?('before_send_hook')
36
+
35
37
  Crm::Activity.create(@params)
36
38
  return {status: "success", message: "Your form was send successfully"}
37
39
  rescue Crm::Errors::InvalidValues => e
@@ -47,6 +49,7 @@ class CrmFormPresenter
47
49
  @params.delete(:custom_file)
48
50
  end
49
51
 
52
+ @params.delete('access_via_form')
50
53
  @params.delete("widget_id")
51
54
  @params["title"] = @params[:title].empty? ? @activity.id : @params[:title]
52
55
  @params["type_id"] = @activity.id
@@ -125,17 +128,18 @@ class CrmFormPresenter
125
128
 
126
129
  def redirect_after_submit(controller, widget, submit_message)
127
130
  if submit_message[:status] == "success"
128
- controller.redirect_to(redirect_path(@page, widget), notice: submit_message[:message])
131
+ controller.redirect_to(redirect_path(@page, widget), notice: [submit_message[:message]])
129
132
  elsif submit_message[:status] == "error"
130
- controller.redirect_to("/#{@page.id}", alert: submit_message[:message])
133
+ controller.redirect_to("/#{@page.id}", alert: [submit_message[:message]])
131
134
  end
132
135
  end
133
136
 
134
137
  def validate_params
135
- return false if @params.nil?
136
- email = valid_email?(@params['custom_email'])
137
- hook = Obj.respond_to?('crm_form_validation') ? Obj.crm_form_validation(@params) : false
138
- !email || hook
138
+ email = valid_email?(@params['custom_email']) ? [] : [{attribute: 'custom_email', message: 'The email is not a valid email address.', code: 'email'}]
139
+ hook = Obj.respond_to?('crm_form_validation_hook') ? Obj.crm_form_validation_hook(@params, @widget) : []
140
+ crm = @widget.validate(@params)
141
+
142
+ email + hook + crm
139
143
  end
140
144
 
141
145
  def valid_email?(email)
@@ -0,0 +1,12 @@
1
+ <div class="alert-danger crm-form-message alert">
2
+ <ul>
3
+ <% flash['alert']['message'].each do |msg| %>
4
+ <li>
5
+ <%= t("helpers.messages.crm_form_presenter.#{msg['code']}",
6
+ field: t("helpers.label.crm_form_presenter.#{msg['attribute']}", default: msg['attribute']),
7
+ default: msg['message']).html_safe
8
+ %>
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ </div>
@@ -1,8 +1,16 @@
1
1
  <% if widget.activity_id? %>
2
+ <% if(flash[:alert] && ScrivitoCrmFormWidget.configuration.show_error_message && (flash[:alert]['widget_id'] == widget.id)) %>
3
+ <%= render 'crm_form_widget/error_messages' %>
4
+ <% end %>
5
+ <% if flash[:notice] && ScrivitoCrmFormWidget.configuration.show_error_message %>
6
+ <div class="alert-success crm-form-message alert">
7
+ <%= t('helpers.messages.crm_form_presenter.success', default: 'Thank you for your message.').html_safe %>
8
+ </div>
9
+ <% end %>
2
10
  <%= render 'crm_form_widget/form', widget: widget %>
3
11
  <% else %>
4
12
  <div class="alert alert-warning">
5
13
  <p><strong>Select an activty</strong></p>
6
14
  <%= scrivito_tag(:div, widget, :activity_id, data: {toggle_button_list: CrmFormWidget.activity_ids, scrivito_editors_reload: true }) %>
7
15
  </div>
8
- <% end %>
16
+ <% end %>
@@ -1,9 +1,11 @@
1
1
  module ScrivitoCrmFormWidget
2
2
  class Configuration
3
3
  attr_accessor :hidden_attributes
4
+ attr_accessor :show_error_message
4
5
 
5
6
  def initialize
6
7
  @hidden_attributes = ['origin','referrer','tracking','service']
8
+ @show_error_message = true
7
9
  end
8
10
  end
9
11
  end
@@ -1,3 +1,3 @@
1
1
  module ScrivitoCrmFormWidget
2
- VERSION = "1.0.0.beta4"
2
+ VERSION = "1.0.0.beta5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrivito_crm_form_widget
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta4
4
+ version: 1.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scrivito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-26 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scrivito
@@ -90,6 +90,7 @@ files:
90
90
  - app/views/crm_form_widget/_crm_string.html.erb
91
91
  - app/views/crm_form_widget/_crm_text.html.erb
92
92
  - app/views/crm_form_widget/_dynamic_attributes.html.erb
93
+ - app/views/crm_form_widget/_error_messages.html.erb
93
94
  - app/views/crm_form_widget/_file_upload.html.erb
94
95
  - app/views/crm_form_widget/_form.html.erb
95
96
  - app/views/crm_form_widget/details.html.erb