fixes for contacts import;flash fixes

master
Wojciech Todryk 2011-09-16 22:08:30 +02:00
parent 2afeebad53
commit bb3289e0d4
6 changed files with 24 additions and 20 deletions

View File

@ -82,13 +82,17 @@ class ContactsController < ApplicationController
tmp_file.flush tmp_file.flush
tmp_file.rewind tmp_file.rewind
tmp_file.readlines.each do |line| tmp_file.readlines.each do |line|
next if line =~ /^#/
Contact.import(@current_user,line) Contact.import(@current_user,line)
end end
rescue Exception => e rescue ActiveRecord::RecordInvalid => e
flash[:error] = e.to_s flash[:error] = {:title => e.to_s,:info => e.record.inspect + e.record.errors.inspect}
rescue Exception => e
flash[:error] = e.to_s
else
flash[:notice] = t(:were_imported,:scope=>:contact)
end end
end end
flash[:notice] = t(:were_imported,:scope=>:contact) if not flash[:error]
redirect_to :action => 'index' redirect_to :action => 'index'
end end

View File

@ -4,14 +4,14 @@ class Contact < ActiveRecord::Base
validates_length_of :first_name,:last_name, :within => 3..20 validates_length_of :first_name,:last_name, :within => 3..20
validates_length_of :email, :within => 5..50 validates_length_of :email, :within => 5..50
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates_length_of :info, :maximum => 50 validates_length_of :info, :maximum => 100
validate :check_unique_nick, :on => :create validate :check_unique_nick, :on => :create
default_scope :order => 'nick ASC'
belongs_to :user belongs_to :user
def self.getPageForUser(user,page,sort_field,sort_dir) def self.getPageForUser(user,page,sort_field,sort_dir)
order = 'last_name asc'
if sort_field if sort_field
if Contact.attribute_method?(sort_field) == true if Contact.attribute_method?(sort_field) == true
order = sort_field order = sort_field
@ -44,11 +44,11 @@ class Contact < ActiveRecord::Base
def self.import(user,line) def self.import(user,line)
fields = line.split(/;/) fields = line.split(/;/)
contact = user.contacts.build( :nick => fields[0], contact = user.contacts.build( :nick => fields[0].strip,
:first_name => fields[1], :first_name => fields[1].strip,
:last_name => fields[2], :last_name => fields[2].strip,
:email => fields[3], :email => fields[3].strip,
:info => fields[4]) :info => fields[4].strip)
contact.save! contact.save!
end end
end end

View File

@ -1,2 +0,0 @@
class Event < ActiveRecord::Base
end

View File

@ -583,3 +583,8 @@ div.logo {
div#logo { div#logo {
background-color: #EFF3E4; background-color: #EFF3E4;
} }
div.flash p.info {
text-align: left;
font-size: 10px;
}

View File

@ -2,6 +2,10 @@
<%= form_tag(contacts_external_path, :multipart => true) %> <%= form_tag(contacts_external_path, :multipart => true) %>
<label for="upload_file"><%= t(:select_file,:scope=>:compose) %></label>:&nbsp; <label for="upload_file"><%= t(:select_file,:scope=>:compose) %></label>:&nbsp;
<%= file_field 'upload', 'datafile' %> <%= file_field 'upload', 'datafile' %>
<% if @contacts.size.zero? %>
<%= raw single_action('import','contact','right.png') %>
<% else %>
<%= raw group_action(@ei_buttons) %> <%= raw group_action(@ei_buttons) %>
<% end %>
</form> </form>
</div> </div>

View File

@ -28,14 +28,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<%= yield :sidebar %> <%= yield :sidebar %>
</div> </div>
<div id="main"> <div id="main">
<div class="flash"> <%= render :partial=>'layouts/flash', :object => flash %>
<% flash.each do |key, msg| %>
<% unless msg.blank? %>
<%= content_tag(:div,(content_tag :p, msg), :class => "message #{key.to_s}" )%>
<%= flash[key.to_sym]='' %>
<% end %>
<% end %>
</div>
<%= yield %> <%= yield %>
</div> </div>
<br class="clear"/> <br class="clear"/>