Multiple fixes in contacts

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

View File

@ -47,23 +47,23 @@ class Contact < ActiveRecord::Base
protected
def validate
errors.add 'fname', _('Please enter your first name (2 to 20 characters).') 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 'fname', I18n.t(:validate_fname_error) unless self.fname =~ /^.{2,20}$/i
errors.add 'lname', I18n.t(:validate_lname_error) unless self.lname =~ /^.{2,20}$/i
# Contact e-mail cannot be changed
unless self.new_record?
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
def validate_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
if self.new_record?
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

View File

@ -1,26 +1,26 @@
<h1><%=_('Add multiple contacts')%></h1>
<% if @flash["errors"] and not @flash["errors"].empty?%>
<%= _('Errors')%>
<h1><%=t :add_multiple_contacts %></h1>
<% if flash["errors"] and not flash["errors"].empty?%>
<%= t(:errors)%>
<ul>
<% @flash["errors"].each do |message| %>
<% flash["errors"].each do |message| %>
<li><%= message %>
<% end %>
</ul>
<% end %>
<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", "2")%> <%= _('Tab-delimited text file')%>
<%= radio_button("contact", "file_type", "1")%> <%= t(:csv_file)%>
<%= radio_button("contact", "file_type", "2")%> <%= t(:tab_file)%>
<table>
<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>
</tr>
<tr>
<td colspan=2>
<input type="submit" value="<%=_('Import')%>"/>
<input type="button" value="<%= _('Back to contacts')%>" onclick="window.location='<%=link_contact_list%>'">
<input type="button" value="<%= _('Back to folders')%>" onclick="window.location='<%=link_main_index%>'">
<input type="submit" value="<%= t(:import)%>"/>
<input type="button" value="<%= t(:back_to_contacts)%>" onclick="window.location='<%=contacts_url%>'">
<input type="button" value="<%= t(:back_to_folders)%>" onclick="window.location='<%=url_for(:controller => :webmail)%>'">
</td>
</tr>
</table>
</form>
</form>

View File

@ -1,9 +1,9 @@
<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')%>
<ul>
<% @flash["errors"].each do |message| %>
<% flash["errors"].each do |message| %>
<li><%= message %>
<% end %>
</ul>

View File

@ -8,7 +8,7 @@
<li><span><%= t :contacts %></span>
<ul id="secondary">
<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"] %>
<li><%=link_to(t(:back_to_message), ret) %></li>
<% end %>
@ -100,9 +100,11 @@
</tr>
<% for contact in @contacts %>
<tr class="<%= alternator %>">
<td><%= link_to(contact.full_name, :controller=>"/contacts/contact", :action => "edit", :id => contact.id ) %></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(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(t(:delete), {:controller=>:contacts, :action=>'delete', :id=>contact.id},
{:confirm=>t(:delete_contact_question, :name => contact.show_name, :email => contact.email)})%>
</td>
</tr>
<% end %>
<% end %>

View File

@ -60,9 +60,21 @@ es-ES:
cancel: Cancelar
add_one_contact: Agregar un contacto
add_multiple: Agregar multiples
add_multiple_contacts: Agregar multiples contactos
name: nombre
add_folder: Agregar carpeta
total_messages: Mensajes totales
unseen: No leidos
edit_create_contact: Editar o crear contacto
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|
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
# Add your own custom routes here.