fixes for contacts import;flash fixes
This commit is contained in:
parent
2afeebad53
commit
bb3289e0d4
|
@ -82,13 +82,17 @@ class ContactsController < ApplicationController
|
|||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
next if line =~ /^#/
|
||||
Contact.import(@current_user,line)
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
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
|
||||
flash[:notice] = t(:were_imported,:scope=>:contact) if not flash[:error]
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@ class Contact < ActiveRecord::Base
|
|||
validates_length_of :first_name,:last_name, :within => 3..20
|
||||
validates_length_of :email, :within => 5..50
|
||||
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
|
||||
default_scope :order => 'nick ASC'
|
||||
|
||||
belongs_to :user
|
||||
|
||||
def self.getPageForUser(user,page,sort_field,sort_dir)
|
||||
|
||||
order = 'last_name asc'
|
||||
if sort_field
|
||||
if Contact.attribute_method?(sort_field) == true
|
||||
order = sort_field
|
||||
|
@ -44,11 +44,11 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
def self.import(user,line)
|
||||
fields = line.split(/;/)
|
||||
contact = user.contacts.build( :nick => fields[0],
|
||||
:first_name => fields[1],
|
||||
:last_name => fields[2],
|
||||
:email => fields[3],
|
||||
:info => fields[4])
|
||||
contact = user.contacts.build( :nick => fields[0].strip,
|
||||
:first_name => fields[1].strip,
|
||||
:last_name => fields[2].strip,
|
||||
:email => fields[3].strip,
|
||||
:info => fields[4].strip)
|
||||
contact.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
class Event < ActiveRecord::Base
|
||||
end
|
|
@ -583,3 +583,8 @@ div.logo {
|
|||
div#logo {
|
||||
background-color: #EFF3E4;
|
||||
}
|
||||
|
||||
div.flash p.info {
|
||||
text-align: left;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
<%= form_tag(contacts_external_path, :multipart => true) %>
|
||||
<label for="upload_file"><%= t(:select_file,:scope=>:compose) %></label>:
|
||||
<%= file_field 'upload', 'datafile' %>
|
||||
<% if @contacts.size.zero? %>
|
||||
<%= raw single_action('import','contact','right.png') %>
|
||||
<% else %>
|
||||
<%= raw group_action(@ei_buttons) %>
|
||||
<% end %>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -28,14 +28,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|||
<%= yield :sidebar %>
|
||||
</div>
|
||||
<div id="main">
|
||||
<div class="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>
|
||||
<%= render :partial=>'layouts/flash', :object => flash %>
|
||||
<%= yield %>
|
||||
</div>
|
||||
<br class="clear"/>
|
||||
|
|
Loading…
Reference in a new issue