view contacts by the letter
This commit is contained in:
parent
ce40b31f7a
commit
25bdf4736e
|
@ -2,22 +2,11 @@ class ContactsController < ApplicationController
|
|||
layout :select_layout
|
||||
|
||||
def index
|
||||
@contact_pages = Paginator.new(self, Contact.count("customer_id = #{logged_user}"), CDF::CONFIG[:contacts_per_page], params['page'])
|
||||
@contacts = Contact.find(:all, :conditions=>["customer_id = #{logged_user}"], :order=>['fname'], :limit=>CDF::CONFIG[:contacts_per_page], :offset=>@contact_pages.current.offset)
|
||||
|
||||
if params["mode"] == "groups"
|
||||
if params["id"] and not params["id"].nil? and not params["id"] == ''
|
||||
@group_id = params["id"].to_i
|
||||
@contacts_for_group = Hash.new
|
||||
for contact in @contacts
|
||||
@contacts_for_group[contact.id] = 0 # initialize
|
||||
for gr in contact.groups
|
||||
if gr.contact_group_id.to_i == @group_id
|
||||
@contacts_for_group[contact.id] = 1 # checked
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if params[:letter] && params[:letter].any?
|
||||
@contacts = Contact.for_customer(logged_user).letter(params[:letter]).paginate :page => params[:page],
|
||||
:per_page => CDF::CONFIG[:contacts_per_page]
|
||||
else
|
||||
@contacts = Contact.for_customer(logged_user).paginate :page => params[:page], :per_page => CDF::CONFIG[:contacts_per_page]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@ class Contact < ActiveRecord::Base
|
|||
result
|
||||
end
|
||||
|
||||
named_scope :for_customer, lambda{ |customer_id| {:conditions => {:customer_id => customer_id}} }
|
||||
named_scope :letter, lambda{ |letter| {:conditions => ["contacts.fname LIKE ?", "#{letter}%"]} }
|
||||
|
||||
def Contact.find_by_user_letter(user_id, letter)
|
||||
find_by_sql("select * from contacts where customer_id=#{user_id} and substr(UPPER(fname),1,1) = '#{letter}' order by fname")
|
||||
end
|
||||
|
|
|
@ -29,17 +29,15 @@
|
|||
<table class="list">
|
||||
<tr>
|
||||
<td colspan="4" id="alphaListHeader">
|
||||
<%
|
||||
letters = CDF::CONFIG[:contact_letters]
|
||||
for letterIndex in 0...letters.size
|
||||
letter = letters[letterIndex] %>
|
||||
<%= link_to(letter, :controller=>"contacts", :action=>"listLetter", :id=>letterIndex, :params=>{"mode"=>@mode, "group_id"=>(@group_id ? @group_id : nil)}) %>
|
||||
<% CDF::CONFIG[:contact_letters].each do |letter| %>
|
||||
<%= link_to letter, contacts_path(:letter => letter) %>
|
||||
<% end %>
|
||||
<%= link_to(_('Show all'), :controller=>"contact", :action=>"list", :id=>(@group_id ? @group_id : nil), :params=>{"mode"=>@mode})%>
|
||||
|
||||
<%= link_to _('Show all'), contacts_path %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3"><%= pagination_links @contact_pages, {}, :mode => @mode %></td>
|
||||
<td colspan="3"><%= will_paginate @contacts %></td>
|
||||
</tr>
|
||||
<% if @mode == "choose" %>
|
||||
<tr>
|
||||
|
|
Loading…
Reference in a new issue