scrivito_crm_form_widget 0.1.3 → 0.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/styles/scrivito_crm_form_widget.css +3 -3
- data/app/models/crm_form_widget.rb +23 -2
- data/app/models/dynamic_attribute_widget.rb +23 -0
- data/app/presenter/crm_form_presenter.rb +40 -17
- data/app/views/crm_form_widget/_crm_enum.html.erb +1 -1
- data/app/views/crm_form_widget/_crm_multienum.html.erb +5 -5
- data/app/views/crm_form_widget/_crm_string.html.erb +1 -1
- data/app/views/crm_form_widget/_crm_text.html.erb +1 -1
- data/app/views/crm_form_widget/_dynamic_attributes.html.erb +5 -0
- data/app/views/crm_form_widget/_form.html.erb +13 -1
- data/app/views/crm_form_widget/details.html.erb +44 -40
- data/app/views/dynamic_attribute_widget/details.html.erb +26 -0
- data/lib/scrivito_crm_form_widget/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac77b44eb5e2e7bfee8460cac4971f710d86c81c
|
4
|
+
data.tar.gz: 84a9d7aef19eb87b54538347feacde41b58482b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e728681e8c89a0d3ac48699c567e8b413757e08107676fe13dd9086fab81be0b467d6ec6e354bd70a2cb9643454d845963c7b7704fe2c28fd70a4a2756983dfe
|
7
|
+
data.tar.gz: 782e84b8c0f4a0c92599db7cbe1b47732b6f14dcf8b8d79aee2eb6f119edcbe994e9c8fe7003ac577191d89b159fd6784478087346db0020ce8e8393b9c095c1
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
|
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
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
43
|
-
|
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="
|
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>
|
@@ -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
|
-
|
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
|
-
|
2
|
-
<
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
</
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
<%= scrivito_details_for 'Text on submitbutton' do %>
|
20
|
+
<%= scrivito_tag :div, widget, :submit_button_text %>
|
21
|
+
<% end %>
|
22
|
+
</div>
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
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 %>
|
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.
|
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:
|
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:
|
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:
|
145
|
+
version: 1.3.1
|
143
146
|
requirements: []
|
144
147
|
rubyforge_project:
|
145
148
|
rubygems_version: 2.4.5
|