From 00c96256e0e3325e114aa97d9f938e2809112331 Mon Sep 17 00:00:00 2001 From: Daniel Collis-Puro Date: Thu, 29 Apr 2010 16:09:11 -0400 Subject: [PATCH] Fix routing, bulk tagging, UI and other issues. --- app/controllers/admin/bulk_action_controller.rb | 12 +++++------- app/controllers/contact_carts_controller.rb | 12 ++++++------ .../freemailer_campaigns_controller.rb | 14 +++++++------- app/models/contact_cart.rb | 2 ++ app/models/freemailer_campaign.rb | 2 ++ app/views/contact_carts/_bulk_action.html.erb | 8 +++----- app/views/shared/_bulk_contact_actions.html.erb | 6 ++++-- public/stylesheets/base.css | 16 ++++++++++++++-- 8 files changed, 43 insertions(+), 29 deletions(-) diff --git a/app/controllers/admin/bulk_action_controller.rb b/app/controllers/admin/bulk_action_controller.rb index 118ea7d..d802ab2 100644 --- a/app/controllers/admin/bulk_action_controller.rb +++ b/app/controllers/admin/bulk_action_controller.rb @@ -17,13 +17,13 @@ def bulk_note def bulk_tag_remove if request.post? - tags = [] + tags = [] parse_bulk_tag_list(:tags => params[:bulk_remove_tags], :tag_list => tags, :autocreate => false) contact_ids = params[:contact_ids] Contact.find_all_by_id(contact_ids).each do |c| ctids = c.tag_ids tags.each do |t| - ctids.delete(t) + ctids.delete(t.to_i) end c.tag_ids = ctids end @@ -54,9 +54,7 @@ def bulk_tag parse_bulk_tag_list(:tags => params[:bulk_apply_tags], :tag_list => new_tags, :autocreate => true) contact_ids = params[:contact_ids] Contact.find_all_by_id(contact_ids, :include => :tags).each do |c| - tag_ids = c.tag_ids - tag_ids << new_tags - c.tag_ids = tag_ids.uniq.compact + c.tag_ids = [c.tag_ids, new_tags].flatten.uniq.compact end Contact.bulk_index(contact_ids) flash[:notice] = 'Those contacts have been tagged.' @@ -83,7 +81,7 @@ def bulk_create_campaign flash[:notice] = 'Campaign created. Now just fill in the rest!' redirect_to edit_freemailer_campaign_url @campaign and return else - flash[:error] = "We couldn't create the campaign. Perhaps a more unique title?" + flash[:error] = "We couldn't create the campaign. Please select some contacts and ensure that the title of this campaign is unique." end end manage_destination @@ -95,7 +93,7 @@ def parse_bulk_tag_list(param) param[:tags].split(',').each do |tag| matchval = tag.match(/\(id\:(\d+)\)$/) if matchval - param[:tag_list] << matchval[1].to_i + param[:tag_list] << matchval[1] elsif param[:autocreate] && param[:autocreate] == true begin unless tag.blank? diff --git a/app/controllers/contact_carts_controller.rb b/app/controllers/contact_carts_controller.rb index ada9622..153c953 100644 --- a/app/controllers/contact_carts_controller.rb +++ b/app/controllers/contact_carts_controller.rb @@ -6,7 +6,7 @@ def make_active @session_user.active_contact_cart = ContactCart.find(params[:contact_cart_id], :conditions => ["user_id = ? or global = true",@session_user.id]) @session_user.save flash[:notice] = "Contact Cart has been made active." - redirect_to contact_carts_url + manage_destination contact_carts_url end # (GET) clear_active sets the user's active contact cart to nil. @@ -14,7 +14,7 @@ def clear_active flash[:notice] = "Active contact cart cleared." @session_user.active_contact_cart = nil @session_user.save - redirect_to contact_carts_url + manage_destination contact_carts_url end def edit @@ -60,10 +60,10 @@ def create @session_user.save flash[:notice] = 'Contact cart created/updated.' else - flash[:error] = "We couldn't create the cart." + flash[:error] = "We couldn't create the cart. Be sure to select some contacts." end end - manage_destination + manage_destination contact_carts_url end # (POST) remove_contact removes the contact with id of params[:contact_to_remove_id] from the user's active contact cart @@ -72,7 +72,7 @@ def remove_contact @contact_cart = @session_user.active_contact_cart @contact_cart.contacts.delete( Contact.find(params[:contact_to_remove_id])) @contact_cart.save - manage_destination + manage_destination contact_carts_url end end @@ -86,7 +86,7 @@ def destroy flash[:error] = 'Contact cart not destroyed. Are you trying to delete someone else\'s cart?' end respond_to do |format| - format.html { manage_destination } + format.html { manage_destination(contact_carts_url) } format.xml { head :ok } end end diff --git a/app/controllers/freemailer_campaigns_controller.rb b/app/controllers/freemailer_campaigns_controller.rb index 5e43943..8eeb6bf 100644 --- a/app/controllers/freemailer_campaigns_controller.rb +++ b/app/controllers/freemailer_campaigns_controller.rb @@ -8,7 +8,7 @@ class FreemailerCampaignsController < ApplicationController def make_active @freemailer_campaign.make_active_for_sender flash[:notice] = "Campaign has been made active." - redirect_to freemailer_campaigns_url + manage_destination(freemailer_campaigns_url) end # Clear user's current active campaign @@ -16,7 +16,7 @@ def clear_active flash[:notice] = "Active campaign cleared." @session_user.active_campaign = nil @session_user.save - redirect_to freemailer_campaigns_url + manage_destination(freemailer_campaigns_url) end # Tell the Campaign that it should send the user's active campaign @@ -27,7 +27,7 @@ def send_campaign flash[:notice] = "Mailing Campaign will be sent shortly." @session_user.active_campaign = nil @session_user.save - redirect_to freemailer_campaigns_url + manage_destination(freemailer_campaigns_url) end # Renders a partial displaying mail delivery status for the given campaign. Used in conjuction with Modalbox for display - see app/views/_campaign.html.haml @@ -69,7 +69,7 @@ def create # :nodoc: respond_to do |format| if @freemailer_campaign.save flash[:notice] = 'Mailing Campaign was successfully created.' - format.html { redirect_to(@freemailer_campaign) } + format.html { manage_destination(@freemailer_campaign) } format.xml { render :xml => @freemailer_campaign, :status => :created, :location => @freemailer_campaign } else format.html { render :action => "new" } @@ -82,7 +82,7 @@ def update # :nodoc: respond_to do |format| if @freemailer_campaign.update_attributes(params[:freemailer_campaign]) flash[:notice] = 'Mailing Campaign was successfully updated.' - format.html { redirect_to(@freemailer_campaign) } + format.html { manage_destination(@freemailer_campaign) } format.xml { head :ok } else format.html { render :action => "edit" } @@ -95,7 +95,7 @@ def destroy # :nodoc: @freemailer_campaign.destroy respond_to do |format| - format.html { redirect_to(freemailer_campaigns_url) } + format.html { manage_destination(freemailer_campaigns_url) } format.xml { head :ok } end end @@ -109,7 +109,7 @@ def only_load_campaigns_user_owns @freemailer_campaign = FreemailerCampaign.find(params[:id]) if @freemailer_campaign.sender != @session_user flash[:error] = "You do not own the freemailer campaign you are trying to access" - redirect_to freemailer_campaigns_url + manage_destination(freemailer_campaigns_url) end end end diff --git a/app/models/contact_cart.rb b/app/models/contact_cart.rb index 35d8169..b61d72c 100644 --- a/app/models/contact_cart.rb +++ b/app/models/contact_cart.rb @@ -6,6 +6,8 @@ class ContactCart < ActiveRecord::Base has_many :contact_cart_entries, :dependent => :destroy has_many :contacts, :through => :contact_cart_entries + validates_presence_of :contact_ids + # Provides a list of contacts in the cart joined by ", " or " -- None Added -- " if there are no contacts. def contact_names contacts.count == 0 ? ' -- None Added -- ' : contacts.map(&:name_for_display).join(', ').squeeze(' ') diff --git a/app/models/freemailer_campaign.rb b/app/models/freemailer_campaign.rb index 5fff5f3..6a7d9dc 100644 --- a/app/models/freemailer_campaign.rb +++ b/app/models/freemailer_campaign.rb @@ -4,6 +4,8 @@ class FreemailerCampaign < ActiveRecord::Base has_many :freemailer_campaign_contacts, :dependent => :destroy has_many :contacts, :through => :freemailer_campaign_contacts + validates_presence_of :contact_ids + validates_uniqueness_of :title, :scope => :sender_id, :on => :create, :message => "must be unique" #JS me before_destroy :remove_active_campaign diff --git a/app/views/contact_carts/_bulk_action.html.erb b/app/views/contact_carts/_bulk_action.html.erb index 8b65acf..2b419a5 100644 --- a/app/views/contact_carts/_bulk_action.html.erb +++ b/app/views/contact_carts/_bulk_action.html.erb @@ -1,9 +1,8 @@ - diff --git a/app/views/shared/_bulk_contact_actions.html.erb b/app/views/shared/_bulk_contact_actions.html.erb index 8b9ecb4..0ab7d1a 100644 --- a/app/views/shared/_bulk_contact_actions.html.erb +++ b/app/views/shared/_bulk_contact_actions.html.erb @@ -61,11 +61,13 @@ Due Date: <%= calendar_date_select_tag "follow_up", '', :time => true, :minute_i <% if @session_user.active_campaign.nil? %> <%= text_field_tag 'title',"#{@session_user.username} - #{Date.today}" %>
+ <% else %> +

