2011-07-29 20:05:47 +02:00
|
|
|
class ContactsController < ApplicationController
|
|
|
|
|
2011-09-03 13:07:40 +02:00
|
|
|
before_filter :check_current_user,:selected_folder, :get_current_folders
|
2011-08-16 20:05:58 +02:00
|
|
|
|
|
|
|
before_filter :get_contacts, :only => [:index]
|
2011-07-29 20:05:47 +02:00
|
|
|
|
2011-09-09 22:10:25 +02:00
|
|
|
before_filter :prepare_ops_buttons, :only => [:index]
|
|
|
|
|
2011-07-29 20:05:47 +02:00
|
|
|
theme :theme_resolver
|
|
|
|
|
|
|
|
def index
|
2011-08-16 20:05:58 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def ops
|
2011-09-09 22:10:25 +02:00
|
|
|
if params["create_new"]
|
|
|
|
redirect_to(new_contact_path)
|
|
|
|
return
|
|
|
|
end
|
2011-08-16 20:05:58 +02:00
|
|
|
if !params["cids"]
|
|
|
|
flash[:warning] = t(:no_selected,:scope=>:contact)
|
|
|
|
else
|
2011-09-09 22:10:25 +02:00
|
|
|
if params["delete_selected"]
|
2011-08-16 20:05:58 +02:00
|
|
|
params["cids"].each do |id|
|
|
|
|
@current_user.contacts.find_by_id(id).destroy
|
|
|
|
end
|
2011-09-09 22:10:25 +02:00
|
|
|
elsif params["compose_to_selected"]
|
2011-08-16 20:05:58 +02:00
|
|
|
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
|
|
|
|
# redirect_to(contacts_path)
|
|
|
|
#end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@contact = Contact.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@contact = @current_user.contacts.find(params[:id])
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@contact = @current_user.contacts.build(params[:contact])
|
|
|
|
if @contact.valid?
|
|
|
|
@contact.save
|
|
|
|
flash[:notice] = t(:was_created,:scope=>:contact)
|
|
|
|
redirect_to(contacts_path)
|
|
|
|
else
|
|
|
|
render 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@contact = @current_user.contacts.find(params[:id])
|
|
|
|
if @contact.update_attributes(params[:contact])
|
|
|
|
redirect_to(contacts_path)
|
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-09 22:10:25 +02:00
|
|
|
####################################### 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
|
|
|
|
|
2011-08-16 20:05:58 +02:00
|
|
|
####################################### private section ##################################
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_contacts
|
|
|
|
@contacts = Contact.getPageForUser(@current_user,params[:page],params[:sort_field],params[:sort_dir])
|
2011-07-29 20:05:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|