photos do not require an album. uploading files on a user's photos#index page will post to all aspects.

This commit is contained in:
danielvincent 2010-10-28 15:01:23 -07:00
parent 2b4e3e3a41
commit a7df1bca68
13 changed files with 46 additions and 41 deletions

View file

@ -16,10 +16,12 @@ class PhotosController < ApplicationController
@photos = current_user.visible_posts(:_type => "Photo", :person_id => @person.id)
@albums = current_user.visible_posts(:_type => "Album", :person_id => @person.id)
@aspect = :photos
end
def create
album = current_user.find_visible_post_by_id( params[:album_id] )
album = current_user.find_visible_post_by_id( params[:photo][:album_id] )
begin
@ -45,9 +47,9 @@ class PhotosController < ApplicationController
##############
params[:user_file] = file
params[:photo][:user_file] = file
@photo = current_user.post(:photo, params)
@photo = current_user.post(:photo, params[:photo])
respond_to do |format|
format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}

View file

@ -4,8 +4,8 @@
class PhotoAlbumValidator < ActiveModel::Validator
def validate(document)
unless document.album.person_id == document.person_id
document.errors[:base] << "You can't post photos to that album"
unless document.album.nil? || document.album.person_id == document.person_id
document.errors[:base] << "You post photos to that album"
end
end
end
@ -27,7 +27,6 @@ class Photo < Post
timestamps!
validates_presence_of :album
validates_with PhotoAlbumValidator
before_destroy :ensure_user_picture

View file

@ -144,8 +144,7 @@ class User
######## Posting ########
def post(class_name, options = {})
if class_name == :photo
raise ArgumentError.new("No album_id given") unless options[:album_id]
if class_name == :photo && !options[:album_id].to_s.empty?
aspect_ids = aspects_with_post(options[:album_id])
aspect_ids.map! { |aspect| aspect.id }
else

View file

@ -4,15 +4,15 @@
.album{:id => post.id, :class => ("mine" if current_user.owns?(post))}
%div.name
= link_to post.name, object_path(post, :aspect => @aspect)
= link_to post.name, album_path(post)
%div.time
by
= link_to ((current_user.person == post.person)? t('.you') : post.person.real_name), person_path(post.person)
%br
= link_to(how_long_ago(post), object_path(post, :aspect => @aspect))
= link_to(how_long_ago(post), album_path(post))
%div.image_cycle
- for photo in post.photos[0..3]
= link_to (image_tag photo.url(:thumb_large)), album_path(post, :aspect => @aspect)
= link_to (image_tag photo.url(:thumb_large)), album_path(post)

View file

@ -30,7 +30,7 @@
="#{t('.updated')} #{how_long_ago(@album)}"
-if current_user.owns? @album
=render 'photos/new_photo'
= render 'photos/new_photo', :album_id => @album.id, :aspect_id => nil
= link_to t('.edit_album'), edit_album_path(@album), :class => 'button'
.album_id{:id => @album.id, :style => "display:hidden;"}

View file

@ -6,7 +6,7 @@
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('file-upload'),
params: {'album_id' : "#{@album.id}"},
params: {'photo' : { 'album_id' : "#{album_id}", 'to' : "#{aspect_id}"}},
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
action: "#{photos_path}"
});

View file

@ -22,8 +22,11 @@
.right
= link_to t('.delete'), photo_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete"
- if !post.album_id.nil?
=t('.posted_a_new_photo_to')
= link_to post.album.name, object_path(post.album)
- else
posted a photo
%br
%br

View file

@ -10,8 +10,12 @@
});
.span-24.last{:style=>"position:relative;"}
= render 'shared/author_info', :person => @person
.right
= link_to "+ Add photos", '#add_photo_pane', :class => "add_photo_button button"
%ul#breadcrumb
%li= link_to "#{@person.profile.first_name}'s Photos", person_photos_path(@person)
@ -19,7 +23,7 @@
#thumbnails
- for photo in @photos
.image_thumb
= link_to (image_tag photo.url(:thumb_medium)), object_path(photo)
= link_to (image_tag photo.url(:thumb_medium)), photo_path(photo)
.span-24.last
%h3
@ -32,3 +36,8 @@
%h3
Albums
.span-24.last
#add_photo_pane
= render "photos/new_photo", :album_id => nil, :aspect_id => :all

View file

@ -9,10 +9,12 @@
= render 'shared/author_info', :person => @photo.person, :post => @photo
%ul#breadcrumb
%li= link_to "#{@album.person.profile.first_name}'s Photos", person_photos_path(@photo.person)
%li= link_to "#{@photo.person.profile.first_name}'s Photos", person_photos_path(@photo.person)
- if !@photo.album_id.nil?
%li= link_to @album.name, album_path(@album)
%li= @photo.caption
- if @photo.album
= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch', :id => "prev_photo"
|
= link_to "#{t('.full_size')}", @photo.url

View file

@ -29,7 +29,7 @@ $(document).ready(function(){
$(".add_aspect_button").fancybox({ 'titleShow' : false , 'hideOnOverlayClick' : false });
$(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".invite_user_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".add_photo_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".remove_person_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".question_mark").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });

View file

@ -208,6 +208,10 @@ header
.avatar
:border-radius 5px
img
:-webkit-box-shadow 0 1px 2px #666
:border-radius 5px
.from
:font

View file

@ -5,8 +5,8 @@
.button, .button_set
:font
:family "Lucida Grande", sans-serif
:style normal
:weight bold
:display inline
@ -37,8 +37,6 @@
:-webkit-box-shadow 0 1px 1px #eee
:-moz-box-shadow 0 1px 1px #eee
:font-weight normal
:color #666
&:hover

View file

@ -52,17 +52,6 @@ describe Photo do
binary.should == fixture_binary
end
it 'must have an album' do
photo = Photo.new()
photo.person = @user.person
photo.image = File.open(@fixture_name)
photo.save
photo.valid?.should be false
photo.album = @album
photo.save
photo.reload.album.name.should == 'foo'
end
it 'should have a caption' do
@photo.image.store! File.open(@fixture_name)
@photo.caption = "cool story, bro"