Contacts page

This commit is contained in:
Eugene Korbut 2009-02-08 04:46:42 +10:00
parent 02a3200143
commit 0199223976
8 changed files with 44 additions and 51 deletions

View file

@ -1,11 +1,4 @@
class Contacts::ContactController < ApplicationController class ContactController < ApplicationController
uses_component_template_root
model :customer
model :contact
model :contact_group
helper :pagination
layout :select_layout layout :select_layout
def index def index
@ -13,12 +6,12 @@ class Contacts::ContactController < ApplicationController
end end
def list def list
@contact_pages = Paginator.new(self, Contact.count("customer_id = #{logged_user}"), CDF::CONFIG[:contacts_per_page], @params['page']) @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) @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["mode"] == "groups"
if @params["id"] and not @params["id"].nil? and not @params["id"] == '' if params["id"] and not params["id"].nil? and not params["id"] == ''
@group_id = @params["id"].to_i @group_id = params["id"].to_i
@contacts_for_group = Hash.new @contacts_for_group = Hash.new
for contact in @contacts for contact in @contacts
@contacts_for_group[contact.id] = 0 # initialize @contacts_for_group[contact.id] = 0 # initialize
@ -35,13 +28,13 @@ class Contacts::ContactController < ApplicationController
def listLetter def listLetter
letters = CDF::CONFIG[:contact_letters] letters = CDF::CONFIG[:contact_letters]
@contact_pages = Paginator.new(self, Contact.count( @contact_pages = Paginator.new(self, Contact.count(
["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[@params['id'].to_i]]), CDF::CONFIG[:contacts_per_page], @params['page']) ["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[params['id'].to_i]]), CDF::CONFIG[:contacts_per_page], params['page'])
@contacts = Contact.find(:all, :conditions=>["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[@params['id'].to_i]], @contacts = Contact.find(:all, :conditions=>["customer_id = %s and substr(UPPER(fname),1,1) = '%s'", logged_user, letters[params['id'].to_i]],
:order=>['fname'], :limit=>CDF::CONFIG[:contacts_per_page], :offset=>@contact_pages.current.offset) :order=>['fname'], :limit=>CDF::CONFIG[:contacts_per_page], :offset=>@contact_pages.current.offset)
if @params["mode"] == "groups" if params["mode"] == "groups"
if @params["group_id"] and not @params["group_id"].nil? and not @params["group_id"] == '' if params["group_id"] and not params["group_id"].nil? and not params["group_id"] == ''
@group_id = @params["group_id"].to_i @group_id = params["group_id"].to_i
@contacts_for_group = Hash.new @contacts_for_group = Hash.new
for contact in @contacts for contact in @contacts
@contacts_for_group[contact.id] = 0 # initialize @contacts_for_group[contact.id] = 0 # initialize
@ -78,8 +71,8 @@ class Contacts::ContactController < ApplicationController
end end
def add_from_mail def add_from_mail
cstr = @params['cstr'] cstr = params['cstr']
retmsg = @params['retmsg'] retmsg = params['retmsg']
@session["return_to"] = url_for(:controller=>'/webmail/webmail', @session["return_to"] = url_for(:controller=>'/webmail/webmail',
:action=>'folders', :action=>'folders',
:msg_id=>retmsg) :msg_id=>retmsg)
@ -132,18 +125,18 @@ class Contacts::ContactController < ApplicationController
end end
def import_preview def import_preview
file = @params["contact"]["data"] file = params["contact"]["data"]
flash["errors"] = Array.new flash["errors"] = Array.new
if file.size == 0 if file.size == 0
flash["errors"] << _('You haven\'t selected file or the file is empty') flash["errors"] << _('You haven\'t selected file or the file is empty')
@contact = Contact.new @contact = Contact.new
@contact["file_type"] = @params["contact"]["file_type"] @contact["file_type"] = params["contact"]["file_type"]
render :action => "add_multiple" render :action => "add_multiple"
end end
file_type = @params["contact"]["file_type"] file_type = params["contact"]["file_type"]
if file_type.nil? or file_type == '1' if file_type.nil? or file_type == '1'
separator = ',' separator = ','
else else
@ -174,8 +167,8 @@ class Contacts::ContactController < ApplicationController
end end
def import def import
contacts_count = @params["contact"].length contacts_count = params["contact"].length
contacts_to_import = @params["contact"] contacts_to_import = params["contact"]
@contacts = Array.new @contacts = Array.new
emails = Array.new emails = Array.new
@ -238,27 +231,27 @@ class Contacts::ContactController < ApplicationController
def choose def choose
if @params["mode"] == "groups" if params["mode"] == "groups"
save_groups save_groups
end end
@tos, @ccs, @bccs = Array.new, Array.new, Array.new @tos, @ccs, @bccs = Array.new, Array.new, Array.new
@params["contacts_to"].each{ |id,value| @tos << Contact.find(id) if value == "1" } if @params["contacts_to"] params["contacts_to"].each{ |id,value| @tos << Contact.find(id) if value == "1" } if params["contacts_to"]
@params["contacts_cc"].each{ |id,value| @ccs << Contact.find(id) if value == "1" } if @params["contacts_cc"] params["contacts_cc"].each{ |id,value| @ccs << Contact.find(id) if value == "1" } if params["contacts_cc"]
@params["contacts_bcc"].each{ |id,value| @bccs << Contact.find(id) if value == "1" } if @params["contacts_bcc"] params["contacts_bcc"].each{ |id,value| @bccs << Contact.find(id) if value == "1" } if params["contacts_bcc"]
@params["groups_to"].each{ |id,value| params["groups_to"].each{ |id,value|
ContactGroup.find(id).contacts.each {|c| @tos << c} if value == "1" } if @params["groups_to"] ContactGroup.find(id).contacts.each {|c| @tos << c} if value == "1" } if params["groups_to"]
@params["groups_cc"].each{ |id,value| params["groups_cc"].each{ |id,value|
ContactGroup.find(id).contacts.each {|c| @ccs << c} if value == "1" } if @params["groups_cc"] ContactGroup.find(id).contacts.each {|c| @ccs << c} if value == "1" } if params["groups_cc"]
@params["groups_bcc"].each{ |id,value| params["groups_bcc"].each{ |id,value|
ContactGroup.find(id).contacts.each {|c| @bccs << c} if value == "1" } if @params["groups_bcc"] ContactGroup.find(id).contacts.each {|c| @bccs << c} if value == "1" } if params["groups_bcc"]
end end
def save_groups def save_groups
contacts_for_group = @params["contacts_for_group"] contacts_for_group = params["contacts_for_group"]
group_id = @params["group_id"] group_id = params["group_id"]
contact_group = ContactGroup.find(group_id) contact_group = ContactGroup.find(group_id)
@ -271,11 +264,11 @@ class Contacts::ContactController < ApplicationController
contact_group.contacts.delete(contact) contact_group.contacts.delete(contact)
end end
} }
redirect_to(:action=>"list", :id=>group_id, :params=>{"mode"=>@params["mode"]}) redirect_to(:action=>"list", :id=>group_id, :params=>{"mode"=>params["mode"]})
end end
def edit def edit
@contact = Contact.find(@params["id"]) @contact = Contact.find(params["id"])
# load related lists # load related lists
loadLists loadLists
@ -301,18 +294,18 @@ class Contacts::ContactController < ApplicationController
# Insert or update # Insert or update
def save def save
logger.info("BEGIN") logger.info("BEGIN")
if @params["contact"]["id"] == "" if params["contact"]["id"] == ""
# New contact # New contact
@contact = Contact.create(@params["contact"]) @contact = Contact.create(params["contact"])
else else
# Edit existing # Edit existing
@contact = Contact.find(@params["contact"]["id"]) @contact = Contact.find(params["contact"]["id"])
@contact.attributes = @params["contact"] @contact.attributes = params["contact"]
end end
@contactgroups = ContactGroup.find_by_user(logged_user) @contactgroups = ContactGroup.find_by_user(logged_user)
# Groups displayed # Groups displayed
groups = @params['groups'] groups = params['groups']
tempGroups = Array.new tempGroups = Array.new
tempGroups.concat(@contact.groups) tempGroups.concat(@contact.groups)
@ -333,7 +326,7 @@ class Contacts::ContactController < ApplicationController
end end
} }
if @contact.save if @contact.save
if @params["paction"] == _('Save') if params["paction"] == _('Save')
redirect_to :controller => "/contacts/contact", :action =>"list" redirect_to :controller => "/contacts/contact", :action =>"list"
else else
redirect_to :controller => "/contacts/contact", :action =>"add" redirect_to :controller => "/contacts/contact", :action =>"add"
@ -353,7 +346,7 @@ class Contacts::ContactController < ApplicationController
end end
def delete def delete
Contact.destroy(@params['id']) Contact.destroy(params['id'])
redirect_to(:action=>'list') redirect_to(:action=>'list')
end end
@ -377,11 +370,11 @@ class Contacts::ContactController < ApplicationController
end end
private private
def select_layout def select_layout
if @params["mode"] == "choose" if params["mode"] == "choose"
@mode = "choose" @mode = "choose"
@contactgroups = ContactGroup.find_by_user(logged_user) @contactgroups = ContactGroup.find_by_user(logged_user)
'chooser' 'chooser'
elsif @params["mode"] == "groups" elsif params["mode"] == "groups"
@mode = "groups" @mode = "groups"
'public' 'public'
else else

