Skip to content

Commit

Permalink
Working on Ajax modal+pagination status delivery messages - Does not …
Browse files Browse the repository at this point in the history
…work yet
  • Loading branch information
Ryan Neufeld committed Aug 5, 2009
1 parent e8aaec8 commit c043e1f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin/freemailer_campaigns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def send_campaign
end

def statuses
statuses = FreemailerCampaignContact.paginate(:page => params[:page], :order => 'created_at DESC')
statuses = FreemailerCampaignContact.paginate(:page => params[:page], :order => 'created_at DESC', :per_page => 5)
render :partial => 'statuses', :locals => { :statuses => statuses,
:campaign => @freemailer_campaign, :per_page => 10 }
:campaign => @freemailer_campaign }
end

# ############## Restful Actions ##############################
Expand Down
48 changes: 48 additions & 0 deletions app/helpers/freemailer_campaigns_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
module FreemailerCampaignsHelper
end

class StatusPaginationModalSwitchRenderer < WillPaginate::LinkRenderer
def to_html
links = @options[:page_links] ? windowed_links : []

links.unshift(page_link_or_span(@collection.previous_page, 'previous', @options[:previous_label]))
links.push(page_link_or_span(@collection.next_page, 'next', @options[:next_label]))

html = links.join(@options[:separator])
end

protected

def windowed_links
visible_page_numbers.map { |n| page_link_or_span(n, (n == current_page ? 'current' : nil)) }
end

def page_link_or_span(page, span_class, text = nil)
text ||= page.to_s
if page && page != current_page
page_link(page, text, :class => span_class)
else
page_span(page, text, :class => span_class)
end
end

def page_link(page, text, attributes = {})
onclick = <<-EOS
var old_page=Modalbox.content;
var new_page;
if(old_page.endsWith('statuses')){
new_page=old_page+'?page='+#{page};
}else{
new_page=old_page.gsub(/(\d+)$/,#{page});
}
alert(new_page);
EOS

<<-EOS
<a onclick="#{onclick}; Modalbox.show(text,new_page,{title: Modalbox.title, width: '450'});" href="#">#{text}</a>
EOS
end

def page_span(page, text, attributes = {})
@template.content_tag(:span, text, attributes)
end

end
21 changes: 11 additions & 10 deletions app/views/freemailer_campaigns/_statuses.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
%table
%tr
%th Contact
%th Email
%th Status
- statuses.each do |status|
#delivery_statuses
%table
%tr
%td= status.contact.name_for_display
%td= status.contact.primary_email
%td= status.delivery_status || "Pending"
= will_paginate(statuses)
%th Contact
%th Email
%th Status
- statuses.each do |status|
%tr
%td= status.contact.name_for_display
%td= status.contact.primary_email
%td= status.delivery_status || "Pending"
= will_paginate(statuses, :renderer => StatusPaginationModalSwitchRenderer)

0 comments on commit c043e1f

Please sign in to comment.