scrivito_jr_form_widget 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +4 -0
- data/Rakefile +21 -0
- data/app/assets/images/form.png +0 -0
- data/app/controllers/scrivito_jr_form_widget/application_controller.rb +4 -0
- data/app/models/jr_form_widget.rb +23 -0
- data/app/presenter/jr_form_presenter.rb +73 -0
- data/app/views/jr_form_widget/_form.html.erb +12 -0
- data/app/views/jr_form_widget/_jr_enum.html.erb +0 -0
- data/app/views/jr_form_widget/_jr_multienum.ht.erb +0 -0
- data/app/views/jr_form_widget/_jr_string.html.erb +6 -0
- data/app/views/jr_form_widget/_jr_text.html.erb +6 -0
- data/app/views/jr_form_widget/details.html.erb +29 -0
- data/app/views/jr_form_widget/show.html.erb +7 -0
- data/app/views/jr_form_widget/thumbnail.html.erb +11 -0
- data/lib/scrivito_jr_form_widget/engine.rb +5 -0
- data/lib/scrivito_jr_form_widget/version.rb +3 -0
- data/lib/scrivito_jr_form_widget.rb +4 -0
- data/lib/tasks/scrivito_jr_form_widget_tasks.rake +4 -0
- data/scrivito/migrate/0_create_jr_form_widget.rb +16 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a06ab0c567c8525acc231eb17ae755f775def41
|
4
|
+
data.tar.gz: b33289c2c441f0044f7343d05a869142210e5f49
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1ba1876ca4b22b7a6fb2a8f7b61c35f4873c29d966f8659a768e8c6ce30fff520ef005c5164d618d2add65b70a6008055339e39f96686db69bd9a3811c04c5b
|
7
|
+
data.tar.gz: a7d2555d5d60baae5cb83305b4b006f5c52778523d0cdf71f3df09f9e9903399e29dc72dfd212d500d877166ba5b0972ea362ca932433b8af663c0d6b273b3dc
|
data/LICENSE
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'ScrivitoJrFormWidget'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class JrFormWidget < Widget
|
2
|
+
include JustRelate
|
3
|
+
|
4
|
+
def self.activities
|
5
|
+
Obj.try(:jr_activity_filter) || JustRelate::Type.all.to_a
|
6
|
+
end
|
7
|
+
|
8
|
+
def attributes
|
9
|
+
activity.attribute_definitions
|
10
|
+
end
|
11
|
+
|
12
|
+
def activity
|
13
|
+
JustRelate::Type.find(activity_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def activity_id?
|
17
|
+
self.activity_id != ""
|
18
|
+
end
|
19
|
+
|
20
|
+
def submit_button
|
21
|
+
submit_button_text.present? ? submit_button_text : "send"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class JrFormPresenter < JrFormAttributes
|
2
|
+
def initialize(widget, request, controller)
|
3
|
+
@widget = widget
|
4
|
+
@activity = widget.activity
|
5
|
+
@page = widget.obj
|
6
|
+
@params = request.params["jr_form_presenter"]
|
7
|
+
|
8
|
+
if request.post?
|
9
|
+
redirect_after_submit(controller, widget, self.submit)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def submit
|
14
|
+
contact = manipulate_or_create_user
|
15
|
+
|
16
|
+
set_params_for_activty(contact)
|
17
|
+
|
18
|
+
activity = JustRelate::Activity.create(@params)
|
19
|
+
|
20
|
+
return {status: "success", message: "Your form was send successfully"}
|
21
|
+
rescue JustRelate::Errors::InvalidValues => e
|
22
|
+
return {status: "error", message: e.validation_errors}
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def manipulate_or_create_user
|
27
|
+
contact = JustRelate::Contact.where(:email, :equals, @params['custom_email']).and(:last_name, :equals, @params['custom_last_name']).first
|
28
|
+
unless contact
|
29
|
+
contact = JustRelate::Contact.create({
|
30
|
+
first_name: @params['custom_first_name'],
|
31
|
+
last_name: @params['custom_last_name'],
|
32
|
+
email: @params['custom_email'],
|
33
|
+
language: 'de'
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
add_tags_to(contact)
|
38
|
+
|
39
|
+
return contact
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_tags_to(contact)
|
43
|
+
tags = contact.tags + @widget.tags.split("|")
|
44
|
+
contact.update({tags: tags})
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_params_for_activty(contact)
|
48
|
+
if @params["title"] == ""
|
49
|
+
@params["title"] = @activity.id
|
50
|
+
end
|
51
|
+
|
52
|
+
@params["contact_ids"] = contact.id
|
53
|
+
@params["type_id"] = @activity.id
|
54
|
+
@params["state"] = 'created'
|
55
|
+
end
|
56
|
+
|
57
|
+
def redirect_path(page, widget)
|
58
|
+
obj = redirect_obj(page, widget)
|
59
|
+
obj.binary? ? obj.try(:binary_url) : "/#{obj.id}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def redirect_obj(page, widget)
|
63
|
+
(widget.respond_to?('redirect_to') && widget.redirect_to.present?) ? widget.redirect_to : page
|
64
|
+
end
|
65
|
+
|
66
|
+
def redirect_after_submit(controller, widget, submit_message)
|
67
|
+
if submit_message[:status] == "success"
|
68
|
+
controller.redirect_to(redirect_path(@page, widget), notice: submit_message[:message])
|
69
|
+
elsif submit_message[:status] == "error"
|
70
|
+
controller.redirect_to("/#{@page.id}", alert: submit_message[:message])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%= form_for JrFormPresenter.new(widget, request, controller), url: scrivito_path(widget.obj), html: { class: "form-horizontal"} do |form| %>
|
2
|
+
<% if widget.subject %>
|
3
|
+
<%= form.hidden_field(:title, value: widget.subject) %>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<% widget.attributes.each do |name, options| %>
|
7
|
+
<%= render "jr_form_widget/jr_#{options["attribute_type"]}", form: form, name: name, options: options %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<%= form.submit widget.submit_button, class: "btn btn-primary pull-right" %>
|
11
|
+
|
12
|
+
<% end %>
|
File without changes
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<div class="details-view">
|
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
|
+
</ul>
|
7
|
+
|
8
|
+
<div class="tab-panels">
|
9
|
+
<div class="tab-panel" id="edit-general">
|
10
|
+
<h4>Subject</h4>
|
11
|
+
<%= scrivito_tag :div, widget, :subject %>
|
12
|
+
<h4>Redirect after submit</h4>
|
13
|
+
<%= scrivito_tag :div, widget, :redirect_to %>
|
14
|
+
|
15
|
+
<h4>Text on submitbutton</h4>
|
16
|
+
<%= scrivito_tag :div, widget, :submit_button_text %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="tab-panel" id="edit-tags">
|
20
|
+
<h4>Tags <abbr title="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." class="initialism"></abbr></h4>
|
21
|
+
<%= scrivito_tag :div, widget, :tags, data: {editor: 'scrivito-list-editor'} %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="tab-panel" id="edit-activity">
|
25
|
+
<h4>Activity</h4>
|
26
|
+
<%= scrivito_toggle_button_editor widget, :activity_id, JrFormWidget.activities.map { |a| a.id } %>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="scrivito_editing_widget_visualization">
|
2
|
+
<%= image_tag("form.png") %>
|
3
|
+
</div>
|
4
|
+
|
5
|
+
<div class="scrivito_editing_widget_title">
|
6
|
+
Just Relate Form Widget
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="scrivito_editing_widget_description">
|
10
|
+
Add a formular to your page based on an activty from just relate CRM.
|
11
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateJrFormWidget < ::Scrivito::Migration
|
2
|
+
def up
|
3
|
+
Scrivito::ObjClass.create(
|
4
|
+
name: 'JrFormWidget',
|
5
|
+
type: 'publication',
|
6
|
+
title: 'Just Relate Fromular Widget',
|
7
|
+
attributes: [
|
8
|
+
{name: "activity_id", type: "string"},
|
9
|
+
{name: "subject", type: "string"},
|
10
|
+
{name: "tags", type: "string"},
|
11
|
+
{name: "redirect_to", type: "reference"},
|
12
|
+
{name: "submit_button_text", type: "string"}
|
13
|
+
]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scrivito_jr_form_widget
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scrivito
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: scrivito_sdk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: scrivito_advanced_editors
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A widget for Scrivito to show a form using just relate api.
|
70
|
+
email:
|
71
|
+
- support@scrivito.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE
|
77
|
+
- Rakefile
|
78
|
+
- app/assets/images/form.png
|
79
|
+
- app/controllers/scrivito_jr_form_widget/application_controller.rb
|
80
|
+
- app/models/jr_form_widget.rb
|
81
|
+
- app/presenter/jr_form_presenter.rb
|
82
|
+
- app/views/jr_form_widget/_form.html.erb
|
83
|
+
- app/views/jr_form_widget/_jr_enum.html.erb
|
84
|
+
- app/views/jr_form_widget/_jr_multienum.ht.erb
|
85
|
+
- app/views/jr_form_widget/_jr_string.html.erb
|
86
|
+
- app/views/jr_form_widget/_jr_text.html.erb
|
87
|
+
- app/views/jr_form_widget/details.html.erb
|
88
|
+
- app/views/jr_form_widget/show.html.erb
|
89
|
+
- app/views/jr_form_widget/thumbnail.html.erb
|
90
|
+
- lib/scrivito_jr_form_widget.rb
|
91
|
+
- lib/scrivito_jr_form_widget/engine.rb
|
92
|
+
- lib/scrivito_jr_form_widget/version.rb
|
93
|
+
- lib/tasks/scrivito_jr_form_widget_tasks.rake
|
94
|
+
- scrivito/migrate/0_create_jr_form_widget.rb
|
95
|
+
homepage: https://www.scrivito.com
|
96
|
+
licenses:
|
97
|
+
- LGPL-3.0
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.2.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: A widget for Scrivito to show a form using just relate api.
|
119
|
+
test_files: []
|