1
0
Fork 0
forked from OpenNeo/impress

nice page to view current user's outfits

This commit is contained in:
Emi Matchu 2011-03-23 18:23:01 -04:00
parent 88fbc72a46
commit 1207e84804
14 changed files with 663 additions and 514 deletions

View file

@ -10,9 +10,19 @@ class OutfitsController < ApplicationController
end end
end end
def for_current_user def index
@outfits = user_signed_in? ? current_user.outfits : [] if user_signed_in?
render :json => @outfits @outfits = current_user.outfits.wardrobe_order
respond_to do |format|
format.html { render }
format.json { render :json => @outfits }
end
else
respond_to do |format|
format.html { redirect_to login_path(:return_to => request.fullpath) }
format.json { render :json => [] }
end
end
end end
def destroy def destroy
@ -60,3 +70,4 @@ class OutfitsController < ApplicationController
render :json => {:errors => @outfit.errors}, :status => :bad_request render :json => {:errors => @outfit.errors}, :status => :bad_request
end end
end end

View file

@ -3,6 +3,25 @@ module OutfitsHelper
hidden_field_tag 'destination', value, :id => nil hidden_field_tag 'destination', value, :id => nil
end end
def link_to_edit_outfit(content_or_outfit, outfit_or_options, options={})
if block_given?
content = capture_haml(&Proc.new)
outfit = content_or_outfit
options = outfit_or_options
else
content = content_or_outfit
outfit = outfit_or_options
end
query = outfit.to_query
query << "&outfit=#{outfit.id}" if outfit.user == current_user
link_to content, wardrobe_path(:anchor => query), options
end
def outfit_li_for(outfit)
class_name = outfit.starred? ? 'starred' : nil
content_tag :li, :class => class_name, &Proc.new
end
def pet_attribute_select(name, collection, value=nil) def pet_attribute_select(name, collection, value=nil)
select_tag name, select_tag name,
options_from_collection_for_select(collection, :id, :human_name, value) options_from_collection_for_select(collection, :id, :human_name, value)
@ -13,3 +32,4 @@ module OutfitsHelper
text_field_tag 'name', nil, options text_field_tag 'name', nil, options
end end
end end

View file

@ -11,6 +11,8 @@ class Outfit < ActiveRecord::Base
attr_accessible :name, :pet_state_id, :starred, :worn_and_unworn_item_ids attr_accessible :name, :pet_state_id, :starred, :worn_and_unworn_item_ids
scope :wardrobe_order, order('starred DESC', :name)
def as_json(more_options={}) def as_json(more_options={})
serializable_hash :only => [:id, :name, :pet_state_id, :starred], serializable_hash :only => [:id, :name, :pet_state_id, :starred],
:methods => [:color_id, :species_id, :worn_and_unworn_item_ids] :methods => [:color_id, :species_id, :worn_and_unworn_item_ids]
@ -80,3 +82,4 @@ class Outfit < ActiveRecord::Base
end end
end end
end end

View file

