Multiple fixes in contacts

This commit is contained in:
Emilio Blanco 2011-03-27 15:53:06 -03:00
parent 799802957d
commit 231b1e1d1c
7 changed files with 44 additions and 31 deletions

View file

@ -249,7 +249,7 @@ class ContactsController < 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=>"index", :id=>group_id, :params=>{"mode"=>params["mode"]})
end end
def edit def edit
@ -273,12 +273,11 @@ class ContactsController < ApplicationController
@groups[g.id] = 0 # unchecked @groups[g.id] = 0 # unchecked
end end
} }
render :action => "add" render :action => "new"
end end
# Insert or update # Insert or update
def create def create
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"])
@ -311,10 +310,10 @@ class ContactsController < ApplicationController
end end
} }
if @contact.save if @contact.save
if params["paction"] == _('Save') if params["paction"] == t(:save)
redirect_to :controller => "/contacts/contact", :action =>"list" redirect_to :action =>:index
else else
redirect_to :controller => "/contacts/contact", :action =>"add" redirect_to :action => :new
end end
else else
loadLists loadLists
@ -326,13 +325,13 @@ class ContactsController < ApplicationController
@groups[g.id] = 0 @groups[g.id] = 0
end end
} }
redirect_to contacts_path render :action => :new
end end
end end
def delete def delete
Contact.destroy(params['id']) Contact.destroy(params['id'])
redirect_to(:action=>'list') redirect_to(:action=>'index')
end end
protected protected

View file

@ -47,23 +47,23 @@ class Contact < ActiveRecord::Base
protected protected
def validate def validate
errors.add 'fname', _('Please enter your first name (2 to 20 characters).') unless self.fname =~ /^.{2,20}$/i errors.add 'fname', I18n.t(:validate_fname_error) unless self.fname =~ /^.{2,20}$/i
errors.add 'lname', _('Please enter your surname (2 to 20 characters).') unless self.lname =~ /^.{2,20}$/i errors.add 'lname', I18n.t(:validate_lname_error) unless self.lname =~ /^.{2,20}$/i
# Contact e-mail cannot be changed # Contact e-mail cannot be changed
unless self.new_record? unless self.new_record?
old_record = Contact.find(self.id) old_record = Contact.find(self.id)
errors.add 'email', _('Contacts email cannot be changed.') unless old_record.email == self.email errors.add 'email', I18n.t(:contacto_cannot_be_changed) unless old_record.email == self.email
end end
end end
def validate_on_create def validate_on_create
# Contact e-mail cannot be changed, so we only need to validate it on create # Contact e-mail cannot be changed, so we only need to validate it on create
errors.add 'email', _('Please enter a valid email address.') unless valid_email?(self.email) errors.add 'email', I18n.t(:validate_email_error) unless valid_email?(self.email)
# Already existing e-mail in contacts for this user is not allowed # Already existing e-mail in contacts for this user is not allowed
if self.new_record? if self.new_record?
if Contact.find :first, :conditions => {:email => email, :customer_id => customer_id} if Contact.find :first, :conditions => {:email => email, :customer_id => customer_id}
errors.add('email', _('An account for your email address already exists.')) errors.add('email', I18n.t(:email_exists))
end end
end end
end end

View file

@ -1,26 +1,26 @@
<h1><%=_('Add multiple contacts')%></h1> <h1><%=t :add_multiple_contacts %></h1>
<% if @flash["errors"] and not @flash["errors"].empty?%> <% if flash["errors"] and not flash["errors"].empty?%>
<%= _('Errors')%> <%= t(:errors)%>
<ul> <ul>
<% @flash["errors"].each do |message| %> <% flash["errors"].each do |message| %>
<li><%= message %> <li><%= message %>
<% end %> <% end %>
</ul> </ul>
<% end %> <% end %>
<form action="<%=link_import_preview%>" enctype="multipart/form-data" method="post"> <form action="<%=link_import_preview%>" enctype="multipart/form-data" method="post">
<%= radio_button("contact", "file_type", "1")%> <%= _('Comma-separated (CSV) file')%> <%= radio_button("contact", "file_type", "1")%> <%= t(:csv_file)%>
<%= radio_button("contact", "file_type", "2")%> <%= _('Tab-delimited text file')%> <%= radio_button("contact", "file_type", "2")%> <%= t(:tab_file)%>
<table> <table>
<tr> <tr>
<th><label for="contact[data]"><%=_('Select file')%></label></th> <th><label for="contact[data]"><%=t(:select_file)%></label></th>
<td><input type="file" name="contact[data]"/></td> <td><input type="file" name="contact[data]"/></td>
</tr> </tr>
<tr> <tr>
<td colspan=2> <td colspan=2>
<input type="submit" value="<%=_('Import')%>"/> <input type="submit" value="<%= t(:import)%>"/>
<input type="button" value="<%= _('Back to contacts')%>" onclick="window.location='<%=link_contact_list%>'"> <input type="button" value="<%= t(:back_to_contacts)%>" onclick="window.location='<%=contacts_url%>'">
<input type="button" value="<%= _('Back to folders')%>" onclick="window.location='<%=link_main_index%>'"> <input type="button" value="<%= t(:back_to_folders)%>" onclick="window.location='<%=url_for(:controller => :webmail)%>'">
</td> </td>
</tr> </tr>
</table> </table>
</form> </form>

