scrivito_crm_form_widget 0.1.3 → 0.7.0.rc1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a43a0a25760b9265c7ccef43eba38980b5f20b1d
4
- data.tar.gz: 98eb6fb7a70cfc9f661611cbd105c064a7e855fa
3
+ metadata.gz: ac77b44eb5e2e7bfee8460cac4971f710d86c81c
4
+ data.tar.gz: 84a9d7aef19eb87b54538347feacde41b58482b1
5
5
  SHA512:
6
- metadata.gz: 3567cdf96cebe341f857db8e0069e184bd26f93f2197911cdd1f357c33fc3e737b1da2b2d72a936faa9d7019243edbd77bf486c9bd701feb1afb34c33238052e
7
- data.tar.gz: 6bf225abbefdaa9a864f1f14e197ea9efe40751d3c5f18b8a655db55321d4155f9cbc2bd00f4c6e02be8b942f728bfe6886856cc22ef38e3d6dd6e7391c2a880
6
+ metadata.gz: e728681e8c89a0d3ac48699c567e8b413757e08107676fe13dd9086fab81be0b467d6ec6e354bd70a2cb9643454d845963c7b7704fe2c28fd70a4a2756983dfe
7
+ data.tar.gz: 782e84b8c0f4a0c92599db7cbe1b47732b6f14dcf8b8d79aee2eb6f119edcbe994e9c8fe7003ac577191d89b159fd6784478087346db0020ce8e8393b9c095c1
@@ -1,3 +1,3 @@
1
- /*
2
- *= require scrivito_advanced_editors
3
- */
1
+ form .form-group.last {
2
+ display: none;
3
+ }
@@ -7,9 +7,14 @@ class CrmFormWidget < Widget
7
7
  attribute :tags, :string
8
8
  attribute :redirect_to, :reference
9
9
  attribute :submit_button_text, :string
10
+ attribute :dynamic_attributes, :widgetlist
11
+
12
+ def valid_widget_classes_for(field_name)
13
+ [DynamicAttributeWidget]
14
+ end
10
15
 
11
16
  def self.activities
12
- Obj.try(:crm_activity_filter) || Crm::Type.all.select {|i| i.item_base_type == "Activity"}
17
+ @activities ||= Obj.try(:crm_activity_filter) || Crm::Type.all.select {|i| i.item_base_type == "Activity"}
13
18
  end
14
19
 
15
20
  def attributes
@@ -29,6 +34,22 @@ class CrmFormWidget < Widget
29
34
  end
30
35
 
31
36
  def self.events
32
- Obj.try(:crm_activity_filter) || Crm::Event.all.to_a
37
+ @events ||= Obj.try(:crm_activity_filter) || Crm::Event.all.to_a
38
+ end
39
+
40
+ def self.event_ids
41
+ CrmFormWidget.events.map {|e| e.id}
42
+ end
43
+
44
+ def self.event_names
45
+ name_hash = {}
46
+ CrmFormWidget.events.each do |e|
47
+ name_hash[e.id] = e.title
48
+ end
49
+ return name_hash
50
+ end
51
+
52
+ def self.activity_ids
53
+ CrmFormWidget.activities.map {|a| a.id}
33
54
  end
34
55
  end
@@ -0,0 +1,23 @@
1
+ class DynamicAttributeWidget < Widget
2
+ attribute :title, :string
3
+ attribute :label, :string
4
+ attribute :type, :enum, values: ['string','text','enum','multienum'], default: 'string'
5
+ attribute :valid_values, :stringlist
6
+ attribute :maxlength, :string, default: 100
7
+
8
+ def self.valid_container_classes
9
+ [CrmFormWidget]
10
+ end
11
+
12
+ def options
13
+ {
14
+ 'valid_values' => valid_values,
15
+ 'maxlength' => maxlength
16
+ }
17
+ end
18
+
19
+ def field_name
20
+ field = title.parameterize('_')
21
+ return "dynamic_#{field}"
22
+ end
23
+ end
@@ -1,4 +1,5 @@
1
- class CrmFormPresenter < CrmFormAttributes
1
+ class CrmFormPresenter
2
+ include ActiveModel::Model
2
3
 
