adding favorite support, enhancing the photo browser, use the photo browser for favorites, allow voting controls on any page that uses the photo partial

master
Coleman 2008-10-11 17:40:01 -05:00
parent e29cae00b4
commit ccf29f309a
10 changed files with 87 additions and 154 deletions

View File

@ -1,17 +1,21 @@
class Favorites < Application
before :logged_in?
before :fetch_allowed_user, :only => [ :show ]
only_provides :xml
def show
only_provides :html
@photos = @user.favorite_photos
render
@page = params[:page].to_i
per_page = 24
@page_count = (current_user.photo_favorites.count(:id).to_f / per_page.to_f).ceil
@photos = current_user.favorite_photos.find :all, :order => 'id DESC', :limit => per_page, :offset => (per_page * @page)
if request.xhr?
partial 'photos/photo_browser'
else
render
end
end
def create
raise NotAllowed unless request.xhr?
@photo = Photo.find params[:id]
raise NotAcceptable unless request.xhr?
@photo = Photo.find params[:photo_id] rescue nil
pf = PhotoFavorite.new :photo_id => @photo.id, :user_id => current_user.id
if pf.save
render '', :status => 200
@ -20,10 +24,12 @@ class Favorites < Application
end
end
def delete
raise NotAllowed unless request.xhr?
pf = PhotoFavorite.find params[:id], :include => :user
if pf.user == current_user and pf.destroy
def destroy
raise NotAcceptable unless request.xhr?
pf = current_user.photo_favorites.detect do |f|
f.photo_id == params[:id].to_i
end
if pf and pf.user_id == current_user.id and pf.destroy
render '', :status => 200
else
render '', :status => 403

View File

@ -1,3 +1,8 @@
%h1 Your favorite photos
= partial 'photos/photo_browser'
= pagination 'photo_browser', url(:favorites, :id => current_user.user_name)
#browser_container.centered
= partial 'home/pagination_navigation'
#photo_browser
= partial 'photos/photo_browser'

View File

@ -0,0 +1,5 @@
%h1 Disclaimer
%p You should really not take anything on this site very seriously. It's all in good fun and has no scientific or cultural basis for correctness.
%p It's all a pack of lies!

View File

@ -1,5 +1,60 @@
:javascript
function add_favorite(pid)
{
new Ajax.Request('#{url(:favorites)}?photo_id=' + pid, { onSuccess: function(){ $('favorite_add').hide(); $('favorite_remove').show(); new Effect.Highlight($('favorites')); } });
}
function remove_favorite(del_url)
{
new Ajax.Request(del_url, { onSuccess: function(){ $('favorite_remove').hide(); $('favorite_add').show(); new Effect.Highlight($('favorites')); } });
}
function transition_out_controls()
{
if($('to_be_unvoted').style.display == 'none')
return false;
new Effect.DropOut($('to_be_unvoted'));
setTimeout('transition_in_controls()', 1000);
}
function transition_in_controls()
{
new Effect.Appear($('to_be_voted'));
}
%style{ :type => "text/css" }
:sass
#outer_vote_container
:height 30px
#photo_controls
:padding 3px 10px 3px 10px
:border 1px solid #c17d11
:background-color #e9b96e
:margin 5px 0px 5px 0px
img
:vertical-align middle
a
:font-weight bold
:text-decoration none
:color #8f5902
&:hover
:color #5e3a01
#favorites
:padding-left 3px
:padding-right 3px
%div.centered{ :style => "width: #{@photo.width rescue 50}px" }
- if @photo and @photo.exist?
#photo_controls
- unless Vote.voted_for?(@photo, current_user) or params[:controller] =~ /vote/i
%span#to_be_unvoted
%a{ :href => '#', :onclick => "transition_out_controls(); return false;" } Vote!
|
- if logged_in?
%span#favorites
%span#favorite_add{ :style => (current_user.photo_favorites.detect { |f| f.photo_id == @photo.id }.nil? ? '' : "display: none;") }
%a{ :href => '#', :onclick => "add_favorite(#{@photo.id}); return false;" }
Add as favorite
%span#favorite_remove{ :style => (current_user.photo_favorites.detect { |f| f.photo_id == @photo.id }.nil? ? "display: none;" : '') }
%a{ :href => '#', :onclick => "remove_favorite('#{url(:favorite, :id => @photo.id)}?_method=delete'); return false;" }
Remove favorite
%img{ :src => @photo.pathname, :alt => @photo.filename, :width => @photo.width, :height => @photo.height }
- else
%img{ :src => '/images/image-missing.png', :alt => 'Missing File' }

View File

@ -38,26 +38,7 @@
%div.centered{ :style => "width: 400px;"}
= vote_count @photo
- else
%style{ :type => 'text/css' }
:sass
#outer_vote_container
:height 30px
#outer_vote_container
%div{ :style => 'display: none', :id => 'to_be_voted' }
= partial 'votes/vote_controls'
#to_be_unvoted
%p
%a{ :href => '#', :onclick => "transition_out_controls(); return false;" } Vote on this photo now!
:javascript
function transition_out_controls()
{
new Effect.DropOut($('to_be_unvoted'));
setTimeout('transition_in_controls()', 1000);
}
function transition_in_controls()
{
new Effect.Appear($('to_be_voted'));
}
#outer_vote_container
%div{ :style => 'display: none', :id => 'to_be_voted' }
= partial 'votes/vote_controls'

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -1,119 +0,0 @@
body {
font-family: Arial, Verdana, sans-serif;
font-size: 12px;
background-color: #fff;
}
* {
margin: 0px;
padding: 0px;
text-decoration: none;
}
html {
height: 100%;
margin-bottom: 1px;
}
#container {
width: 80%;
text-align: left;
background-color: #fff;
margin-right: auto;
margin-left: auto;
}
#header-container {
width: 100%;
padding-top: 15px;
}
#header-container h1, #header-container h2 {
margin-left: 6px;
margin-bottom: 6px;
}
.spacer {
width: 100%;
height: 15px;
}
hr {
border: 0px;
color: #ccc;
background-color: #cdcdcd;
height: 1px;
width: 100%;
text-align: left;
}
h1 {
font-size: 28px;
color: #c55;
background-color: #fff;
font-family: Arial, Verdana, sans-serif;
font-weight: 300;
}
h2 {
font-size: 15px;
color: #999;
font-family: Arial, Verdana, sans-serif;
font-weight: 300;
background-color: #fff;
}
h3 {
color: #4d9b12;
font-size: 15px;
text-align: left;
font-weight: 300;
padding: 5px;
margin-top: 5px;
}
#left-container {
float: left;
width: 250px;
background-color: #FFFFFF;
color: black;
}
#left-container h3 {
color: #c55;
}
#main-container {
margin: 5px 5px 5px 260px;
padding: 15px;
border-left: 1px solid silver;
min-height: 400px;
}
p {
color: #000;
background-color: #fff;
line-height: 20px;
padding: 5px;
}
a {
color: #4d9b12;
background-color: #fff;
text-decoration: none;
}
a:hover {
color: #4d9b12;
background-color: #fff;
text-decoration: underline;
}
#footer-container {
clear: both;
font-size: 12px;
font-family: Verdana, Arial, sans-serif;
}
.right {
float: right;
font-size: 100%;
margin-top: 5px;
color: #999;
background-color: #fff;
}
.left {
float: left;
font-size: 100%;
margin-top: 5px;
color: #999;
background-color: #fff;
}
#main-container ul {
margin-left: 3.0em;
}