e9_crm 0.1.19 → 0.1.20

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.
@@ -2,6 +2,8 @@ class E9Crm::CampaignsController < E9Crm::ResourcesController
2
2
  defaults :resource_class => Campaign
3
3
  include E9Rails::Controllers::Orderable
4
4
 
5
+ before_filter :redirect_new_to_subclass, :only => :new
6
+
5
7
  self.should_paginate_index = false
6
8
 
7
9
  has_scope :of_group, :as => :group, :only => :index
@@ -11,11 +13,17 @@ class E9Crm::CampaignsController < E9Crm::ResourcesController
11
13
  end
12
14
 
13
15
  has_scope :of_type, :as => :type, :only => :index do |_, scope, value|
14
- scope.of_type("#{value}_campaign".classify)
16
+ scope.of_type("#{type}_campaign".classify)
15
17
  end
16
18
 
17
19
  protected
18
20
 
21
+ def redirect_new_to_subclass
22
+ types = %w(advertising affiliate email sales)
23
+ type = types.member?(params[:type]) ? params[:type] : types.first
24
+ redirect_to send("new_#{type}_campaign_path")
25
+ end
26
+
19
27
  def collection_scope
20
28
  #end_of_association_chain.typed.includes(:campaign_group)
21
29
 
@@ -2,8 +2,9 @@ class E9Crm::ContactMergesController < E9Crm::BaseController
2
2
  before_filter :build_resources
3
3
 
4
4
  def create
5
- if @contact_a.update_attributes(params[:contact])
6
- @contact_a.merge_and_destroy!(@contact_b)
5
+ @contact_a.attributes = params[:contact]
6
+
7
+ if @contact_a.merge_and_destroy!(@contact_b)
7
8
  redirect_to @contact_a
8
9
  else
9
10
  render :new
@@ -13,14 +14,8 @@ class E9Crm::ContactMergesController < E9Crm::BaseController
13
14
  protected
14
15
 
15
16
  def build_resources
16
- @contact ||= Contact.new
17
17
  @contact_a ||= Contact.find(params[:contact_a_id])
18
-
19
- # NOTE lets see if this works
20
- @contact_b ||= if params[:contact]
21
- Contact.new(params[:contact])
22
- else
23
- Contact.find(params[:contact_b_id])
24
- end
18
+ @contact_b ||= Contact.find(params[:contact_b_id])
19
+ @contact ||= Contact.new
25
20
  end
26
21
  end
@@ -12,10 +12,4 @@ module E9Crm::OffersHelper
12
12
  retv.compact
13
13
  end
14
14
  end
15
-
16
- def offer_select_options(with_all_option = true)
17
- options = %w(contact file_download new_content_subscription newsletter_subscription video).map {|t| [t.titleize, t] }
18
- options.unshift(['All Types', nil]) if with_all_option
19
- options_for_select(options)
20
- end
21
15
  end
@@ -210,16 +210,32 @@ class Contact < ActiveRecord::Base
210
210
  [first_name, last_name].join(' ').to_s.strip
211
211
  end
212
212
 
213
- def merge_and_destroy!(other_contact)
214
- other_contact.users.clear_primary!
213
+ # NOTE there's no non-destructive `merge`
214
+ def merge_and_destroy!(other)
215
+ merge_tags(other)
215
216
 
216
- self.users |= other_contact.users
217
- self.website_attributes |= other_contact.website_attributes
218
- self.address_attributes |= other_contact.address_attributes
219
- self.phone_number_attributes |= other_contact.phone_number_attributes
220
- self.instant_messaging_handle_attributes |= other_contact.instant_messaging_handle_attributes
217
+ if success = save
218
+ merge_destructive_and_destroy!(other)
219
+ end
220
+
221
+ success
222
+ end
221
223
 
222
- other_contact.destroy
224
+ def merge_tags(other)
225
+ tags = self.tag_list_on('users__h__')
226
+ other_tags = other.tag_list_on('users__h__')
227
+ set_tag_list_on('users__h__', tags | other_tags)
228
+ end
229
+
230
+ def merge_destructive_and_destroy!(other)
231
+ other.users.clear_primary!
232
+ self.associated_deals |= other.associated_deals
233
+ self.users |= other.users
234
+ self.website_attributes |= other.website_attributes
235
+ self.address_attributes |= other.address_attributes
236
+ self.phone_number_attributes |= other.phone_number_attributes
237
+ self.instant_messaging_handle_attributes |= other.instant_messaging_handle_attributes
238
+ other.destroy
223
239
  end
224
240
 
225
241
  def valid?(context = nil)
@@ -248,33 +264,33 @@ class Contact < ActiveRecord::Base
248
264
  unless errors.delete(:"users.email").blank?
249
265
  users.dup.each_with_index do |user, i|
250
266
  user.errors[:email].each do |error|
