ffcrm_cloudfuji 0.2.11 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/app/assets/javascripts/event_rules.js.coffee +5 -0
- data/app/assets/stylesheets/event_rules.css.scss +6 -1
- data/app/helpers/admin/event_rules_helper.rb +7 -5
- data/app/models/event_rule.rb +44 -15
- data/app/views/admin/event_rules/_form.html.haml +23 -7
- data/db/migrate/20120607115701_add_mailing_list_and_page_fields_to_event_rules.rb +14 -0
- data/lib/fat_free_crm/cloudfuji/event_observers/event_rules_observer.rb +2 -2
- data/lib/ffcrm_cloudfuji/version.rb +1 -1
- metadata +5 -4
data/README
CHANGED
@@ -48,6 +48,11 @@
|
|
48
48
|
$('.event_category_select').live "change", ->
|
49
49
|
event_rules.show_field_group this, 'event_category', $(this).val()
|
50
50
|
|
51
|
+
# Set 'cloudfuji_event' to 'page_loaded' if event category is page_loaded.
|
52
|
+
if $(this).val() == "page_loaded"
|
53
|
+
index = $(this).closest('li.event_rule').data('index')
|
54
|
+
$("#event_rules_#{index}_cloudfuji_event").val('page_loaded')
|
55
|
+
|
51
56
|
$('.action_select').live "change", ->
|
52
57
|
event_rules.show_field_group this, 'action', $(this).val()
|
53
58
|
|
@@ -14,10 +14,15 @@ ul#event_rules {
|
|
14
14
|
vertical-align: middle;
|
15
15
|
margin-bottom: 3px;
|
16
16
|
}
|
17
|
-
.
|
17
|
+
.cloudfuji_event_input { width: 120px; }
|
18
|
+
.page_name_input { width: 120px; }
|
19
|
+
.app_id_input { width: 110px; }
|
18
20
|
.match_input { width: 140px; }
|
19
21
|
.numeric_input { width: 35px; }
|
20
22
|
.tag_input { width: 100px; }
|
23
|
+
.mailing_list_input { width: 100px; }
|
24
|
+
.mailing_list_group_input { width: 100px; }
|
25
|
+
.mailing_list_grouping_input { width: 120px; }
|
21
26
|
input[type='checkbox'] {
|
22
27
|
width: 14px;
|
23
28
|
margin-left: 2px;
|
@@ -10,16 +10,18 @@ module Admin::EventRulesHelper
|
|
10
10
|
def event_category_select(form)
|
11
11
|
form.select :event_category, [
|
12
12
|
["Cloudfuji event", :cloudfuji_event_received],
|
13
|
-
["
|
13
|
+
["Page loaded", :page_loaded],
|
14
|
+
["Lead attribute", :lead_attribute_changed]
|
14
15
|
], {}, :class => "event_category_select"
|
15
16
|
end
|
16
17
|
|
17
18
|
def action_select(form)
|
18
19
|
form.select :action, [
|
19
|
-
["change Lead score",
|
20
|
-
["send notification",
|
21
|
-
["add tag",
|
22
|
-
["remove tag",
|
20
|
+
["change Lead score", :change_lead_score],
|
21
|
+
["send notification", :send_notification],
|
22
|
+
["add tag", :add_tag],
|
23
|
+
["remove tag", :remove_tag],
|
24
|
+
["add to mailing group", :add_to_mailing_list_group]
|
23
25
|
], {}, :class => "action_select"
|
24
26
|
end
|
25
27
|
|
data/app/models/event_rule.rb
CHANGED
@@ -2,34 +2,39 @@ class EventRule < ActiveRecord::Base
|
|
2
2
|
|
3
3
|
# event category validations
|
4
4
|
validates_presence_of :event_category
|
5
|
-
validates_presence_of :
|
6
|
-
validates_presence_of :
|
5
|
+
validates_presence_of :lead_attribute, :if => lambda { self.event_category == 'lead_attribute_changed' }
|
6
|
+
validates_presence_of :cloudfuji_event, :if => lambda { self.event_category == 'cloudfuji_event_received' }
|
7
|
+
validates_presence_of :page_name, :app_id, :if => lambda { self.cloudfuji_event == 'page_loaded' }
|
7
8
|
|
8
9
|
# action validations
|
9
10
|
validates_presence_of :action
|
10
11
|
validates_presence_of :tag, :if => lambda { %w(add_tag remove_tag).include?(self.action) }
|
12
|
+
validates_presence_of :mailing_list, :mailing_list_group, :mailing_list_grouping, :if => lambda { self.action == "add_to_mailing_list_group" }
|
13
|
+
|
11
14
|
validates_numericality_of :change_score_by, :only_integer => true, :if => lambda { self.action == 'change_lead_score' }
|
12
15
|
|
13
16
|
validates_numericality_of :limit_per_lead, :only_integer => true, :allow_blank => true
|
14
17
|
|
15
18
|
has_many :lead_event_rule_counts
|
16
19
|
|
17
|
-
def process(lead,
|
20
|
+
def process(lead, params = {})
|
18
21
|
# How many times this rule has been applied to a given Lead
|
19
22
|
count = LeadEventRuleCount.find_by_lead_id_and_event_rule_id(lead, self) ||
|
20
23
|
LeadEventRuleCount.new(:lead => lead, :event_rule => self)
|
21
24
|
# Don't apply this rule more than limit_per_lead, if set
|
22
25
|
unless limit_per_lead.present? && count.count > limit_per_lead
|
23
26
|
# If :match is present, only apply the rule if data matches string
|
24
|
-
if match.blank? || event_matches?(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
if match.blank? || (params['data'] && event_matches?(params))
|
28
|
+
if (app_id.blank? && page.blank?) || page_and_app_matches?(params)
|
29
|
+
# Run the action method if defined
|
30
|
+
if respond_to?(action)
|
31
|
+
send(action, lead, params)
|
32
|
+
# Increment and save count of rule/lead applications
|
33
|
+
count.count += 1
|
34
|
+
count.save
|
35
|
+
else
|
36
|
+
raise "Do not know how to process '#{action}' action."
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
end
|
@@ -74,23 +79,47 @@ class EventRule < ActiveRecord::Base
|
|
74
79
|
lead.versions.create! :event => "Rule for #{human_event_label}: Removed tag '#{tag}'"
|
75
80
|
end
|
76
81
|
|
82
|
+
def add_to_mailing_list_group(lead, match_data)
|
83
|
+
# Send a Cloudfuji event which results in a call to the Mailchimp API,
|
84
|
+
# and adds InterestGroup to lead.
|
85
|
+
event = {
|
86
|
+
:category => :mailing_list_group,
|
87
|
+
:name => :added,
|
88
|
+
:data => {
|
89
|
+
:email => lead.email,
|
90
|
+
:customer_ido_id => lead.ido_id,
|
91
|
+
:user_ido_id => user_ido_id,
|
92
|
+
:mailing_list => mailing_list,
|
93
|
+
:mailing_list_grouping => mailing_list_grouping,
|
94
|
+
:mailing_list_group => mailing_list_group
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
puts "Publishing Cloudfuji Event: #{event.inspect}"
|
99
|
+
::Cloudfuji::Event.publish(event)
|
100
|
+
end
|
77
101
|
|
78
102
|
private
|
79
103
|
|
80
|
-
def event_matches?(
|
104
|
+
def event_matches?(match)
|
81
105
|
test_string = case_insensitive_matching ? match.downcase : match
|
82
106
|
case event_category
|
83
107
|
when 'cloudfuji_event_received'
|
84
|
-
match_string =
|
108
|
+
match_string = match['data'].inspect
|
85
109
|
match_string.downcase! if case_insensitive_matching
|
86
110
|
match_string.include?(test_string)
|
87
111
|
when 'lead_attribute_changed'
|
88
|
-
match_string =
|
112
|
+
match_string = match[1].to_s.dup
|
89
113
|
match_string.downcase! if case_insensitive_matching
|
90
114
|
match_string == test_string.to_s
|
91
115
|
end
|
92
116
|
end
|
93
117
|
|
118
|
+
def page_and_app_matches?(params)
|
119
|
+
(page_name.blank? || page_name == params["data"]["page"]) &&
|
120
|
+
(app_id.blank? || app_id == params["app_id"])
|
121
|
+
end
|
122
|
+
|
94
123
|
def human_event_label
|
95
124
|
case event_category
|
96
125
|
when 'cloudfuji_event_received'; "Cloudfuji event - '#{cloudfuji_event}'"
|
@@ -7,19 +7,24 @@
|
|
7
7
|
= event_category_select(r)
|
8
8
|
|
9
9
|
= event_fields_for(r.object, 'cloudfuji_event_received') do
|
10
|
-
= r.text_field :cloudfuji_event, :class => "
|
10
|
+
= r.text_field :cloudfuji_event, :class => "cloudfuji_event_input"
|
11
11
|
is received, and contains
|
12
12
|
|
13
|
+
= event_fields_for(r.object, 'page_loaded') do
|
14
|
+
= r.text_field :page_name, :class => "page_name_input"
|
15
|
+
on app ID
|
16
|
+
= r.text_field :app_id, :class => "app_id_input"
|
17
|
+
|
13
18
|
= event_fields_for(r.object, 'lead_attribute_changed') do
|
14
19
|
= r.select :lead_attribute, lead_attributes, :class => "lead_attribute", :include_blank => true
|
15
20
|
changes, and equals
|
16
21
|
|
17
|
-
=
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
= event_fields_for(r.object, %w(cloudfuji_event_received lead_attribute_changed)) do
|
23
|
+
= content_tag(:small, "(optional)") << ":".html_safe
|
24
|
+
= r.text_field :match, :class => "match_input"
|
25
|
+
%small
|
26
|
+
(Case insensitive?
|
27
|
+
= r.check_box(:case_insensitive_matching) << h(")")
|
23
28
|
|
24
29
|
then
|
25
30
|
= action_select(r)
|
@@ -33,6 +38,17 @@
|
|
33
38
|
= action_fields_for(r.object, %w(add_tag remove_tag)) do
|
34
39
|
= r.text_field :tag, :class => "tag_input"
|
35
40
|
|
41
|
+
= action_fields_for(r.object, %w(add_to_mailing_list_group)) do
|
42
|
+
= r.text_field :mailing_list_group, :class => "mailing_list_group_input"
|
43
|
+
in grouping
|
44
|
+
= r.text_field :mailing_list_grouping, :class => "mailing_list_grouping_input"
|
45
|
+
on list
|
46
|
+
= r.text_field :mailing_list, :class => "mailing_list_input"
|
47
|
+
%br
|
48
|
+
-# TEMPORARY WORKAROUND
|
49
|
+
%small{:style => "margin-left:26px;display:inline-block;padding-top:14px;"} Umi user Ido ID:
|
50
|
+
= r.text_field :user_ido_id
|
51
|
+
|
36
52
|
= action_fields_for(r.object, %w(change_lead_score send_notification)) do
|
37
53
|
%small
|
38
54
|
(Limit per lead:
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class AddMailingListAndPageFieldsToEventRules < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :event_rules, :mailing_list, :string
|
4
|
+
add_column :event_rules, :mailing_list_group, :string
|
5
|
+
add_column :event_rules, :mailing_list_grouping, :string
|
6
|
+
|
7
|
+
add_column :event_rules, :page_name, :string
|
8
|
+
add_column :event_rules, :app_id, :string
|
9
|
+
|
10
|
+
# TODO - There's no way to figure out which user to use based on a received event... ??
|
11
|
+
# Just making the Umi user's ido_id field temporarily part of the event rule form, for now.
|
12
|
+
add_column :event_rules, :user_ido_id, :string
|
13
|
+
end
|
14
|
+
end
|
@@ -8,8 +8,8 @@ module FatFreeCRM
|
|
8
8
|
def catch_all
|
9
9
|
if lead = find_lead_by_data
|
10
10
|
event_name = "#{params['category']}_#{params['event']}"
|
11
|
-
EventRule.
|
12
|
-
rule.process(lead, params
|
11
|
+
EventRule.find(:all, :conditions => ["event_category IN ('cloudfuji_event_received', 'page_loaded') AND cloudfuji_event = ?", event_name]).each do |rule|
|
12
|
+
rule.process(lead, params)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffcrm_cloudfuji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec-rails
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- db/migrate/20120515194445_add_lead_scoring_rules.rb
|
130
130
|
- db/migrate/20120524031157_extend_lead_scoring_as_event_rules.rb
|
131
131
|
- db/migrate/20120525151511_add_ido_id_to_lead.rb
|
132
|
+
- db/migrate/20120607115701_add_mailing_list_and_page_fields_to_event_rules.rb
|
132
133
|
- ffcrm_cloudfuji.gemspec
|
133
134
|
- install.rb
|
134
135
|
- lib/fat_free_crm/cloudfuji.rb
|
@@ -168,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
169
|
version: '0'
|
169
170
|
segments:
|
170
171
|
- 0
|
171
|
-
hash:
|
172
|
+
hash: -1045058604205238337
|
172
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
174
|
none: false
|
174
175
|
requirements:
|
@@ -177,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
178
|
version: '0'
|
178
179
|
segments:
|
179
180
|
- 0
|
180
|
-
hash:
|
181
|
+
hash: -1045058604205238337
|
181
182
|
requirements: []
|
182
183
|
rubyforge_project:
|
183
184
|
rubygems_version: 1.8.24
|