@ -1,5 +1,8 @@
@import ../shared/jquery.jgrowl @import ../shared/jquery.jgrowl
@import icon
@import star
$object-padding: 6px $object-padding: 6px
$nc-icon-size: 16px $nc-icon-size: 16px
@ -16,14 +19,8 @@ $outfit-header-padding: 24px
$outfit-content-width: $sidebar-unit-inner-width - $outfit-thumbnail-size - $outfit-thumbnail-margin - 32px $outfit-content-width: $sidebar-unit-inner-width - $outfit-thumbnail-size - $outfit-thumbnail-margin - 32px
$outfit-content-inner-width: $outfit-content-width - $outfit-header-padding $outfit-content-inner-width: $outfit-content-width - $outfit-header-padding
=icon
bottom: -2px
height: 16px
position: relative
width: 16px
=outfit =outfit
//+clearfix +outfit-star-shifted
padding: .25em 0 padding: .25em 0
//.outfit-thumbnail //.outfit-thumbnail
float: left float: left
@ -38,9 +35,6 @@ $outfit-content-inner-width: $outfit-content-width - $outfit-header-padding
position: absolute position: absolute
top: -$outfit-thumbnail-original-size / 4 top: -$outfit-thumbnail-original-size / 4
width: $outfit-thumbnail-original-size width: $outfit-thumbnail-original-size
//> div
float: left
width: $outfit-content-width
.outfit-delete .outfit-delete
+reset-awesome-button +reset-awesome-button
+opacity(.5) +opacity(.5)
@ -55,23 +49,6 @@ $outfit-content-inner-width: $outfit-content-width - $outfit-header-padding
header header
display: block display: block
padding-left: $outfit-header-padding padding-left: $outfit-header-padding
.outfit-star
+icon
background:
image: image-url("unstarred.png")
position: left top
repeat: no-repeat
cursor: pointer
display: block
float: left
margin-left: -24px
/* makes it not take up inline space
&.starred .outfit-star
background-image: image-url("star.png")
&.loading .outfit-star
background-image: image-url("loading.gif")
&.loading.active .outfit-star
background-image: image-url("loading_current_outfit.gif")
h4 h4
cursor: pointer cursor: pointer
display: inline display: inline
@ -506,3 +483,4 @@ body.outfits-edit
#save-outfit-wrapper.shared-outfit #save-outfit-wrapper.shared-outfit
#current-outfit-permalink, #current-outfit-url #current-outfit-permalink, #current-outfit-url
display: inline-block display: inline-block

View file

@ -0,0 +1,9 @@
$icon-width: 16px
$icon-height: 16px
=icon
bottom: -2px
height: $icon-height
position: relative
width: $icon-width

View file

@ -0,0 +1,16 @@
@import star
body.outfits-index
#outfits
list-style: none
li
+outfit-star
h4
display: inline
.outfit-edit-link
font-size: 85%
margin-left: 1em

View file

@ -0,0 +1,27 @@
@import icon
=outfit-star
.outfit-star
+icon
background:
image: image-url("unstarred.png")
position: left top
repeat: no-repeat
cursor: pointer
display: block
float: left
margin-right: $icon-width / 2
&.starred .outfit-star
background-image: image-url("star.png")
&.loading .outfit-star
background-image: image-url("loading.gif")
&.loading.active .outfit-star
background-image: image-url("loading_current_outfit.gif")
=outfit-star-shifted
+outfit-star
.outfit-star
margin-left: -$icon-width * 1.5
margin-right: 0

View file

@ -11,8 +11,10 @@
@import items/index @import items/index
@import items/show @import items/show
@import outfits/edit @import outfits/edit
@import outfits/index
@import outfits/new @import outfits/new
@import outfits/show @import outfits/show
@import pets/bulk @import pets/bulk
@import static/terms @import static/terms
@import users/top_contributors @import users/top_contributors

View file

@ -34,6 +34,7 @@
%span %span
== Hey, #{link_to current_user.name, user_contributions_path(current_user)}! == Hey, #{link_to current_user.name, user_contributions_path(current_user)}!
== You have #{current_user.points} points. == You have #{current_user.points} points.
= link_to 'Outfits', current_user_outfits_path
= link_to 'Settings', Openneo::Auth.remote_settings_url = link_to 'Settings', Openneo::Auth.remote_settings_url
= link_to 'Log out', logout_path_with_return_to = link_to 'Log out', logout_path_with_return_to
- else - else
@ -64,3 +65,4 @@
Images &copy; 2000-2010 Neopets, Inc. All Rights Reserved. Images &copy; 2000-2010 Neopets, Inc. All Rights Reserved.
Used With Permission Used With Permission
= yield(:javascripts) = yield(:javascripts)

View file

@ -0,0 +1,5 @@
= outfit_li_for(outfit) do
.outfit-star
%h4= link_to outfit.name, outfit
= link_to_edit_outfit '(edit)', outfit, :class => 'outfit-edit-link'

View file

@ -0,0 +1,20 @@
- title 'Your outfits'
%p
These are the outfits that you've saved to Dress to Impress so far. To save
some more, head to the wardrobe and click Save Outfit in the top right
corner.
%p
The link for each outfit is totally public, so please feel free to share the
URL with the whole wide world.
- unless @outfits.empty?
%ul#outfits= render @outfits
- else
%p
You haven't saved any outfits yet.
- succeed ',' do
= link_to 'Start at the home page', root_path
enter a pet name or choose a color combination, create the outfit of your
dreams, and click "Save Outfit" in the top right corner.
%p
It'll be fantastic. Promise.

View file

@ -1,6 +1,8 @@
- title(@outfit.name || "Shared outfit") - title(@outfit.name || "Shared outfit")
%a.button#outfit-wardrobe-link{:href => wardrobe_path(:anchor => @outfit.to_query)} = link_to_edit_outfit(@outfit, :class => 'button', :id => 'outfit-wardrobe-link') do
Edit a copy Edit
- unless @outfit.user == current_user
a copy
- if @outfit.user_id - if @outfit.user_id
#outfit-user #outfit-user
Created by Created by
@ -15,3 +17,4 @@
var INITIAL_OUTFIT_DATA = #{@outfit.to_json}; var INITIAL_OUTFIT_DATA = #{@outfit.to_json};
= include_javascript_libraries :jquery, :swfobject = include_javascript_libraries :jquery, :swfobject
= include_javascripts :show_outfit_package = include_javascripts :show_outfit_package

View file

@ -23,7 +23,7 @@ OpenneoImpressItems::Application.routes.draw do |map|
resources :outfits, :only => [:show, :create, :update, :destroy] resources :outfits, :only => [:show, :create, :update, :destroy]
resources :pet_attributes, :only => [:index] resources :pet_attributes, :only => [:index]
match '/users/current-user/outfits.json' => 'outfits#for_current_user' match '/users/current-user/outfits' => 'outfits#index', :as => :current_user_outfits
match '/pets/load' => 'pets#load', :method => :post, :as => :load_pet match '/pets/load' => 'pets#load', :method => :post, :as => :load_pet
match '/pets/bulk' => 'pets#bulk', :as => :bulk_pets match '/pets/bulk' => 'pets#bulk', :as => :bulk_pets
@ -42,3 +42,4 @@ OpenneoImpressItems::Application.routes.draw do |map|
match '/terms' => 'static#terms', :as => :terms match '/terms' => 'static#terms', :as => :terms
end end

File diff suppressed because it is too large Load diff