3
4
  def attribute_names
4
5
  @type.standard_attrs.keys + @type.custom_attrs.keys
@@ -11,37 +12,59 @@ class CrmFormPresenter < CrmFormAttributes
11
12
  @params = request.params["crm_form_presenter"]
12
13
 
13
14
  if request.post? && widget.id == @params[:widget_id]
14
- @params.delete("widget_id")
15
15
  redirect_after_submit(controller, widget, self.submit)
16
16
  end
17
17
  end
18
18
 
19
19
  def submit
20
- contact = nil
21
-
22
- if @params['custom_email'] && @params['custom_last_name']
23
- contact = manipulate_or_create_user
20
+ if @params['email'].present?
21
+ raise 'No human exeception'
22
+ else
23
+ @params.delete('email')
24
24
  end
25
+ prepare_contact(@params['custom_email'], @params['custom_last_name'])
26
+ prepare_activity_params
27
+ Crm::Activity.create(@params)
28
+ return {status: "success", message: "Your form was send successfully"}
29
+ rescue Crm::Errors::InvalidValues => e
30
+ return {status: "error", message: e.validation_errors}
31
+ end
25
32
 
26
- if contact
27
- set_params_for_activty(contact)
28
- add_contact_to_event(contact) if @widget.event_id.present?
29
- end
33
+ private
34
+ def prepare_activity_params
35
+ dynamic_params = set_dynamic_params
36
+ @params[:comment_notes] = dynamic_params if dynamic_params.present?
30
37
 
38
+ @params.delete("widget_id")
31
39
  @params["title"] = @params[:title].empty? ? @activity.id : @params[:title]
32
40
  @params["type_id"] = @activity.id
33
41
  @params["state"] = @activity.attributes['states'].first
42
+ end
34
43
 
35
- activity = Crm::Activity.create(@params)
44
+ def set_dynamic_params
45
+ dynamic_params = {};
46
+ @params.each do |key, value|
47
+ if key.starts_with? 'dynamic_'
48
+ dynamic_params[key] = value
49
+ @params.delete(key)
50
+ end
51
+ end
52
+ return dynamic_params
53
+ end
36
54
 
37
- return {status: "success", message: "Your form was send successfully"}
38
- rescue Crm::Errors::InvalidValues => e
39
- return {status: "error", message: e.validation_errors}
55
+
56
+ def prepare_contact(email, last_name)
57
+ if email && last_name
58
+ contact = manipulate_or_create_user(email, last_name)
59
+ if contact
60
+ set_params_for_activty(contact)
61
+ add_contact_to_event(contact) if @widget.event_id.present?
62
+ end
63
+ end
40
64
  end
41
65
 
42
- private
43
- def manipulate_or_create_user
44
- contact = Crm::Contact.where(:email, :equals, @params['custom_email']).and(:last_name, :equals, @params['custom_last_name']).first
66
+ def manipulate_or_create_user(email, last_name)
67
+ contact = Crm::Contact.where(:email, :equals, email).and(:last_name, :equals, last_name).first
45
68
  unless contact