251
- if error.taken? && users.select {|u| u.email == user.email }.length == 1
252
- existing_user = User.find_by_email(user.email)
253
-
254
- if contact = existing_user.contact
255
- args = if new_record?
256
- [contact, 'new', {:contact => self.attributes}]
257
- else
258
- [contact, self]
259
- end
260
-
261
- errors.add(:users, :merge_required, {
262
- :email => user.email,
263
- :merge_path => new_contact_merge_path(*args)
264
- })
265
-
266
- return false
267
- else
268
- self.users.delete(user)
269
- self.users << existing_user
270
- end
271
- else
267
+ #if error.taken? && users.select {|u| u.email == user.email }.length == 1
268
+ #existing_user = User.find_by_email(user.email)
269
+
270
+ #if contact = existing_user.contact
271
+ #args = if new_record?
272
+ #[contact, 'new', {:contact => self.attributes}]
273
+ #else
274
+ #[contact, self]
275
+ #end
276
+
277
+ #errors.add(:users, :merge_required, {
278
+ #:email => user.email,
279
+ #:merge_path => new_contact_merge_path(*args)
280
+ #})
281
+
282
+ #return false
283
+ #else
284
+ #self.users.delete(user)
285
+ #self.users << existing_user
286
+ #end
287
+ #else
272
288
  if error.label
273
289
  errors.add(:users, error.label.to_sym, :email => user.email)
274
290
  else
275
291
  errors.add(:users, nil, :message => error, :email => user.email)
276
292
  end
277
- end
293
+ #end
278
294
  end
279
295
  end
280
296
 
@@ -9,7 +9,7 @@
9
9
  = campaign_active_select_options
10
10
 
11
11
  .toolbar-right
12
- = form_tag new_advertising_campaign_path, :method => :get, :id => 'new_campaign_form' do
12
+ = form_tag new_campaign_path, :method => :get, :id => 'new_campaign_form' do
13
13
  = label_tag 'new_campaign_type_select', t('activerecord.links.new', :model => Campaign.model_name.human)
14
14
  %select{:name => 'type', :id => 'new_campaign_type_select'}
15
15
  = campaign_type_select_options(false)
@@ -1,10 +1,13 @@
1
+ - val = f.object.send(column)
2
+ - a_checked = val == contact_a(column) || val.blank?
3
+ - b_checked = !a_checked
1
4
  .field
2
5
  = f.label column
3
6
  .contact-a-value
4
7
  %label{:for => "contact_a_#{column}"}
5
8
  = contact_a(column).presence || e9_t(:no_value)
6
- = f.radio_button column, contact_a(column), :checked => (f.object.send(column) == contact_a(column) || f.object.send(column).blank?), :id => "contact_a_#{column}"
9
+ = f.radio_button column, contact_a(column), :checked => a_checked, :id => "contact_a_#{column}"
7
10
  .contact-b-value
8
11
  %label{:for => "contact_b_#{column}"}
9
12
  = contact_b(column).presence || e9_t(:no_value)
10
- = f.radio_button column, contact_b(column), :id => "contact_b_#{column}"
13
+ = f.radio_button column, contact_b(column), :checked => b_checked, :id => "contact_b_#{column}"
@@ -6,5 +6,6 @@
6
6
  = render 'field', :column => :last_name, :f => f
7
7
  = render 'field', :column => :company_name, :f => f
8
8
  = render 'field', :column => :title, :f => f
9
+
9
10
  .actions
10
11
  = f.submit t(:save)
@@ -42,3 +42,6 @@
42
42
 
43
43
  - content_for :bottom_javascripts do
44
44
  = javascript_include_tag templates_contacts_path
45
+ #merge-dialog{:title => t(:email_taken_title), 'data-id' => resource.try(:id) }
46
+ %p= I18n.t(resource.persisted? ? :edit_conflict : :merge_conflict).html_safe
47
+
@@ -21,10 +21,14 @@
21
21
  = check_box_tag "offer[mailing_list_ids][]", ml.id, resource.has_mailing_list?(ml), :id => "offer_mailing_list_ids_#{ml.id}"
22
22
  = label_tag "offer_mailing_list_ids_#{ml.id}", ml.name
23
23
 
24
- .field.tinymce
25
- = f.label :template
24
+ .field
25
+ = help_label(f, :template, :markdown => true)
26
26
  = f.text_area :template
27
27
 
28
+ .field.tinymce
29
+ = f.label :success_page_text
30
+ = f.text_area :success_page_text
31
+
28
32
  .field
29
33
  = f.label :custom_form_html
30
34
  = f.text_area :custom_form_html
@@ -1,8 +1,3 @@
1
1
  .toolbar
2
- .toolbar-left
3
- = form_tag(resource_class, :method => :get, :class => 'scope-selects') do
4
- %select{:name => 'type'}
5
- = offer_select_options
6
-
7
2
  .toolbar-right
8
3
  = link_to_new_resource(Offer)
@@ -1,4 +1,8 @@
1
1
  en:
2
+ email_taken_title: Oops!
3
+ edit_conflict: "<p>This email is already attached to another contact and cannot be used.</p><p>Do you want to merge these contacts now?</p><p>Be careful! If you have made extensive edits you may want to save first and come back to merge.</p>"
4
+ merge_conflict: "<p>This email is already attached to another contact and cannot be used.</p><p>Do you want to edit that contact instead?</p>"
5
+
2
6
  actions: Actions