View file

@ -1,4 +1,4 @@
module Contacts::ContactHelper module ContactHelper
def link_import_preview() "/contacts/contact/import_preview" end def link_import_preview() "/contacts/contact/import_preview" end
def link_main_index() "/webmail/webmail/folders" end def link_main_index() "/webmail/webmail/folders" end
def link_contact_save() "/contacts/contact/save" end def link_contact_save() "/contacts/contact/save" end

View file

@ -9,7 +9,7 @@
<ul id="secondary"> <ul id="secondary">
<li><%=link_contact_add_one%></li> <li><%=link_contact_add_one%></li>
<li><%=link_contact_add_multiple%></li> <li><%=link_contact_add_multiple%></li>
<% if ret = @session["return_to"] %> <% if ret = session["return_to"] %>
<li><%=link_to(_('Back to message'), ret) %></li> <li><%=link_to(_('Back to message'), ret) %></li>
<% end %> <% end %>
</ul> </ul>
@ -20,7 +20,7 @@
<div id="tab_main"> <div id="tab_main">
<div id="tab_content"> <div id="tab_content">
<% if @flash["alert"] %><ul><li><%= @flash["alert"] %></li></ul><% end %> <% if flash["alert"] %><ul><li><%= flash["alert"] %></li></ul><% end %>
<form action="<%=link_contact_choose%>?mode=<%=@mode%>" method="post"> <form action="<%=link_contact_choose%>?mode=<%=@mode%>" method="post">
<input type="hidden" name="mode" value="<%=@mode%>"/> <input type="hidden" name="mode" value="<%=@mode%>"/>
<% if @group_id and not @group_id.nil? %> <% if @group_id and not @group_id.nil? %>
@ -39,7 +39,7 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="3"><%= @contact_pages.basic_html(self, 2, false, {"mode"=>@mode}) %></td> <td colspan="3"><%= pagination_links @contact_pages, {}, :mode => @mode %></td>
</tr> </tr>
<% if @mode == "choose" %> <% if @mode == "choose" %>
<tr> <tr>