View file

@ -1,9 +1,9 @@
<h1><%= _('Contacts You Are About To Import')%></h1> <h1><%= _('Contacts You Are About To Import')%></h1>
<% if @flash["errors"] and not @flash["errors"].empty?%> <% if flash["errors"] and not flash["errors"].empty?%>
<%= _('Errors')%> <%= _('Errors')%>
<ul> <ul>
<% @flash["errors"].each do |message| %> <% flash["errors"].each do |message| %>
<li><%= message %> <li><%= message %>
<% end %> <% end %>
</ul> </ul>

View file

@ -8,7 +8,7 @@
<li><span><%= t :contacts %></span> <li><span><%= t :contacts %></span>
<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_to t(:add_multiple), add_multiple_contacts_path %></li>
<% if ret = session["return_to"] %> <% if ret = session["return_to"] %>
<li><%=link_to(t(:back_to_message), ret) %></li> <li><%=link_to(t(:back_to_message), ret) %></li>
<% end %> <% end %>
@ -100,9 +100,11 @@
</tr> </tr>
<% for contact in @contacts %> <% for contact in @contacts %>
<tr class="<%= alternator %>"> <tr class="<%= alternator %>">
<td><%= link_to(contact.full_name, :controller=>"/contacts/contact", :action => "edit", :id => contact.id ) %></td> <td><%= link_to(contact.full_name, :controller=>:contacts, :action => "edit", :id => contact.id ) %></td>
<td><%= link_to( contact.email, :controller => "/webmail", :action => "compose", :params => { "mail[to]" => contact.email } ) %></td> <td><%= link_to( contact.email, :controller => :webmail, :action => "compose", :params => { "mail[to]" => contact.email } ) %></td>
<td><%= link_to(_('delete'), {:controller=>'/contacts/contact', :action=>'delete', :id=>contact.id}, {:confirm=>sprintf(_('DELETE CONTACT?\r\n\Name - %s\r\nE-mail - %s'), contact.show_name, contact.email)})%></td> <td><%= link_to(t(:delete), {:controller=>:contacts, :action=>'delete', :id=>contact.id},
{:confirm=>t(:delete_contact_question, :name => contact.show_name, :email => contact.email)})%>
</td>
</tr> </tr>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -60,9 +60,21 @@ es-ES:
cancel: Cancelar cancel: Cancelar
add_one_contact: Agregar un contacto add_one_contact: Agregar un contacto
add_multiple: Agregar multiples add_multiple: Agregar multiples
add_multiple_contacts: Agregar multiples contactos
name: nombre name: nombre
add_folder: Agregar carpeta add_folder: Agregar carpeta
total_messages: Mensajes totales total_messages: Mensajes totales
unseen: No leidos unseen: No leidos
edit_create_contact: Editar o crear contacto edit_create_contact: Editar o crear contacto
back_to_contacts: Volver a contactos back_to_contacts: Volver a contactos
email_exists: Una cuenta con ese correo electr&oacute;nico ya existe.
delete_contact_question: "Desea borrar este contacto? {{name}} - {{email}}"
validate_fname_error: Por favor, ingrese un nombre (2 a 20 caracteres)
validate_lname_error: Por favor, ingrese un apellido (2 a 20 caracteres)
validate_email_error: Por favor, ingrese una direcci&oacute;n email v&aacute;lida.
contact_cannot_be_changed: El email del contacto no puede ser cambiado
csv_file: Archivo separado por comas(CSV)
tab_file: Archivo separado por tabulaciones
select_file: Selecionar archivo
import: Importar
back_to_folders: Volver a carpetas

View file

@ -1,6 +1,6 @@
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
map.resources :folders, :requirements => {:id => /[^\/]+/} map.resources :folders, :requirements => {:id => /[^\/]+/}
map.resources :contacts, :member => {:add_from_mail => :get} map.resources :contacts, :member => {:add_from_mail => :get}, :collection => {:add_multiple => :get}
map.resources :contact_groups map.resources :contact_groups
# Add your own custom routes here. # Add your own custom routes here.