diff --git a/app/controllers/favorites.rb b/app/controllers/favorites.rb index 628ac98..11dec0b 100644 --- a/app/controllers/favorites.rb +++ b/app/controllers/favorites.rb @@ -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 diff --git a/app/views/favorites/show.html.haml b/app/views/favorites/show.html.haml index 5c4045f..dbc1819 100644 --- a/app/views/favorites/show.html.haml +++ b/app/views/favorites/show.html.haml @@ -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' diff --git a/app/views/home/disclaimer.html.haml b/app/views/home/disclaimer.html.haml new file mode 100644 index 0000000..45f1cdc --- /dev/null +++ b/app/views/home/disclaimer.html.haml @@ -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! diff --git a/app/views/photos/_photo.html.haml b/app/views/photos/_photo.html.haml index 7eb4168..1de616d 100644 --- a/app/views/photos/_photo.html.haml +++ b/app/views/photos/_photo.html.haml @@ -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' } diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 715cf3e..63b5b0c 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -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' diff --git a/public/photos/28/28/28/dsc01816.jpg b/public/photos/28/28/28/dsc01816.jpg new file mode 100644 index 0000000..ff83303 Binary files /dev/null and b/public/photos/28/28/28/dsc01816.jpg differ diff --git a/public/photos/29/29/29/dsc01819.jpg b/public/photos/29/29/29/dsc01819.jpg new file mode 100644 index 0000000..0fc80b5 Binary files /dev/null and b/public/photos/29/29/29/dsc01819.jpg differ diff --git a/public/photos/30/30/30/dsc01837.jpg b/public/photos/30/30/30/dsc01837.jpg new file mode 100644 index 0000000..019b804 Binary files /dev/null and b/public/photos/30/30/30/dsc01837.jpg differ diff --git a/public/photos/31/31/31/dsc01851.jpg b/public/photos/31/31/31/dsc01851.jpg new file mode 100644 index 0000000..9a65640 Binary files /dev/null and b/public/photos/31/31/31/dsc01851.jpg differ diff --git a/public/stylesheets/master.css b/public/stylesheets/master.css deleted file mode 100644 index c4fa676..0000000 --- a/public/stylesheets/master.css +++ /dev/null @@ -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; -} \ No newline at end of file