46
69
  contact = Crm::Contact.create({
47
70
  first_name: @params['custom_first_name'],
@@ -1,5 +1,5 @@
1
1
  <div class="form-group">
2
- <%= form.label name.to_sym, class: "control-label col-sm-3 #{options[:mandatory] ? 'mandatory' : ''}" %>
2
+ <%= form.label name.to_sym, label, class: "control-label col-sm-3 #{options[:mandatory] ? 'mandatory' : ''}" %>
3
3
  <div class="col-sm-9">
4
4
  <% options['valid_values'].each do |value| %>
5
5
  <div class="radio">
@@ -1,13 +1,13 @@
1
1
  <div class="form-group">
2
- <%= form.label name.to_sym, class: "control-label col-sm-3 #{options[:mandatory] ? 'mandatory' : ''}" %>
2
+ <%= form.label name.to_sym, label, class: "control-label col-sm-3 #{options[:mandatory] ? 'mandatory' : ''}" %>
3
3
  <div class="col-sm-9">
4
4
  <% options['valid_values'].each do |value| %>
5
- <div class="^checkbox">
5
+ <div class="checkbox">
6
6
  <%= form.label "#{name}_#{value.downcase}" do %>
7
- <%= form.check_box name.to_sym, value %>
8
- <%= t("helpers.label.crm_form_presenter.#{name}_option.#{value.downcase}") %>
7
+ <%= form.check_box name.to_sym, {:multiple => true, id: "crm_form_presenter_#{name}_#{value.downcase}"}, value, nil %>
8
+ <%= t("helpers.label.crm_form_presenter.#{name}_option.#{value.downcase}", default: value) %>
9
9
  <% end %>
10
10
  </div>
11
11
  <% end %>
12
12
  </div>
13
- </div>
13
+ </div>
@@ -1,5 +1,5 @@
1
1
  <div class="form-group">
2
- <%= form.label name.to_sym, class: "control-label col-sm-3 #{options[:mandatory] ? 'mandatory' : ''}" %>
2
+ <%= form.label name.to_sym, label, class: "control-label col-sm-3 #{options[:mandatory] ? 'mandatory' : ''}" %>
3
3
  <div class="col-sm-9">
4
4
  <%= form.text_field name.to_sym, class: "form-control", maxlength: options[:maxlength] %>
5
5
  </div>
@@ -1,5 +1,5 @@
1
1
  <div class="form-group">
2
- <%= form.label name.to_sym, class: "control-label col-sm-3 #{options[:mandatory] ? 'mandatory' : ''}" %>
2
+ <%= form.label name.to_sym, label, class: "control-label col-sm-3 #{options[:mandatory] ? 'mandatory' : ''}" %>
3
3
  <div class="col-sm-9">
4
4
  <%= form.text_area name.to_sym, class: "form-control", maxlength: options[:maxlength] %>
5
5
  </div>
@@ -0,0 +1,5 @@
1
+ <% attributes.each do |attribute| %>
2
+ <% name, type = attribute.split(':') %>
3
+ <%= name %>
4
+ <%= type %>
5
+ <% end %>
@@ -6,9 +6,21 @@
6
6
  <%= form.hidden_field(:widget_id, value: widget.id) %>
7
7
 
8
8
  <% widget.attributes.each do |name, options| %>
9
- <%= render "crm_form_widget/crm_#{options["attribute_type"]}", form: form, name: name, options: options %>
9
+ <% CrmFormPresenter.send(:attr_accessor, name.to_sym) %>
10
+ <%= render "crm_form_widget/crm_#{options["attribute_type"]}", form: form, name: name, options: options, label: nil %>
10
11
  <% end %>
11
12
 
13
+ <% widget.dynamic_attributes.each do |attribute| %>
14
+ <% CrmFormPresenter.send(:attr_accessor, attribute.field_name.to_sym) %>
15
+ <%= render "crm_form_widget/crm_#{attribute.type}", form: form, name: attribute.field_name, options: attribute.options || {}, label: attribute.label %>
16
+ <% end %>
17
+
18
+ <div class="form-group last">
19
+ <label class="control-label col-sm-3" for="crm_form_presenter_email">Email</label>
20
+ <div class="col-sm-9">
21
+ <input class="form-control" type="text" name="crm_form_presenter[email]" id="crm_form_presenter_email">
22
+ </div>
23
+ </div>
12
24
  <%= form.submit widget.submit_button, class: "btn btn-primary pull-right" %>
13
25
 
14
26
  <% end %>
@@ -1,47 +1,51 @@
1
- <ul class="tab-list">
2
- <li class="active" data-panel-target="#edit-general">General</li>
3
- <li data-panel-target="#edit-tags">Tags</li>
4
- <li data-panel-target="#edit-activity">Activity</li>
5
- <li data-panel-target="#edit-event">Event</li>
6
- </ul>
1
+ <%= scrivito_large_dialog do %>
2
+ <ul class="tab-list">
3
+ <li class="active" data-panel-target="#edit-general">General</li>
4
+ <li data-panel-target="#edit-tags">Tags</li>
5
+ <li data-panel-target="#edit-activity">Activity</li>
6
+ <li data-panel-target="#edit-event">Event</li>
7
+ <li data-panel-target="#edit-dynamic">Add fields</li>
8
+ </ul>
7
9
 
8
- <div class="tab-panels">
9
- <div class="tab-panel" id="edit-general">
10
- <%= scrivito_details_for 'Subject' do %>
11
- <%= scrivito_tag :div, widget, :subject %>
12
- <% end %>
13
- <%= scrivito_details_for 'Redirect after submit' do %>
14
- <%= scrivito_tag :div, widget, :redirect_to %>
15
- <% end %>
10
+ <div class="tab-panels">
11
+ <div class="tab-panel" id="edit-general">
12
+ <%= scrivito_details_for 'Subject' do %>
13
+ <%= scrivito_tag :div, widget, :subject %>
14
+ <% end %>
15
+ <%= scrivito_details_for 'Redirect after submit' do %>
16
+ <%= scrivito_tag :div, widget, :redirect_to %>
17
+ <% end %>
16
18
 
17
- <%= scrivito_details_for 'Text on submitbutton' do %>
18
- <%= scrivito_tag :div, widget, :submit_button_text %>
19
- <% end %>
20
- </div>
19
+ <%= scrivito_details_for 'Text on submitbutton' do %>
20
+ <%= scrivito_tag :div, widget, :submit_button_text %>
21
+ <% end %>
22
+ </div>
21
23
 
22
- <div class="tab-panel" id="edit-tags">
23
- <%= scrivito_details_for 'Tags for Contact' do %>
24
- <div class="alert alert-info">
25
- optional attribute. can be used to add tags to a contact like has_visited_event. contatc will be calculated by the custom attributes email and last_name of your selected activtiy. If this fields do not exist, this field has no effect.
26
- </div>
27
- <%= scrivito_tag :div, widget, :tags, data: {editor: 'scrivito-list-editor'} %>
28
- <% end %>
29
- </div>
24
+ <div class="tab-panel" id="edit-tags">
25
+ <%= scrivito_details_for 'Tags for Contact' do %>
26
+ <%= scrivito_tag :div, widget, :tags, data: {editor: 'scrivito-list-editor'} %>
27
+ <% end %>
28
+ <%= scrivito_colapsable_for 'What is this for?', 'help small mark' do %>
29
+ Optional attribute. Can be used to add tags to a contact like has_visited_event. Contatc will be calculated by the custom attributes email and last_name of your selected activtiy. If one of this fields at the crm activity do not exist, this attribute has no effect.
30
+ <% end %>
31
+ </div>
30
32
 
31
- <div class="tab-panel" id="edit-activity">
32
- <%= scrivito_details_for 'Activity' do %>
33
- <%= scrivito_toggle_button_editor widget, :activity_id, CrmFormWidget.activities.map { |a| a.id } %>
34
- <% end %>
35
- </div>
33
+ <div class="tab-panel" id="edit-activity">
34
+ <%= scrivito_details_for 'Activity' do %>
35
+ <%= scrivito_tag(:div, widget, :activity_id, data: {toggle_button_list: CrmFormWidget.activity_ids}) %>
36
+ <% end %>
37
+ </div>
36
38
 
37
- <div class="tab-panel" id="edit-event">
38
- <%= scrivito_details_for 'Event' do %>
39
- <%- scrivito_toggle_button_editor(widget, :event_id, CrmFormWidget.events) do |event| %>
40
- <%= scrivito_tag(:button, widget, :event_id, data: {editor: 'scrivito-toggle-button', content: event.id}) do %>
41
- <%= event.title %>
42
- <% end %>
39
+ <div class="tab-panel" id="edit-event">
40
+ <%= scrivito_details_for 'Event' do %>
41
+ <%= scrivito_tag(:div, widget, :event_id, data: {
42
+ toggle_button_list: CrmFormWidget.event_ids,
43
+ toggle_button_caption: CrmFormWidget.event_names }) %>
43
44
  <% end %>
44
- <% end %>
45
- </div>
46
- </div>
45
+ </div>
47
46
 
47
+ <div class="tab-panel" id="edit-dynamic">
48
+ <%= scrivito_tag :div, widget, :dynamic_attributes %>
49
+ </div>
50
+ </div>
51
+ <% end %>
@@ -0,0 +1,26 @@
1
+ <%= scrivito_colapsable_for 'Attribute' do %>
2
+ <%= scrivito_details_for do %>
3
+ <h4>Type</h4>
4
+ <%= scrivito_tag :div, widget, :type %>
5
+ <% end %>
6
+
7
+ <%= scrivito_details_for do %>
8
+ <h4>Label</h4>
9
+ <%= scrivito_tag :div, widget, :label %>
10
+ <% end %>
11
+
12
+ <%= scrivito_details_for do %>
13
+ <h4>Title</h4>
14
+ <%= scrivito_tag :div, widget, :title %>
15
+ <% end %>
16
+
17
+ <%= scrivito_details_for do %>
18
+ <h4>Maxlength</h4>
19
+ <%= scrivito_tag :div, widget, :maxlength %>
20
+ <% end %>
21
+
22
+ <%= scrivito_details_for do %>
23
+ <h4>Values <small>Mandatory for type enum or multienum</small></h4>
24
+ <%= scrivito_tag :div, widget, :valid_values %>
25
+ <% end %>
26
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module ScrivitoCrmFormWidget
2
- VERSION = "0.1.3"
2
+ VERSION = "0.7.0.rc1"
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: 0.1.3
4
+ version: 0.7.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scrivito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-28 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: scrivito_sdk
28
+ name: scrivito
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -108,15 +108,18 @@ files:
108
108
  - app/assets/styles/scrivito_crm_form_widget.css
109
109
  - app/controllers/scrivito_crm_form_widget/application_controller.rb
110
110
  - app/models/crm_form_widget.rb
111
+ - app/models/dynamic_attribute_widget.rb
111
112
  - app/presenter/crm_form_presenter.rb
112
113
  - app/views/crm_form_widget/_crm_enum.html.erb
113
114
  - app/views/crm_form_widget/_crm_multienum.html.erb
114
115
  - app/views/crm_form_widget/_crm_string.html.erb
115
116
  - app/views/crm_form_widget/_crm_text.html.erb
117
+ - app/views/crm_form_widget/_dynamic_attributes.html.erb
116
118
  - app/views/crm_form_widget/_form.html.erb
117
119
  - app/views/crm_form_widget/details.html.erb
118
120
  - app/views/crm_form_widget/show.html.erb
119
121
  - app/views/crm_form_widget/thumbnail.html.erb
122
+ - app/views/dynamic_attribute_widget/details.html.erb
120
123
  - lib/scrivito_crm_form_widget.rb
121
124
  - lib/scrivito_crm_form_widget/engine.rb
122
125
  - lib/scrivito_crm_form_widget/version.rb
@@ -137,9 +140,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
140
  version: '0'
138
141
  required_rubygems_version: !ruby/object:Gem::Requirement
139
142
  requirements:
140
- - - ">="
143
+ - - ">"
141
144
  - !ruby/object:Gem::Version
142
- version: '0'
145
+ version: 1.3.1
143
146
  requirements: []
144
147
  rubyforge_project:
145
148
  rubygems_version: 2.4.5