Permalink
Browse files

Fixed a couple of bugs.

  • Loading branch information...
1 parent 326f598 commit 0e6750fbb1a87d4b5691ea5b445600c539d222c6 @steveyken steveyken committed Feb 21, 2013
View
@@ -1,4 +1,4 @@
-source :rubygems
+source 'https://rubygems.org'
gemspec
View
@@ -33,9 +33,11 @@ New in version 1.3 (steveyken)
* Added ability to merge addresses visually
* Moved styles out of template and into css
* Custom field labels are translated on merge form
-** Expects the translation lookup path to be 'active_record.attributes.contact.cf_your_custom_field_name'
+ * Expects the translation lookup path to be 'active_record.attributes.contact.cf_your_custom_field_name'
* Improved subscribed_users formatting
* Fixed javascript bug where not all merge links were yielding popups. (Have to listen for both jQuery and prototype events.)
+* Fixed final redirect to merged entity when using direct url to merge (v1.3.1)
+* Corrected module namespacing (v1.3.1)
MERGE HOOKS
===========
@@ -26,14 +26,10 @@ def into
flash[:error] = I18n.t('assets_merge_invalid', :name => @master.name)
elsif !@duplicate.valid?
flash[:error] = I18n.t('assets_merge_invalid', :name => @duplicate.name)
- else
- if request.put?
- if do_merge(@master, @duplicate)
- redirect_to(@master) and return
- else
- flash[:error] = I18n.t('assets_merge_error', :assets => klass.to_s.humanize)
- end
- end
+ elsif request.put?
+ do_merge(@master, @duplicate)
+ @success = true # do_merge will throw error if problem
+ flash[:error] = I18n.t('assets_merge_error', :assets => klass.to_s.humanize) unless @success
end
respond_with(@duplicate)
@@ -6,7 +6,20 @@
<%# ensure we replace with either @master or @duplicate depending on the id in @previous %>
<% @entity = (@master.id.to_s == @previous.gsub("#{klass_name}_", '')) ? @master : @duplicate %>
- jQuery('#<%=@previous%>').replaceWith('<%= j(render :partial => "#{klass_name.tableize}/#{klass_name}", :collection => [ @entity ]) %>')
+ jQuery('#<%=@previous%>').replaceWith('<%= j(render :partial => "#{klass_name.tableize}/#{klass_name}", :collection => [ @entity ]) %>');
+
+<% elsif @success %>
+
+ <% if @previous.blank? %>
+ <%# we are not on the index page so redirect to the merged entity %>
+ jQuery(window.location.href = "<%= polymorphic_url(@master) %>");
+ <% else %>
+ <% remove_id = (@master.id.to_s == @previous.gsub("#{klass_name}_", '')) ? @duplicate.id : @master.id %>
+ jQuery('#<%=klass_name%>_<%=remove_id%>').remove();
+ jQuery('#<%=@previous%>').replaceWith('<%= j(render :partial => "#{klass_name.tableize}/#{klass_name}", :collection => [ @master ]) %>');
+ jQuery('#<%=@previous%>').effect('highlight', 1000);
+ jQuery('#recently').replaceWith('<%= j(render :partial => "shared/recently") %>');
+ <% end %>
<% else %>
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.description = 'Fat Free CRM - Merge Contacts & Accounts'
s.files = `git ls-files`.split("\n")
s.test_files = Dir["spec/**/*"]
- s.version = FatFreeCRM::Merge::VERSION
+ s.version = FfcrmMerge::VERSION
s.add_development_dependency 'rspec-rails', '>= 2.12.2'
s.add_development_dependency 'capybara'
@@ -1,4 +1,4 @@
-module Merge
+module FfcrmMerge
module Accounts
IGNORED_ATTRIBUTES = %w(updated_at created_at deleted_at id)
@@ -84,10 +84,10 @@ def merge_with(master, ignored_attr = [])
def merge_attributes
attrs = self.attributes.dup.reject{ |k,v| ignored_merge_attributes.include?(k) }
attrs.merge!(address_attributes) # we want addresses to be shown in the UI
- attrs.sort do |a,b|
+ sorted = attrs.sort do |a,b|
(ordered_merge_attributes.index(a.first) || 1000) <=> (ordered_merge_attributes.index(b.first) || 1000)
end
- attrs
+ Hash[*sorted.flatten]
end
# These attributes need to be included on the merge form but ignore in update_attributes
@@ -122,13 +122,3 @@ def merge_hook(duplicate)
end
end
-
-Account.class_eval do
- include Merge::Accounts
-end
-
-# TODO lazy loading would be better here
-# something like (note we haven't defined on_load for account class yet)
-# ActiveSupport.on_load :account do
-# include Merge::Accounts
-# end
@@ -1,4 +1,4 @@
-module Merge
+module FfcrmMerge
module Contacts
IGNORED_ATTRIBUTES = %w(updated_at created_at deleted_at id)
@@ -92,10 +92,10 @@ def merge_with(master, ignored_attr = [])
def merge_attributes
attrs = self.attributes.dup.reject{ |k,v| ignored_merge_attributes.include?(k) }
attrs.merge!(address_attributes) # we want addresses to be shown in the UI
- attrs.sort do |a,b|
+ sorted = attrs.sort do |a,b|
(ordered_merge_attributes.index(a.first) || 1000) <=> (ordered_merge_attributes.index(b.first) || 1000)
end
- attrs
+ Hash[*sorted.flatten]
end
# These attributes need to be included on the merge form but ignore in update_attributes
@@ -128,14 +128,3 @@ def merge_hook(duplicate)
end
end
-
-# Include Merge::Contacts methods on Contact model
-Contact.class_eval do
- include Merge::Contacts
-end
-
-# TODO lazy loading would be better here
-# something like (note we haven't defined on_load for contact class yet)
-# ActiveSupport.on_load :contact do
-# include Merge::Contacts
-# end
View
@@ -1,21 +1,27 @@
-module FatFreeCRM
- module Merge
- class Engine < ::Rails::Engine
-
- config.to_prepare do
- require 'ffcrm_merge/accounts'
- require 'ffcrm_merge/contacts'
- require 'ffcrm_merge/merge_view_hooks'
- require 'ffcrm_merge/merge_not_found_controller'
+module FfcrmMerge
+ class Engine < ::Rails::Engine
+
+ config.to_prepare do
+ require 'ffcrm_merge/accounts'
+ Account.class_eval do
+ include FfcrmMerge::Accounts
end
- config.generators do |g|
- g.test_framework :rspec, :fixture => false
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
- g.assets false
- g.helper false
+ require 'ffcrm_merge/contacts'
+ Contact.class_eval do
+ include FfcrmMerge::Contacts
end
+ require 'ffcrm_merge/merge_view_hooks'
+ require 'ffcrm_merge/merge_not_found_controller'
+ end
+
+ config.generators do |g|
+ g.test_framework :rspec, :fixture => false
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
+ g.assets false
+ g.helper false
end
+
end
end
@@ -1,10 +1,14 @@
-class MergeViewHooks < FatFreeCRM::Callback::Base
-
- def contact_tools_before(view, context = {})
- view.render(:partial => 'merge/merge_tool', :locals => {:entity => context[:contact]})
- end
-
- def account_tools_before(view, context = {})
- view.render(:partial => 'merge/merge_tool', :locals => {:entity => context[:account]})
+module FfcrmMerge
+
+ class MergeViewHooks < FatFreeCRM::Callback::Base
+
+ def contact_tools_before(view, context = {})
+ view.render(:partial => 'merge/merge_tool', :locals => {:entity => context[:contact]})
+ end
+
+ def account_tools_before(view, context = {})
+ view.render(:partial => 'merge/merge_tool', :locals => {:entity => context[:account]})
+ end
end
+
end
@@ -1,5 +1,3 @@
-module FatFreeCRM
- module Merge
- VERSION = '1.3'
- end
+module FfcrmMerge
+ VERSION = '1.3.1'
end

0 comments on commit 0e6750f

Please sign in to comment.