Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
before_filter :authenticate_user!
Daniel Grippi & Raphael Sofaer
a validé
respond_to :html
respond_to :json, :only => [:show, :create]
Daniel Grippi & Raphael Sofaer
a validé
@aspects = current_user.aspects.where(:id => params[:a_ids]).includes(:contacts => {:person => :profile})
@aspects = current_user.aspects.includes(:contacts => {:person => :profile})
if (current_user.getting_started == true || @aspects.blank?) && !request.format.mobile?
@posts = StatusMessage.joins(:aspects).where(:pending => false,
:aspects => {:id => @aspect_ids}).includes(:comments, :photos).select('DISTINCT `posts`.*').paginate(
:page => params[:page], :per_page => 15, :order => 'created_at DESC')
@fakes = PostsFake.new(@posts)
@contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
danielvincent
a validé
end
danielvincent
a validé
@aspect = current_user.aspects.create(params[:aspect])
#hack, we don't know why mass assignment is not working
@aspect.contacts_visible = params[:aspect][:contacts_visible]
@aspect.save
flash[:notice] = I18n.t('aspects.create.success', :name => @aspect.name)
if current_user.getting_started
redirect_to :back
elsif request.env['HTTP_REFERER'].include?("aspects/manage")
redirect_to :back
elsif params[:aspect][:share_with]
@contact = Contact.where(:id => params[:aspect][:contact_id]).first
@person = Person.where(:id => params[:aspect][:person_id]).first
respond_to do |format|
format.js { render :json => {:html => render_to_string(
:partial => 'aspects/aspect_list_item',
:locals => {:aspect => @aspect,
:person => @person,
:contact => @contact}
)},:status => 201 }
end
flash[:error] = I18n.t('aspects.create.failure')
redirect_to :back
@aspect = current_user.aspects.where(:id => params[:id]).first
flash[:notice] = I18n.t 'aspects.destroy.success',:name => @aspect.name
@aspect = current_user.aspects.where(:id => params[:id]).first
if @aspect
redirect_to aspects_path('a_ids[]' => @aspect.id)
else
redirect_to aspects_path
end
@aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first
@contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@aspect_ids = [@aspect.id]
@aspect_contacts_count = @aspect.contacts.length
danielvincent
a validé
render :layout => false
def manage
@aspect = :manage
@contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
@remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender => :profile)
@aspects = @all_aspects.includes(:contacts => {:person => :profile})
end
def update
@aspect = current_user.aspects.where(:id => params[:id]).first
if @aspect.update_attributes!( params[:aspect] )
#hack, we don't know why mass assignment is not working
@aspect.contacts_visible = params[:aspect][:contacts_visible]
@aspect.save
flash[:notice] = I18n.t 'aspects.update.success',:name => @aspect.name
else
flash[:error] = I18n.t 'aspects.update.failure',:name => @aspect.name
end
def move_contact
Raphael
a validé
@person = Person.find(params[:person_id])
@from_aspect = current_user.aspects.where(:id => params[:from]).first
@to_aspect = current_user.aspects.where(:id => params[:to][:to]).first
Raphael
a validé
danielvincent
a validé
unless current_user.move_contact( @person, @to_aspect, @from_aspect)
flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect
if aspect = current_user.aspects.where(:id => params[:to][:to]).first
response_hash[:notice] = I18n.t 'aspects.move_contact.success'
response_hash[:success] = true
response_hash[:notice] = I18n.t 'aspects.move_contact.failure'
response_hash[:success] = false
Raphael
a validé
@person = Person.find(params[:person_id])
@aspect = current_user.aspects.find(params[:aspect_id])
@contact = current_user.contact_for(@person)
if @contact
current_user.add_contact_to_aspect(@contact, @aspect)
else
current_user.send_contact_request_to(@person, @aspect)
Raphael
a validé
contact = current_user.contact_for(@person)
if request = Request.where(:sender_id => @person.id, :recipient_id => current_user.person.id).first
Raphael
a validé
request.destroy
contact.update_attributes(:pending => false)
end
Raphael
a validé
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
respond_to do |format|
format.js { render :json => {
:button_html => render_to_string(:partial => 'aspects/add_to_aspect',
:locals => {:aspect_id => @aspect.id,
:person_id => @person.id}),
:badge_html => render_to_string(:partial => 'aspects/aspect_badge',
:locals => {:aspect => @aspect})
}}
format.html{ redirect_to aspect_path(@aspect.id)}
def remove_from_aspect
begin current_user.delete_person_from_aspect(params[:person_id], params[:aspect_id])
@person_id = params[:person_id]
@aspect_id = params[:aspect_id]
flash.now[:notice] = I18n.t 'aspects.remove_from_aspect.success'
format.js { render :json => {:button_html =>
render_to_string(:partial => 'aspects/remove_from_aspect',
:locals => {:aspect_id => @aspect_id,
:person_id => @person_id}),
:aspect_id => @aspect_id
}}
rescue Exception => e
flash.now[:error] = I18n.t 'aspects.remove_from_aspect.failure'
respond_to do |format|
format.js { render :text => e, :status => 403 }
danielvincent
a validé
end
end