3
7
  clear: Clear
4
8
  clear_all_filters: Clear All Filters
@@ -41,7 +45,7 @@ en:
41
45
 
42
46
  errors:
43
47
  messages:
44
- merge_required: 'Merge Required! <a href="%{merge_path}">MERGE ME</a>.'
48
+ merge_required:
45
49
  models:
46
50
  campaign:
47
51
  not_a_number: "%{attribute} must be a number (maximum 2 decimal places)."
data/config/routes.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  Rails.application.routes.draw do
2
2
  crm_path = 'admin/crm'
3
3
 
4
- get '/autocomplete/contacts' => E9Crm::Rack::ContactAutoCompleter
4
+ get '/autocomplete/contacts' => E9Crm::Rack::ContactAutoCompleter
5
5
  get '/autocomplete/companies' => E9Crm::Rack::CompanyAutoCompleter
6
+ get '/users/email_test.json' => E9Crm::Rack::EmailAvailabilityChecker
6
7
 
7
8
  scope :module => :e9_crm do
8
9
  resources :offers, :as => :public_offer, :only => :show do
@@ -41,7 +42,7 @@ Rails.application.routes.draw do
41
42
  end
42
43
  end
43
44
 
44
- resources :campaigns, :only => [:index, :destroy] do
45
+ resources :campaigns, :only => [:index, :destroy, :new] do
45
46
  # page_views currently not routed, but near working
46
47
  #resources :page_views, :path => 'activity', :only => :index
47
48
  end
@@ -0,0 +1,31 @@
1
+ module E9Crm::Rack
2
+ class EmailAvailabilityChecker
3
+ def self.call(env)
4
+ @params = Rack::Request.new(env).params
5
+ @email = @params['email']
6
+ @contact = nil
7
+ @url = nil
8
+
9
+ if @user = User.find_by_email(@email)
10
+ if @contact = @user.contact
11
+ @url = if @params['id'] && c = Contact.find_by_id(@params['id'])
12
+ "/admin/crm/merge_contacts/#{@contact.id}/and/#{c.id}"
13
+ else
14
+ "/admin/crm/contacts/#{@contact.id}/edit"
15
+ end
16
+ end
17
+
18
+ @body = {
19
+ :email => @email,
20
+ :id => @user.id,
21
+ :contact_id => @contact.try(:id),
22
+ :url => @url
23
+ }.to_json
24
+
25
+ [200, {"Content-Type" => "application/json"}, [@body]]
26
+ else
27
+ [404, {"Content-Type" => "text/html", "X-Cascade" => "pass"}, ["Not Found"]]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module E9Crm
2
- VERSION = '0.1.19'
2
+ VERSION = '0.1.20'
3
3
  end
data/lib/e9_crm.rb CHANGED
@@ -3,16 +3,17 @@ require 'money'
3
3
  require 'e9_crm/rails_extensions'
4
4
 
5
5
  module E9Crm
6
- autoload :VERSION, 'e9_crm/version'
7
- autoload :Controller, 'e9_crm/controller'
8
- autoload :Model, 'e9_crm/model'
9
- autoload :Email, 'e9_crm/email'
10
- autoload :TrackingController, 'e9_crm/tracking_controller'
11
- autoload :SystemEmailsController, 'e9_crm/system_emails_controller'
6
+ autoload :VERSION, 'e9_crm/version'
7
+ autoload :Controller, 'e9_crm/controller'
8
+ autoload :Model, 'e9_crm/model'
9
+ autoload :Email, 'e9_crm/email'
10
+ autoload :TrackingController, 'e9_crm/tracking_controller'
11
+ autoload :SystemEmailsController, 'e9_crm/system_emails_controller'
12
12
 
13
13
  module Rack
14
- autoload :ContactAutoCompleter, 'e9_crm/rack/contact_auto_completer'
15
- autoload :CompanyAutoCompleter, 'e9_crm/rack/company_auto_completer'
14
+ autoload :ContactAutoCompleter, 'e9_crm/rack/contact_auto_completer'
15
+ autoload :CompanyAutoCompleter, 'e9_crm/rack/company_auto_completer'
16
+ autoload :EmailAvailabilityChecker, 'e9_crm/rack/email_availability_checker'
16
17
  end
17
18
 
18
19
  mattr_accessor :cookie_name
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: e9_crm
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.19
5
+ version: 0.1.20
6
6
  platform: ruby
7
7
  authors:
8
8
  - Travis Cox
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-14 00:00:00 Z
13
+ date: 2011-09-15 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -310,6 +310,7 @@ files:
310
310
  - lib/e9_crm/model.rb
311
311
  - lib/e9_crm/rack/company_auto_completer.rb
312
312
  - lib/e9_crm/rack/contact_auto_completer.rb
313
+ - lib/e9_crm/rack/email_availability_checker.rb
313
314
  - lib/e9_crm/rails_extensions.rb
314
315
  - lib/e9_crm/system_emails_controller.rb
315
316
  - lib/e9_crm/tracking_controller.rb