From 2b4e3e3a412e8882a83e316d93bc9e24cff1fe65 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Sat, 23 Oct 2010 21:49:53 -0700 Subject: [PATCH] a person now has a photos#index page. --- app/controllers/photos_controller.rb | 12 ++++ app/helpers/application_helper.rb | 7 +++ app/views/albums/index.html.haml | 6 -- app/views/albums/show.html.haml | 4 +- app/views/photos/index.html.haml | 34 ++++++++++++ app/views/photos/show.html.haml | 71 ++++-------------------- app/views/shared/_author_info.html.haml | 23 ++++---- app/views/status_messages/show.html.haml | 2 +- config/routes.rb | 2 +- public/javascripts/photo.js | 57 +++++++++++++++++++ public/stylesheets/sass/application.sass | 2 + 11 files changed, 140 insertions(+), 80 deletions(-) create mode 100644 app/views/photos/index.html.haml create mode 100644 public/javascripts/photo.js diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index c0c585148..2a7f51381 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -8,6 +8,16 @@ class PhotosController < ApplicationController respond_to :html respond_to :json, :only => :show + def index + if params[:person_id] + @person = current_user.visible_people.find_by_person_id(params[:person_id]) + end + @person ||= current_user.person + + @photos = current_user.visible_posts(:_type => "Photo", :person_id => @person.id) + @albums = current_user.visible_posts(:_type => "Album", :person_id => @person.id) + end + def create album = current_user.find_visible_post_by_id( params[:album_id] ) @@ -78,6 +88,8 @@ class PhotosController < ApplicationController render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else @album = @photo.album + @ownership = current_user.owns? @photo + respond_with @photo, @album end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 869d49a98..9cb502908 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -78,4 +78,11 @@ module ApplicationHelper def post_yield_tag(post) (':' + post.id.to_s).to_sym end + + def person_photos_path person + person_id = person.id if person.respond_to?(:id) + person_id ||= person + + "#{photos_path}?person_id=#{person_id}" + end end diff --git a/app/views/albums/index.html.haml b/app/views/albums/index.html.haml index 076893404..300371393 100644 --- a/app/views/albums/index.html.haml +++ b/app/views/albums/index.html.haml @@ -2,12 +2,6 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -- content_for :head do - :javascript - $(document).ready(function(){ - $("#add_album_button").fancybox(); - }); - .span-4.append-1.last = render "shared/aspect_friends" diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml index 4941a2bee..07ebff0bf 100644 --- a/app/views/albums/show.html.haml +++ b/app/views/albums/show.html.haml @@ -10,10 +10,10 @@ }); -= render 'shared/author_info', :post => @album += render 'shared/author_info', :person => @album.person, :post => @album %ul#breadcrumb - %li= link_to "#{@album.person.profile.first_name}'s Photos", '#' + %li= link_to "#{@album.person.profile.first_name}'s Photos", person_photos_path(@album.person) %li= @album.name diff --git a/app/views/photos/index.html.haml b/app/views/photos/index.html.haml new file mode 100644 index 000000000..8f9fb7766 --- /dev/null +++ b/app/views/photos/index.html.haml @@ -0,0 +1,34 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +:javascript + $(document).ready(function(){ + $(".image_thumb img").load( function() { + $(this).fadeIn("slow"); + }); + }); + + += render 'shared/author_info', :person => @person + +%ul#breadcrumb + %li= link_to "#{@person.profile.first_name}'s Photos", person_photos_path(@person) + +.span-24.last + #thumbnails + - for photo in @photos + .image_thumb + = link_to (image_tag photo.url(:thumb_medium)), object_path(photo) + +.span-24.last + %h3 + Photos + %div + - for album in @albums + = render "albums/album", :post => album + +.span-24.last + %h3 + Albums + diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 9b48538e5..2b10e4a8a 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -3,93 +3,46 @@ -# the COPYRIGHT file. - content_for :head do - :javascript - $(document).keydown(function(e){ - switch(e.keyCode) { - case 37: - if(!$("textarea").hasClass("hasfocus")){//prevent redirect if textarea has focus - window.location.replace( "#{url_to_prev(@photo,@album)}" ); - } - break; - case 39: - if(!$("textarea").hasClass("hasfocus")){ - window.location.replace( "#{url_to_next(@photo,@album)}" ); - } - break; - } - }); + =javascript_include_tag 'photo' + - $(document).ready(function(){ - //add a clas to verify if a textarea has focus - $("textarea").live('focus',function(){ - $(this).addClass("hasfocus"); - }); - $("textarea").live('blur',function(){ - $(this).removeClass("hasfocus"); - }); - - //show form to add description - $(".edit-desc").click(function(){ - $(".edit_photo").toggle(); - }); - - //Add a description with ajax request - $("#photo_submit").click(function(evenet){ - event.preventDefault(); - var method = $(".edit_photo").attr("method"); - var url = $(".edit_photo").attr("action"); - var data = $(".edit_photo").serialize(); - $(".description").text($("#photo_caption").val()); - $(".edit_photo").toggle(); - - $.ajax({ - type: method, - url: url, - data: data, - success: function(response){ - $("#add-description").remove(); - } - }); - - }); - - });//end document ready - -= render 'shared/author_info', :post => @photo += render 'shared/author_info', :person => @photo.person, :post => @photo %ul#breadcrumb - %li= link_to "#{@album.person.profile.first_name}'s Photos", '#' + %li= link_to "#{@album.person.profile.first_name}'s Photos", person_photos_path(@photo.person) %li= link_to @album.name, album_path(@album) %li= @photo.caption -= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch' += link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch', :id => "prev_photo" | = link_to "#{t('.full_size')}", @photo.url | -= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch' += link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch', :id => "next_photo" .span-14.append-1.last %div{:data=>{:guid=>@photo.id}} #show_photo - -if current_user.owns? @photo + -if @ownership .edit_pane .controls{:data=>{:actor=>"#{@photo.person.owner.id}",:actor_person=>"#{@photo.person.id}",:image_url=>"#{@photo.url(:thumb_medium)}"}} = link_to 'make profile photo', '#', :class => "make_profile_photo" = linked_scaled_photo @photo, @album -else = linked_scaled_photo @photo, @album + .caption - -if current_user.owns? @photo + -if @ownership -if @photo.caption and @photo.caption != "" = link_to 'Edit','javascript:void(0)', :id => "edit-desc", :class => "edit-desc" .description = @photo.caption - -if current_user.owns? @photo + -if @ownership %div{:class => 'clear'} -if !@photo.caption or @photo.caption == "" = link_to 'Add a description','javascript:void(0)', :id => "add-description", :class => "edit-desc" + %br %br @@ -98,7 +51,7 @@ = p.submit %div{:class => 'clear'} - -if current_user.owns? @album + -if @ownership = link_to t('.delete_photo'), @photo, :confirm => t('.are_you_sure'), :method => :delete, :class => 'button' .span-9.last diff --git a/app/views/shared/_author_info.html.haml b/app/views/shared/_author_info.html.haml index 6a619c44b..14f4a1457 100644 --- a/app/views/shared/_author_info.html.haml +++ b/app/views/shared/_author_info.html.haml @@ -1,15 +1,16 @@ #author_info - = owner_image_link + = person_image_link(person) .from %h2 - = post.person.real_name - .aspect - ➔ - %ul - - if post.public? - the world - - else - - for aspect in current_user.aspects_with_post( post.id ) - %li= link_to aspect.name, aspect + = person.real_name + - if defined?(post) + .aspect + ➔ + %ul + - if post.public? + the world + - else + - for aspect in current_user.aspects_with_post( post.id ) + %li= link_to aspect.name, aspect - = link_to "view profile", person_path(post.person) + = link_to "view profile", person_path(person) diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 9aa2749a5..0672ca1e8 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -3,7 +3,7 @@ -# the COPYRIGHT file. -= render 'shared/author_info', :post => @status_message += render 'shared/author_info', :person => @status_message.person, :post => @status_message .span-14.append-1.last %h1.show_text diff --git a/config/routes.rb b/config/routes.rb index c72ed855f..8604abaad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,7 @@ Diaspora::Application.routes.draw do resources :status_messages, :only => [:create, :destroy, :show] resources :comments, :except => [:index] resources :requests, :except => [:edit, :update] - resources :photos, :except => [:index] + resources :photos resources :albums resources :services diff --git a/public/javascripts/photo.js b/public/javascripts/photo.js new file mode 100644 index 000000000..2991903d7 --- /dev/null +++ b/public/javascripts/photo.js @@ -0,0 +1,57 @@ +/* Copyright (c) 2010, Diaspora Inc. This file is +* licensed under the Affero General Public License version 3 or later. See +* the COPYRIGHT file. +*/ + + +$(document).keydown(function(e){ + switch(e.keyCode) { + case 37: + if(!$("textarea").hasClass("hasfocus")){//prevent redirect if textarea has focus + window.location = $("#prev_photo").attr('href'); + } + break; + case 39: + if(!$("textarea").hasClass("hasfocus")){ + window.location = $("#next_photo").attr('href'); + } + break; + } +}); + +$(document).ready(function(){ + //add a clas to verify if a textarea has focus + $("textarea").live('focus',function(){ + $(this).addClass("hasfocus"); + }); + $("textarea").live('blur',function(){ + $(this).removeClass("hasfocus"); + }); + + //show form to add description + $(".edit-desc").click(function(){ + $(".edit_photo").toggle(); + }); + + //Add a description with ajax request + $("#photo_submit").click(function(evenet){ + event.preventDefault(); + var method = $(".edit_photo").attr("method"); + var url = $(".edit_photo").attr("action"); + var data = $(".edit_photo").serialize(); + $(".description").text($("#photo_caption").val()); + $(".edit_photo").toggle(); + + $.ajax({ + type: method, + url: url, + data: data, + success: function(response){ + $("#add-description").remove(); + } + }); + + }); + +}); + diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index e28eaaa4a..871cd9fb6 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -723,6 +723,8 @@ label /* cycle it! */ .album + :margin + :right 3px :position relative :height 200px :width 200px