Skip to content

Commit

Permalink
Re-use index action for spam, too. Added pagination!
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Dec 28, 2010
1 parent a6e7f55 commit ec4af21
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 48 deletions.
21 changes: 15 additions & 6 deletions app/controllers/admin/inquiries_controller.rb
@@ -1,19 +1,20 @@
class Admin::InquiriesController < Admin::BaseController

crudify :inquiry, :title_attribute => "name", :order => "created_at DESC"
helper_method :group_by_date

before_filter :find_all_ham, :only => [:ham]
before_filter :find_all_spam, :only => [:spam]
before_filter :get_spam_count, :only => [:index, :spam]

def index
@inquiries = Inquiry.ham.with_query(params[:search]) if searching?

@grouped_inquiries = group_by_date(Inquiry.ham)
@inquiries = @inquiries.with_query(params[:search]) if searching?
@inquiries = @inquiries.paginate({:page => params[:page]})
end

def spam
@inquiries = Inquiry.spam.with_query(params[:search]) if searching?

@grouped_inquiries = group_by_date(Inquiry.spam)
self.index
render :action => 'index'
end

def toggle_spam
Expand All @@ -25,6 +26,14 @@ def toggle_spam

protected

def find_all_ham
@inquiries = Inquiry.ham
end

def find_all_spam
@inquiries = Inquiry.spam
end

def get_spam_count
@spam_count = Inquiry.count(:conditions => {:spam => true})
end
Expand Down
10 changes: 7 additions & 3 deletions app/views/admin/inquiries/index.html.erb
Expand Up @@ -3,23 +3,27 @@
<% if searching? %>
<h2><%= t('shared.admin.search.results_for', :query => params[:search]) %></h2>
<% if @inquiries.any? %>
<%= will_paginate @inquiries %>
<ul>
<%= render :partial => "inquiry", :collection => @inquiries %>
</ul>
<%= will_paginate @inquiries %>
<% else %>
<p><%= t('shared.admin.search.no_results') %></p>
<% end %>
<% else %>
<% if @grouped_inquiries.any? -%>
<% @grouped_inquiries.each do |container| %>
<% if @inquiries.any? -%>
<%= will_paginate @inquiries %>
<% group_by_date(@inquiries).each do |container| %>
<h3><%= l((inquiry_group = container.last).first.created_at, :format => :short) %></h3>
<ul>
<%= render :partial => 'inquiry', :collection => inquiry_group %>
</ul>
<% end %>
<%= will_paginate @inquiries %>
<% else -%>
<p>
<strong><%= t('.no_inquiries') %></strong>
<strong><%= t(".no_#{action_name == 'index' ? 'inquiries' : 'spam'}") %></strong>
</p>
<% end -%>
<% end %>
Expand Down
26 changes: 0 additions & 26 deletions app/views/admin/inquiries/spam.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion config/locales/de.yml
Expand Up @@ -22,7 +22,6 @@ de:
edit_confirmation_email: Bestätigungs-E-Mail bearbeiten
index:
no_inquiries: Sie haben noch keine Kontaktanfragen erhalten.
spam:
no_spam: Juhu! Sie haben keinen Spam.
show:
details: Details
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Expand Up @@ -22,7 +22,6 @@ en:
edit_confirmation_email: Edit confirmation email
index:
no_inquiries: You have not received any inquiries yet.
spam:
no_spam: Hooray! You don't have any spam.
show:
details: Details
Expand Down
1 change: 0 additions & 1 deletion config/locales/fr.yml
Expand Up @@ -22,7 +22,6 @@ fr:
edit_confirmation_email: Modifier l'e-mail de confirmation
index:
no_inquiries: Vous n'avez reçu aucune requête.
spam:
no_spam: Vous n'avez aucun spam.
show:
details: Détails
Expand Down
1 change: 0 additions & 1 deletion config/locales/it.yml
Expand Up @@ -24,7 +24,6 @@ it:
edit_confirmation_email: Modifica la mail di conferma
index:
no_inquiries: Non hai ancora ricevuto alcuna richiesta.
spam:
no_spam: Evviva! Non hai alcuno spam
show:
details: Dettagli
Expand Down
1 change: 0 additions & 1 deletion config/locales/lolcat.yml
Expand Up @@ -22,7 +22,6 @@ lolcat:
edit_confirmation_email: EDIT CONFIRMASHUN EMAIL
index:
no_inquiries: U HAS NOT RECEIVD ANY INQUIRIEZ YET.
spam:
no_spam: HOORAH! U DOAN HAS ANY SPAM.
show:
details: DETAILS
Expand Down
1 change: 0 additions & 1 deletion config/locales/lt.yml
Expand Up @@ -22,7 +22,6 @@ lt:
edit_confirmation_email: Redaguoti patvirtinimo laišką
index:
no_inquiries: Kol kas nėra jokių užklausų.
spam:
no_spam: Valio! Jūs neturite jokio spamo.
show:
details: Smulkesnė informacija
Expand Down
1 change: 0 additions & 1 deletion config/locales/lv.yml
Expand Up @@ -22,7 +22,6 @@ lv:
edit_confirmation_email: Labot apstiprinājuma epastu
index:
no_inquiries: Nav saņemts neviens pieprasījums.
spam:
no_spam: Urā! Jums nav neviens pieprasījums, kas būtu spams.
show:
details: Detaļas
Expand Down
1 change: 0 additions & 1 deletion config/locales/nb.yml
Expand Up @@ -40,7 +40,6 @@ nb:
index:
search_results_for: Søkeresultater for %{query}
no_inquiries: Du har ikke mottatt noen forespørsler enda.
spam:
no_spam: Hurra! Du har ikke noen søppelpost.
show:
details: Detaljer
Expand Down
1 change: 0 additions & 1 deletion config/locales/nl.yml
Expand Up @@ -21,7 +21,6 @@ nl:
edit_confirmation_email: Bewerk bevestigings email
index:
no_inquiries: Je hebt nog geen vragen ontvangen.
spam:
no_spam: Jeej! Je hebt geen spam.
show:
details: Details
Expand Down
1 change: 0 additions & 1 deletion config/locales/pl.yml
Expand Up @@ -23,7 +23,6 @@ pl:
edit_confirmation_email: Zmień email z potwierdzeniem
index:
no_inquiries: Nie ma jeszcze żadnych zapytań.
spam:
no_spam: Hurra! Nie masz żadnego spamu.
show:
details: Szczegóły
Expand Down
1 change: 0 additions & 1 deletion config/locales/pt-BR.yml
Expand Up @@ -22,7 +22,6 @@ pt-BR:
edit_confirmation_email: Editar email de confirmação
index:
no_inquiries: "Não exitem mensagens."
spam:
no_spam: Não existem mensagens de spam.
show:
details: Detalhes
Expand Down
1 change: 0 additions & 1 deletion config/locales/ru.yml
Expand Up @@ -22,7 +22,6 @@ ru:
edit_confirmation_email: Редактировать письмо-подтверждение
index:
no_inquiries: "Вы еще не получили ни одного запроса."
spam:
no_spam: "Ура, спама нет!"
show:
details: Подробности
Expand Down
1 change: 0 additions & 1 deletion config/locales/sv.yml
Expand Up @@ -22,7 +22,6 @@ sv:
edit_confirmation_email: Redigera bekräftelse
index:
no_inquiries: Du har inte fått några förfrågningar ännu.
spam:
no_spam: Hurra! Du har ingen skräppost.
show:
details: Detaljer
Expand Down

0 comments on commit ec4af21

Please sign in to comment.