Skip to content

Commit

Permalink
Fix routing, bulk tagging, UI and other issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
djcp committed Apr 29, 2010
1 parent c763700 commit 00c9625
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 29 deletions.
12 changes: 5 additions & 7 deletions app/controllers/admin/bulk_action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.'
Expand All @@ -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
Expand All @@ -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?
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/contact_carts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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 <tt>nil</tt>.
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
Expand Down Expand Up @@ -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 <tt>params[:contact_to_remove_id]</tt> from the user's active contact cart
Expand All @@ -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

Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/freemailer_campaigns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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
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
Expand All @@ -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
Expand Down Expand Up @@ -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" }
Expand All @@ -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" }
Expand All @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions app/models/contact_cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ')
Expand Down
2 changes: 2 additions & 0 deletions app/models/freemailer_campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions app/views/contact_carts/_bulk_action.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<h4 id="flyout-bulk-contact-cart" class="toggle hidden tags sub-action"><%= icon(:cart) %>Contact Cart</h4>

<div id="flyout-bulk-contact-cart-actions" class="toggle-target tags sub-action" style="display: none;">
<% cart = @session_user.active_contact_cart %>
<% if !cart.nil? %>
<b><%= "#{cart.title} (#{cart.contacts.count} )" %></b>
<h4><%= "#{cart.title} (#{cart.contacts.count})" %></h4>
<%= render :partial => 'contact_carts/contacts', :locals => { :cart => cart } %>
<% end %>
<% form_tag(url_for(:controller=>'/contact_carts',:action=>:create), :id => 'bulk-contact-cart') do %>
Expand All @@ -14,12 +13,11 @@
<% end %>
<%= hidden_field_tag '_redirect_to', url_for(sanitized_url_params) %>
<% if cart.nil? || (cart && @session_user == cart.user) %>
<%= submit_tag 'Add Selected Contacts to Cart' %>
<%= submit_tag 'Add Contacts' %>
<br/>
<% end %>
<%= link_to show_icon_with_text(:briefcase, "Manage Saved Carts"), contact_carts_path %>
<% if !cart.nil? && @session_user == cart.user %>
<%= link_to show_icon_with_text(:cart_delete, 'Delete Active'), cart, :confirm => "Are you sure you want to delete your active contact cart?", :method => :delete, :controller => 'admin/contact_carts' %>
<%= link_to show_icon_with_text(:cart_delete, 'Deactivate'), contact_cart_clear_active_path(:_redirect_to => url_for(sanitized_url_params)) %>
<% end %>
<% end %>
</div>
6 changes: 4 additions & 2 deletions app/views/shared/_bulk_contact_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ Due Date: <%= calendar_date_select_tag "follow_up", '', :time => true, :minute_i
<% if @session_user.active_campaign.nil? %>
<label for="title">Title:</label> <%= text_field_tag 'title',"#{@session_user.username} - #{Date.today}" %>
<br/>
<% else %>
<h4><%= h @session_user.active_campaign.title %> (<%= @session_user.active_campaign.contacts.length %>)</h4>
<% end %>
<%= hidden_field_tag '_redirect_to', url_for(sanitized_url_params) %>
<%= submit_tag 'Add Cart and Selected Contacts to Mail Campaign' %><br/>
<%= submit_tag 'Add Cart and Contacts' %><br/>
<% 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 %>
</div>
Expand Down
16 changes: 14 additions & 2 deletions public/stylesheets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -403,4 +415,4 @@ span.tag-display span {

.contact-cart-name {
float: left;
}
}

0 comments on commit 00c9625

Please sign in to comment.