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:
parent
2b4e3e3a41
commit
a7df1bca68
13 changed files with 46 additions and 41 deletions
|
|
@ -16,10 +16,12 @@ class PhotosController < ApplicationController
|
||||||
|
|
||||||
@photos = current_user.visible_posts(:_type => "Photo", :person_id => @person.id)
|
@photos = current_user.visible_posts(:_type => "Photo", :person_id => @person.id)
|
||||||
@albums = current_user.visible_posts(:_type => "Album", :person_id => @person.id)
|
@albums = current_user.visible_posts(:_type => "Album", :person_id => @person.id)
|
||||||
|
|
||||||
|
@aspect = :photos
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
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
|
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|
|
respond_to do |format|
|
||||||
format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
|
format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
class PhotoAlbumValidator < ActiveModel::Validator
|
class PhotoAlbumValidator < ActiveModel::Validator
|
||||||
def validate(document)
|
def validate(document)
|
||||||
unless document.album.person_id == document.person_id
|
unless document.album.nil? || document.album.person_id == document.person_id
|
||||||
document.errors[:base] << "You can't post photos to that album"
|
document.errors[:base] << "You post photos to that album"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -27,7 +27,6 @@ class Photo < Post
|
||||||
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
validates_presence_of :album
|
|
||||||
validates_with PhotoAlbumValidator
|
validates_with PhotoAlbumValidator
|
||||||
|
|
||||||
before_destroy :ensure_user_picture
|
before_destroy :ensure_user_picture
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,7 @@ class User
|
||||||
|
|
||||||
######## Posting ########
|
######## Posting ########
|
||||||
def post(class_name, options = {})
|
def post(class_name, options = {})
|
||||||
if class_name == :photo
|
if class_name == :photo && !options[:album_id].to_s.empty?
|
||||||
raise ArgumentError.new("No album_id given") unless options[:album_id]
|
|
||||||
aspect_ids = aspects_with_post(options[:album_id])
|
aspect_ids = aspects_with_post(options[:album_id])
|
||||||
aspect_ids.map! { |aspect| aspect.id }
|
aspect_ids.map! { |aspect| aspect.id }
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@
|
||||||
|
|
||||||
.album{:id => post.id, :class => ("mine" if current_user.owns?(post))}
|
.album{:id => post.id, :class => ("mine" if current_user.owns?(post))}
|
||||||
%div.name
|
%div.name
|
||||||
= link_to post.name, object_path(post, :aspect => @aspect)
|
= link_to post.name, album_path(post)
|
||||||
|
|
||||||
%div.time
|
%div.time
|
||||||
by
|
by
|
||||||
= link_to ((current_user.person == post.person)? t('.you') : post.person.real_name), person_path(post.person)
|
= link_to ((current_user.person == post.person)? t('.you') : post.person.real_name), person_path(post.person)
|
||||||
%br
|
%br
|
||||||
= link_to(how_long_ago(post), object_path(post, :aspect => @aspect))
|
= link_to(how_long_ago(post), album_path(post))
|
||||||
|
|
||||||
%div.image_cycle
|
%div.image_cycle
|
||||||
- for photo in post.photos[0..3]
|
- 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)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
="#{t('.updated')} #{how_long_ago(@album)}"
|
="#{t('.updated')} #{how_long_ago(@album)}"
|
||||||
|
|
||||||
-if current_user.owns? @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'
|
= link_to t('.edit_album'), edit_album_path(@album), :class => 'button'
|
||||||
|
|
||||||
.album_id{:id => @album.id, :style => "display:hidden;"}
|
.album_id{:id => @album.id, :style => "display:hidden;"}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
function createUploader(){
|
function createUploader(){
|
||||||
var uploader = new qq.FileUploader({
|
var uploader = new qq.FileUploader({
|
||||||
element: document.getElementById('file-upload'),
|
element: document.getElementById('file-upload'),
|
||||||
params: {'album_id' : "#{@album.id}"},
|
params: {'photo' : { 'album_id' : "#{album_id}", 'to' : "#{aspect_id}"}},
|
||||||
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
|
allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
|
||||||
action: "#{photos_path}"
|
action: "#{photos_path}"
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,11 @@
|
||||||
.right
|
.right
|
||||||
= link_to t('.delete'), photo_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete"
|
= link_to t('.delete'), photo_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete"
|
||||||
|
|
||||||
=t('.posted_a_new_photo_to')
|
- if !post.album_id.nil?
|
||||||
= link_to post.album.name, object_path(post.album)
|
=t('.posted_a_new_photo_to')
|
||||||
|
= link_to post.album.name, object_path(post.album)
|
||||||
|
- else
|
||||||
|
posted a photo
|
||||||
|
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,20 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
= render 'shared/author_info', :person => @person
|
.span-24.last{:style=>"position:relative;"}
|
||||||
|
= render 'shared/author_info', :person => @person
|
||||||
|
|
||||||
%ul#breadcrumb
|
.right
|
||||||
%li= link_to "#{@person.profile.first_name}'s Photos", person_photos_path(@person)
|
= 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
|
.span-24.last
|
||||||
#thumbnails
|
#thumbnails
|
||||||
- for photo in @photos
|
- for photo in @photos
|
||||||
.image_thumb
|
.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
|
.span-24.last
|
||||||
%h3
|
%h3
|
||||||
|
|
@ -32,3 +36,8 @@
|
||||||
%h3
|
%h3
|
||||||
Albums
|
Albums
|
||||||
|
|
||||||
|
|
||||||
|
.span-24.last
|
||||||
|
#add_photo_pane
|
||||||
|
= render "photos/new_photo", :album_id => nil, :aspect_id => :all
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,17 @@
|
||||||
= render 'shared/author_info', :person => @photo.person, :post => @photo
|
= render 'shared/author_info', :person => @photo.person, :post => @photo
|
||||||
|
|
||||||
%ul#breadcrumb
|
%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)
|
||||||
%li= link_to @album.name, album_path(@album)
|
- if !@photo.album_id.nil?
|
||||||
|
%li= link_to @album.name, album_path(@album)
|
||||||
%li= @photo.caption
|
%li= @photo.caption
|
||||||
|
|
||||||
= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch', :id => "prev_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('.full_size')}", @photo.url
|
||||||
= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch', :id => "next_photo"
|
|
|
||||||
|
= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch', :id => "next_photo"
|
||||||
|
|
||||||
.span-14.append-1.last
|
.span-14.append-1.last
|
||||||
%div{:data=>{:guid=>@photo.id}}
|
%div{:data=>{:guid=>@photo.id}}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ $(document).ready(function(){
|
||||||
$(".add_aspect_button").fancybox({ 'titleShow' : false , 'hideOnOverlayClick' : false });
|
$(".add_aspect_button").fancybox({ 'titleShow' : false , 'hideOnOverlayClick' : false });
|
||||||
$(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
|
$(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
|
||||||
$(".invite_user_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 });
|
$(".remove_person_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
|
||||||
$(".question_mark").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
|
$(".question_mark").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,10 @@ header
|
||||||
.avatar
|
.avatar
|
||||||
:border-radius 5px
|
:border-radius 5px
|
||||||
|
|
||||||
|
img
|
||||||
|
:-webkit-box-shadow 0 1px 2px #666
|
||||||
|
:border-radius 5px
|
||||||
|
|
||||||
|
|
||||||
.from
|
.from
|
||||||
:font
|
:font
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
.button, .button_set
|
.button, .button_set
|
||||||
:font
|
:font
|
||||||
:family "Lucida Grande", sans-serif
|
|
||||||
:style normal
|
:style normal
|
||||||
|
:weight bold
|
||||||
|
|
||||||
:display inline
|
:display inline
|
||||||
|
|
||||||
|
|
@ -37,8 +37,6 @@
|
||||||
:-webkit-box-shadow 0 1px 1px #eee
|
:-webkit-box-shadow 0 1px 1px #eee
|
||||||
:-moz-box-shadow 0 1px 1px #eee
|
:-moz-box-shadow 0 1px 1px #eee
|
||||||
|
|
||||||
:font-weight normal
|
|
||||||
|
|
||||||
:color #666
|
:color #666
|
||||||
|
|
||||||
&:hover
|
&:hover
|
||||||
|
|
|
||||||
|
|
@ -52,17 +52,6 @@ describe Photo do
|
||||||
binary.should == fixture_binary
|
binary.should == fixture_binary
|
||||||
end
|
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
|
it 'should have a caption' do
|
||||||
@photo.image.store! File.open(@fixture_name)
|
@photo.image.store! File.open(@fixture_name)
|
||||||
@photo.caption = "cool story, bro"
|
@photo.caption = "cool story, bro"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue