diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 2a7f51381..eda00b144 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -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 )} diff --git a/app/models/photo.rb b/app/models/photo.rb index afc3fa583..d60bd3645 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 071abfcb0..106273b77 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/albums/_album.html.haml b/app/views/albums/_album.html.haml index f9f7d43e2..43ae3a708 100644 --- a/app/views/albums/_album.html.haml +++ b/app/views/albums/_album.html.haml @@ -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) diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml index 07ebff0bf..b8f7bc859 100644 --- a/app/views/albums/show.html.haml +++ b/app/views/albums/show.html.haml @@ -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;"} diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index 6ba1327e8..a5efe45da 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -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}" }); diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index f89f8bba6..9e878b510 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -22,8 +22,11 @@ .right = link_to t('.delete'), photo_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete" - =t('.posted_a_new_photo_to') - = link_to post.album.name, object_path(post.album) + - 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 diff --git a/app/views/photos/index.html.haml b/app/views/photos/index.html.haml index 8f9fb7766..f8de1f037 100644 --- a/app/views/photos/index.html.haml +++ b/app/views/photos/index.html.haml @@ -10,16 +10,20 @@ }); -= render 'shared/author_info', :person => @person +.span-24.last{:style=>"position:relative;"} + = render 'shared/author_info', :person => @person -%ul#breadcrumb - %li= link_to "#{@person.profile.first_name}'s Photos", person_photos_path(@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) .span-24.last #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 + diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 2b10e4a8a..2962cd2d6 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -9,15 +9,17 @@ = 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 @album.name, album_path(@album) + %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 -= 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', :id => "next_photo" +- if @photo.album + = 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', :id => "next_photo" .span-14.append-1.last %div{:data=>{:guid=>@photo.id}} diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 730358083..8cbc5786c 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -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 }); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 871cd9fb6..ba4229ab0 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -208,6 +208,10 @@ header .avatar :border-radius 5px + img + :-webkit-box-shadow 0 1px 2px #666 + :border-radius 5px + .from :font diff --git a/public/stylesheets/sass/ui.sass b/public/stylesheets/sass/ui.sass index ff4b3c099..e1d14cb16 100644 --- a/public/stylesheets/sass/ui.sass +++ b/public/stylesheets/sass/ui.sass @@ -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 diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index edc3aecf6..17fac6be2 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -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"