<%= h @session_user.active_campaign.title %> (<%= @session_user.active_campaign.contacts.length %>)

<% end %> <%= hidden_field_tag '_redirect_to', url_for(sanitized_url_params) %> - <%= submit_tag 'Add Cart and Selected Contacts to Mail Campaign' %>
+ <%= submit_tag 'Add Cart and Contacts' %>
<% if !@session_user.active_campaign.nil? %> - <%= link_to show_icon_with_text(:email_delete, 'Delete my Active Mail Campaign'), @session_user.active_campaign, :confirm => "Are you sure you want to delete \"#{@session_user.active_campaign.title}\"?", :method => :delete %> + <%= link_to show_icon_with_text(:email_delete, 'Deactivate'), freemailer_campaign_clear_active_path(:_redirect_to => url_for(sanitized_url_params)) %> <% end%> <% end %> diff --git a/public/stylesheets/base.css b/public/stylesheets/base.css index d5e738b..e2bc167 100644 --- a/public/stylesheets/base.css +++ b/public/stylesheets/base.css @@ -38,6 +38,15 @@ h1 { font-weight: normal; } +#error{ + margin: .5em auto; + padding: .5em; + background: red; + color: white; + font-weight: bold; + width: 90%; +} + h2 { font-size: 220%; } @@ -289,9 +298,12 @@ dt { } #right-column .pui-autocomplete-holder{ - width: 300px !important; + width: 250px !important; } +.pui-autocomplete-input{ + width: 300px; +} span.tag-display a{ text-decoration: none; @@ -403,4 +415,4 @@ span.tag-display span { .contact-cart-name { float: left; -} \ No newline at end of file +}