devel
This commit is contained in:
parent
b8eddc8e48
commit
77c8d3e7d7
54 changed files with 614 additions and 209 deletions
|
@ -6,34 +6,10 @@ class ContactsController < ApplicationController
|
|||
|
||||
before_filter :get_contacts, :only => [:index]
|
||||
|
||||
before_filter :prepare_ops_buttons, :prepare_export_import_buttons,:only => [:index]
|
||||
|
||||
#theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def ops
|
||||
if params["create_new"]
|
||||
redirect_to(new_contact_path)
|
||||
return
|
||||
end
|
||||
if !params["cids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:contact)
|
||||
else
|
||||
if params["delete_selected"]
|
||||
params["cids"].each do |id|
|
||||
@current_user.contacts.find_by_id(id).destroy
|
||||
end
|
||||
elsif params["compose_to_selected"]
|
||||
redirect_to :controller=>'messages',:action=>'compose',:cids=>params["cids"]
|
||||
return
|
||||
end
|
||||
end
|
||||
redirect_to(contacts_path)
|
||||
end
|
||||
|
||||
#problem http://binary10ve.blogspot.com/2011/05/migrating-to-rails-3-got-stuck-with.html
|
||||
#def destroy
|
||||
# @current_user.contacts.find(params[:id]).destroy
|
||||
|
@ -50,6 +26,21 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
if params["compose_to_selected"]
|
||||
if params["items_ids"]
|
||||
redirect_to compose_path(:cids => params["items_ids"])
|
||||
return
|
||||
end
|
||||
end
|
||||
if params["delete_selected"]
|
||||
if params["items_ids"]
|
||||
params["items_ids"].each do |id|
|
||||
@current_user.contacts.find_by_id(id).destroy
|
||||
end
|
||||
end
|
||||
redirect_to(contacts_path)
|
||||
return
|
||||
end
|
||||
@contact = @current_user.contacts.build(params[:contact])
|
||||
if @contact.valid?
|
||||
@contact.save
|
||||
|
@ -69,10 +60,17 @@ class ContactsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def external
|
||||
def import_export
|
||||
if params["export"]
|
||||
redirect_to :action => 'export'
|
||||
return
|
||||
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
|
||||
return
|
||||
elsif params["import"]
|
||||
begin
|
||||
raise t(:no_file_chosen,:scope=>:common) if not params[:upload]
|
||||
|
@ -82,8 +80,8 @@ class ContactsController < ApplicationController
|
|||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
next if line =~ /^#/
|
||||
Contact.import(@current_user,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}
|
||||
|
@ -96,34 +94,10 @@ class ContactsController < ApplicationController
|
|||
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
|
||||
|
||||
def prepare_ops_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'compose_to_selected',:scope=> 'contact', :image => 'email.png'}
|
||||
@buttons << {:text => 'create_new',:scope=> 'contact', :image => 'plus.png'}
|
||||
@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
|
||||
|
|
|
@ -6,39 +6,10 @@ class LinksController < ApplicationController
|
|||
|
||||
before_filter :get_links, :only => [:index]
|
||||
|
||||
before_filter :prepare_ops_buttons, :only => [:index]
|
||||
|
||||
#, :prepare_export_import_buttons,:only => [:index]
|
||||
|
||||
#theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def ops
|
||||
if params["create_new"]
|
||||
redirect_to(new_link_path)
|
||||
return
|
||||
end
|
||||
if !params["ids"]
|
||||
flash[:warning] = t(:no_selected,:scope=>:link)
|
||||
else
|
||||
if params["delete_selected"]
|
||||
params["ids"].each do |id|
|
||||
@current_user.links.find_by_id(id).destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to(links_path)
|
||||
end
|
||||
|
||||
#problem http://binary10ve.blogspot.com/2011/05/migrating-to-rails-3-got-stuck-with.html
|
||||
#def destroy
|
||||
# @current_user.contacts.find(params[:id]).destroy
|
||||
# redirect_to(contacts_path)
|
||||
#end
|
||||
|
||||
def new
|
||||
@link = Link.new
|
||||
end
|
||||
|
@ -49,6 +20,15 @@ class LinksController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
if params["delete_selected"]
|
||||
if params["items_ids"]
|
||||
params["items_ids"].each do |id|
|
||||
@current_user.links.find_by_id(id).destroy
|
||||
end
|
||||
end
|
||||
redirect_to(links_path)
|
||||
return
|
||||
end
|
||||
@link = @current_user.links.build(params[:link])
|
||||
if @link.valid?
|
||||
@link.save
|
||||
|
@ -68,10 +48,17 @@ class LinksController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def external
|
||||
def import_export
|
||||
if params["export"]
|
||||
redirect_to :action => 'export'
|
||||
return
|
||||
links = @current_user.links
|
||||
s = ""
|
||||
links.each do |l|
|
||||
s += l.export + "\r\n"
|
||||
end
|
||||
headers['Content-type'] = "text/csv"
|
||||
headers['Content-Disposition'] = %(attachment; filename="links.csv")
|
||||
render :text => s
|
||||
return
|
||||
elsif params["import"]
|
||||
begin
|
||||
raise t(:no_file_chosen,:scope=>:common) if not params[:upload]
|
||||
|
@ -81,47 +68,24 @@ class LinksController < ApplicationController
|
|||
tmp_file.flush
|
||||
tmp_file.rewind
|
||||
tmp_file.readlines.each do |line|
|
||||
next if line =~ /^#/
|
||||
Contact.import(@current_user,line)
|
||||
next if line =~ /^#/
|
||||
Link.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[:success] = t(:were_imported,:scope=>:contact)
|
||||
flash[:success] = t(:were_imported,:scope=>:link)
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
def prepare_ops_buttons
|
||||
@buttons = []
|
||||
@buttons << {:text => 'create_new',:scope=> 'link', :image => 'plus.png'}
|
||||
@buttons << {:text => 'delete_selected',:scope=>'link',:image => 'minus.png'}
|
||||
end
|
||||
|
||||
def prepare_export_import_buttons
|
||||
@ei_buttons = []
|
||||
@ei_buttons << {:text => 'import',:scope=>'link',:image => 'right.png'}
|
||||
@ei_buttons << {:text => 'export',:scope=>'link',:image => 'left.png'}
|
||||
end
|
||||
|
||||
####################################### private section ##################################
|
||||
|
||||
private
|
||||
|
|
|
@ -103,8 +103,8 @@ class MessagesController < ApplicationController
|
|||
#@to = mail.To.addrs.presence
|
||||
@from = @message.from_addr
|
||||
@to = @message.to_addr
|
||||
@cc = mail.Cc.presence
|
||||
@bcc = mail.Bcc.presence
|
||||
@cc = mail.cc
|
||||
@bcc = mail.bcc
|
||||
#@subject = mail.Subject
|
||||
@date = mail.date.presence
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class MessagesOpsController < ApplicationController
|
|||
############################################### single #####################################
|
||||
|
||||
def single
|
||||
if params[:reply]
|
||||
if params[:reply] or params[:reply_all]
|
||||
reply
|
||||
return
|
||||
elsif params[:trash]
|
||||
|
@ -281,11 +281,19 @@ class MessagesOpsController < ApplicationController
|
|||
def reply
|
||||
old_message = @current_user.messages.where('folder_id = ? and uid = ?',@current_folder,params[:uids].first).first
|
||||
@message = Message.new
|
||||
@message.to_addr = old_message.from_addr
|
||||
@message.subject = old_message.subject
|
||||
#@message.to_addr = old_message.from_addr
|
||||
#@message.to_addr = old_message.from.first
|
||||
#@message.subject = old_message.subject
|
||||
|
||||
imap_message = @mailbox.fetch_body(old_message.uid)
|
||||
mail = Mail.new(imap_message)
|
||||
@message.to_addr = mail.from.first
|
||||
@message.subject = mail.subject
|
||||
|
||||
if params[:reply_all]
|
||||
@message.cc_addr = mail.cc.join('; ')
|
||||
end
|
||||
|
||||
if mail.multipart?
|
||||
@message.body = mail.text_part.nil? ? "" : mail.text_part.decoded_and_charseted.gsub(/<\/?[^>]*>/, "")
|
||||
else
|
||||
|
@ -295,6 +303,7 @@ class MessagesOpsController < ApplicationController
|
|||
@operation = :reply
|
||||
render 'messages/compose'
|
||||
end
|
||||
|
||||
###################################### protected section #######################################
|
||||
|
||||
protected
|
||||
|
@ -315,6 +324,7 @@ class MessagesOpsController < ApplicationController
|
|||
@mail.from = @current_user.full_id
|
||||
#TODO check if email address is valid if not get address from contacts
|
||||
@mail.to = params[:message][:to_addr]
|
||||
@mail.cc = params[:message][:cc_addr]
|
||||
@mail.body = params[:message][:body]
|
||||
@attachments = Dir.glob(File.join($defaults["msg_upload_dir"],@current_user.username + "*"))
|
||||
@attachments.each do |a|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue