devel
This commit is contained in:
parent
b4bc16ed14
commit
2afeebad53
49 changed files with 342 additions and 160 deletions
|
@ -1,10 +1,12 @@
|
|||
require 'tempfile'
|
||||
|
||||
class ContactsController < ApplicationController
|
||||
|
||||
before_filter :check_current_user,:selected_folder, :get_current_folders
|
||||
|
||||
before_filter :get_contacts, :only => [:index]
|
||||
|
||||
before_filter :prepare_ops_buttons, :only => [:index]
|
||||
before_filter :prepare_ops_buttons, :prepare_export_import_buttons,:only => [:index]
|
||||
|
||||
theme :theme_resolver
|
||||
|
||||
|
@ -67,6 +69,40 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def external
|
||||
if params["export"]
|
||||
redirect_to :action => 'export'
|
||||
return
|
||||
elsif params["import"]
|
||||
begin
|
||||
raise t(:no_file_chosen,:scope=>:common) if not params[:upload]
|
||||
raise t(:no_tmp_dir,:scope=>:common) if not File.exists?($defaults["msg_upload_dir"])
|
||||
tmp_file = Tempfile.new($defaults["contact_tmp_filename"],$defaults["msg_upload_dir"])
|
||||
tmp_file.write(params[:upload][:datafile].read)
|
||||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
Contact.import(@current_user,line)
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = e.to_s
|
||||
end
|
||||
end
|
||||
flash[:notice] = t(:were_imported,:scope=>:contact) if not flash[:error]
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
def export
|
||||
contacts = @current_user.contacts
|
||||
s = ""
|
||||
contacts.each do |c|
|
||||
s += c.export + "\r\n"
|
||||
end
|
||||
headers['Content-type'] = "text/csv"
|
||||
headers['Content-Disposition'] = %(attachment; filename="contacts.csv")
|
||||
render :text => s
|
||||
end
|
||||
|
||||
####################################### protected section ################################
|
||||
|
||||
protected
|
||||
|
@ -78,6 +114,12 @@ class ContactsController < ApplicationController
|
|||
@buttons << {:text => 'delete_selected',:scope=>'contact',:image => 'minus.png'}
|
||||
end
|
||||
|
||||
def prepare_export_import_buttons
|
||||
@ei_buttons = []
|
||||
@ei_buttons << {:text => 'import',:scope=>'contact',:image => 'right.png'}
|
||||
@ei_buttons << {:text => 'export',:scope=>'contact',:image => 'left.png'}
|
||||
end
|
||||
|
||||
####################################### private section ##################################
|
||||
|
||||
private
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
class EventsController < ApplicationController
|
||||
end
|
|
@ -144,7 +144,7 @@ class FoldersController < ApplicationController
|
|||
trash_folder.messages.destroy_all
|
||||
trash_folder.update_attributes(:unseen => 0, :total => 0)
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
flash[:error] = "#{t(:imap_error,:scope=>:common)} (#{e.to_s})"
|
||||
end
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
end
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
class InternalController < ApplicationController
|
||||
|
||||
before_filter :check_current_user ,:selected_folder, :get_current_folders, :only => [:about]
|
||||
|
||||
theme :theme_resolver
|
||||
layout "simple"
|
||||
|
||||
|
||||
ERRORS = [
|
||||
:internal_server_error,
|
||||
:not_found,
|
||||
|
@ -43,4 +46,8 @@ class InternalController < ApplicationController
|
|||
redirect_to :controller=>'user', :action => 'login'
|
||||
end
|
||||
|
||||
def about
|
||||
render 'internal/about', :layout => 'application'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -65,9 +65,23 @@ class MessagesController < ApplicationController
|
|||
end
|
||||
|
||||
def compose
|
||||
#before filter
|
||||
#before filter :prepare_compose_buttons, :create_message_with_params
|
||||
@operation = :new
|
||||
logger.custom('m',@message.inspect)
|
||||
if params["cid"].present?
|
||||
contact = @current_user.contacts.find_by_id(params["cid"])
|
||||
if not contact.nil?
|
||||
@message.to_addr = contact.email
|
||||
end
|
||||
elsif params["cids"].present?
|
||||
contacts = []
|
||||
params["cids"].each do |c|
|
||||
contact = @current_user.contacts.find_by_id(c)
|
||||
if not contact.nil?
|
||||
contacts << contact.email
|
||||
end
|
||||
end
|
||||
@message.to_addr = contacts.join(';')
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'imap_session'
|
|||
require 'imap_mailbox'
|
||||
require 'imap_message'
|
||||
require 'mail'
|
||||
require 'mail_plugin_extension'
|
||||
|
||||
class MessagesOpsController < ApplicationController
|
||||
|
||||
|
@ -128,7 +129,7 @@ class MessagesOpsController < ApplicationController
|
|||
@operation = :upload
|
||||
create_message_with_params
|
||||
if not params[:upload]
|
||||
flash[:error] = t(:no_attach,:scope=>:compose)
|
||||
flash[:error] = t(:no_file_chosen,:scope=>:common)
|
||||
else
|
||||
name = params[:upload][:datafile].original_filename
|
||||
upload_dir = $defaults["msg_upload_dir"]
|
||||
|
@ -188,11 +189,12 @@ class MessagesOpsController < ApplicationController
|
|||
mail = Mail.new
|
||||
mail.subject = params[:message][:subject]
|
||||
mail.from = @current_user.full_address
|
||||
#TODO check if email address is valid if not get address from contacts
|
||||
mail.to = params[:message][:to_addr]
|
||||
mail.body = params[:message][:body]
|
||||
|
||||
attachments = Dir.glob(File.join($defaults["msg_upload_dir"],@current_user.username + "*"))
|
||||
logger.custom('attach',attachments.inspect)
|
||||
#logger.custom('attach',attachments.inspect)
|
||||
attachments.each do |a|
|
||||
mail.add_file :filename => File.basename(a.gsub(/#{@current_user.username}_/,"")), :content => File.read(a)
|
||||
end
|
||||
|
@ -221,7 +223,7 @@ class MessagesOpsController < ApplicationController
|
|||
@mailbox.append(@sent_folder.full_name,mail.to_s,[:Seen])
|
||||
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
flash[:error] = "#{t(:imap_err,:scope=>:internal)} (#{e.to_s})"
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
return
|
||||
end
|
||||
|
@ -238,10 +240,13 @@ class MessagesOpsController < ApplicationController
|
|||
if @drafts_folder.nil?
|
||||
raise t(:not_configured_drafts,:scope=>:compose)
|
||||
end
|
||||
# TODO delete old one if was edit
|
||||
@mailbox.append(@drafts_folder.full_name,mail.to_s,[:Seen])
|
||||
if params[:olduid].present?
|
||||
@mailbox.move_message(params[:olduid],@trash_folder.full_name)
|
||||
@mailbox.expunge
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{t(:imap_error)} (#{e.to_s})"
|
||||
flash[:error] = "#{t(:imap_error,:scope=>:internal)} (#{e.to_s})"
|
||||
redirect_to :controller => 'messages', :action => 'index'
|
||||
return
|
||||
end
|
||||
|
@ -250,24 +255,24 @@ class MessagesOpsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
###################################### protected section #######################################
|
||||
|
||||
protected
|
||||
|
||||
#FIXME edit does not support attachments
|
||||
def edit
|
||||
old_message = @current_user.messages.find(params[:id].first)
|
||||
old_message = @current_user.messages.find(params[:id])
|
||||
@message = Message.new
|
||||
@message.to_addr = old_message.to_addr
|
||||
@message.subject = old_message.subject
|
||||
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
@message.body = mail.text_part.decoded_and_charseted
|
||||
@message.body = mail.text_part.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
else
|
||||
@message.body = mail.decoded_and_charseted
|
||||
@message.body = mail.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
end
|
||||
@attachments = []
|
||||
@operation = :edit
|
||||
@olduid = old_message.uid
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
|
@ -280,7 +285,7 @@ class MessagesOpsController < ApplicationController
|
|||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
if mail.multipart?
|
||||
@message.body = mail.text_part.decoded_and_charseted
|
||||
@message.body = mail.text_part.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
else
|
||||
@message.body = mail.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
end
|
||||
|
@ -288,6 +293,11 @@ class MessagesOpsController < ApplicationController
|
|||
@operation = :reply
|
||||
render 'messages/compose'
|
||||
end
|
||||
###################################### protected section #######################################
|
||||
|
||||
protected
|
||||
|
||||
|
||||
|
||||
############################################ set_mail_defaults ####################################
|
||||
|
||||
|
|
|
@ -252,6 +252,14 @@ end
|
|||
# link_to( t(:prefs,:scope=>:prefs), prefs_look_path )
|
||||
#end
|
||||
|
||||
def single_navigation(label,scope)
|
||||
s = ""
|
||||
s += "<ul class=\"wat-cf\">"
|
||||
s += "<li class=\"first active\">#{link_to(t(label,:scope=>scope),'#')}</li>"
|
||||
s += "<li class=\"last\"> </li>"
|
||||
s += "</ul>"
|
||||
end
|
||||
|
||||
def main_navigation(active)
|
||||
instance_variable_set("@#{active}", "active")
|
||||
s = ""
|
||||
|
@ -310,8 +318,9 @@ def force_charset(text)
|
|||
end
|
||||
|
||||
def content_for_sidebar
|
||||
s = render :partial => 'folders/list'
|
||||
s += render :partial => 'events/calendar'
|
||||
s = render :partial => 'sidebar/logo'
|
||||
s += render :partial => 'folders/list'
|
||||
s += render :partial => 'sidebar/calendar_view'
|
||||
s += render :partial => 'internal/version'
|
||||
s
|
||||
end
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
module EventsHelper
|
||||
#DAYNAMES = [:mon, :tue, :wed, :thu, :fri, :sat, :sun]
|
||||
def calendar(yeard,monthd,addMonths)
|
||||
now = DateTime.now
|
||||
first = Date.new(now.year,now.month,1)
|
||||
last = Date.new(now.year,now.month,-1)
|
||||
curr_week = first.cweek
|
||||
html = "<h3>"
|
||||
html << t(:month_names,:scope=>:date)[now.month]
|
||||
html << "</h3><div class=\"content\">"
|
||||
html << "<table class=\"side_calendar width100\">"
|
||||
html << "<tr><td></td>"
|
||||
|
||||
1.upto(6) do |i|
|
||||
html << "<td class=\"wday\">#{t(:abbr_day_names,:scope=>:date)[i]}</td>"
|
||||
end
|
||||
html << "<td class=\"wday\">#{t(:abbr_day_names,:scope=>:date)[0]}</td>"
|
||||
html << "</tr>"
|
||||
html << "<tr>"
|
||||
html << "<td class=\"week\">#{first.cweek}</td>"
|
||||
|
||||
(first.wday-1).downto(1) do |i|
|
||||
prev = first - i
|
||||
html << "<td class=\"off\">#{prev.day}</td>"
|
||||
end
|
||||
|
||||
(first.day).upto(last.day) do |i|
|
||||
curr = Date.new(now.year,now.month,i)
|
||||
if curr.wday == 1
|
||||
html << "</tr>"
|
||||
html << "<tr>"
|
||||
curr_week += 1
|
||||
html << "<td class=\"week\">#{curr_week}</td>"
|
||||
end
|
||||
if now.day == i
|
||||
html << "<td class=\"today\">#{i}</td>"
|
||||
else
|
||||
if curr.wday == 0 || curr.wday == 6
|
||||
html << "<td class=\"weekend\">#{i}</td>"
|
||||
else
|
||||
html << "<td>#{i}</td>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
1.upto(7-last.wday) do |i|
|
||||
post = last + i
|
||||
html << "<td class=\"off\">#{post.day}</td>"
|
||||
end
|
||||
|
||||
html << "</tr>"
|
||||
html << "</table></div>"
|
||||
html
|
||||
end
|
||||
end
|
|
@ -5,7 +5,7 @@ class Contact < ActiveRecord::Base
|
|||
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
|
||||
validate_on_create :check_unique_nick
|
||||
validate :check_unique_nick, :on => :create
|
||||
|
||||
belongs_to :user
|
||||
|
||||
|
@ -32,4 +32,23 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def export
|
||||
fields = []
|
||||
fields << nick.presence || ""
|
||||
fields << first_name || ""
|
||||
fields << last_name || ""
|
||||
fields << email || ""
|
||||
fields << info || ""
|
||||
fields.join(';')
|
||||
end
|
||||
|
||||
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.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,8 @@ require 'ezcrypto'
|
|||
|
||||
class User < ActiveRecord::Base
|
||||
|
||||
#acts_as_notes_owner
|
||||
|
||||
validates_presence_of :first_name,:last_name
|
||||
validates_uniqueness_of :email
|
||||
has_many :servers, :dependent => :destroy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue