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