forked from OpenNeo/impress
distinguish between owning and wanting an item
This commit is contained in:
parent
01ba06b1b4
commit
85af53417b
8 changed files with 71 additions and 48 deletions
|
@ -13,7 +13,7 @@ class ClosetHangersController < ApplicationController
|
|||
|
||||
def index
|
||||
@user = User.find params[:user_id]
|
||||
@closet_hangers = @user.closet_hangers.alphabetical_by_item_name.includes(:item)
|
||||
@closet_hangers = @user.closet_hangers.owned_before_wanted.alphabetical_by_item_name.includes(:item)
|
||||
@public_perspective = params.has_key?(:public) || !user_is?(@user)
|
||||
end
|
||||
|
||||
|
@ -28,14 +28,17 @@ class ClosetHangersController < ApplicationController
|
|||
# expectations, though, and I can't really think of a genuinely RESTful way
|
||||
# to pull this off.
|
||||
def update
|
||||
@closet_hanger = current_user.closet_hangers.find_or_initialize_by_item_id(@item.id)
|
||||
owned = (params[:closet_hanger][:owned] == 'true') if params[:closet_hanger]
|
||||
owned ||= true
|
||||
|
||||
@closet_hanger = current_user.closet_hangers.find_or_initialize_by_item_id_and_owned(@item.id, owned)
|
||||
@closet_hanger.attributes = params[:closet_hanger]
|
||||
|
||||
unless @closet_hanger.quantity == 0 # save the hanger, new record or not
|
||||
if @closet_hanger.save
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:success] = "Success! You own #{@closet_hanger.quantity} #{@item.name.pluralize}."
|
||||
flash[:success] = "Success! You #{@closet_hanger.verb(:you)} #{@closet_hanger.quantity} #{@item.name.pluralize}."
|
||||
redirect_back!(@item)
|
||||
}
|
||||
|
||||
|
@ -44,7 +47,7 @@ class ClosetHangersController < ApplicationController
|
|||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:alert] = "We couldn't save how many of this item you own: #{@closet_hanger.errors.full_messages.to_sentence}"
|
||||
flash[:alert] = "We couldn't save how many of this item you #{@closet_hanger.verb(:you)}: #{@closet_hanger.errors.full_messages.to_sentence}"
|
||||
redirect_back!(@item)
|
||||
}
|
||||
|
||||
|
@ -74,7 +77,7 @@ class ClosetHangersController < ApplicationController
|
|||
end
|
||||
|
||||
def redirect_after_destroy!
|
||||
flash[:success] = "Success! You do not own #{@item.name}."
|
||||
flash[:success] = "Success! You do not #{@closet_hanger.verb(:you)} #{@item.name}."
|
||||
redirect_back!(@item)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,8 +40,11 @@ class ItemsController < ApplicationController
|
|||
def show
|
||||
@item = Item.find params[:id]
|
||||
if user_signed_in?
|
||||
@hanger = current_user.closet_hangers.find_or_initialize_by_item_id(@item.id)
|
||||
@hanger.quantity ||= 1
|
||||
@hangers = [true, false].map do |owned|
|
||||
hanger = current_user.closet_hangers.find_or_initialize_by_item_id_and_owned(@item.id, owned)
|
||||
hanger.quantity ||= 1
|
||||
hanger
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,12 +2,19 @@ class ClosetHanger < ActiveRecord::Base
|
|||
belongs_to :item
|
||||
belongs_to :user
|
||||
|
||||
attr_accessible :quantity
|
||||
attr_accessible :owned, :quantity
|
||||
|
||||
validates :item_id, :uniqueness => {:scope => :user_id}
|
||||
validates :item_id, :uniqueness => {:scope => [:user_id, :owned]}
|
||||
validates :quantity, :numericality => {:greater_than => 0}
|
||||
validates_presence_of :item, :user
|
||||
|
||||
scope :alphabetical_by_item_name, joins(:item).order(Item.arel_table[:name])
|
||||
scope :owned_before_wanted, order(arel_table[:owned].desc)
|
||||
|
||||
def verb(subject=:someone)
|
||||
base = (owned?) ? 'own' : 'want'
|
||||
base + 's' if subject != :you
|
||||
base
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -63,25 +63,23 @@ body.items-show
|
|||
height: 16px
|
||||
width: 16px
|
||||
|
||||
#closet-hanger-form
|
||||
#closet-hangers
|
||||
border: 1px solid $module-border-color
|
||||
float: right
|
||||
font-size: 85%
|
||||
padding: 1em .5em .5em
|
||||
padding: 1em
|
||||
width: 18em
|
||||
|
||||
label, header
|
||||
display: block
|
||||
font-weight: bold
|
||||
|
||||
header
|
||||
font-size: 125%
|
||||
|
||||
form
|
||||
padding: .5em 0
|
||||
|
||||
input[type=number]
|
||||
width: 4em
|
||||
|
||||
#closet-hanger-form-your-items
|
||||
display: block
|
||||
margin-top: .5em
|
||||
text-align: right
|
||||
|
||||
p
|
||||
font-family: $main-font
|
||||
|
||||
|
|
|
@ -12,19 +12,22 @@
|
|||
== Rarity: #{@item.rarity_index} (#{@item.rarity})
|
||||
= link_to 'NeoItems', neoitems_url_for(@item), :class => 'button'
|
||||
|
||||
- if @hanger
|
||||
= form_for(@hanger, :url => user_item_closet_hanger_path(current_user, @item), :html => {:id => 'closet-hanger-form'}) do |f|
|
||||
- if @hanger.new_record?
|
||||
%header Do you own this item?
|
||||
%p
|
||||
We can help you track your closet.
|
||||
= f.hidden_field :quantity
|
||||
= f.submit "I own this item!"
|
||||
- else
|
||||
= f.label :quantity, "How many of these do you own?"
|
||||
= f.number_field :quantity, :min => 0, :required => true
|
||||
= f.submit "Save"
|
||||
= link_to 'Your Items →'.html_safe, user_closet_hangers_path(current_user), :id => 'closet-hanger-form-your-items'
|
||||
- if @hangers
|
||||
#closet-hangers
|
||||
%header
|
||||
Track this in
|
||||
= link_to 'Your Items', user_closet_hangers_path(current_user)
|
||||
- @hangers.each do |hanger|
|
||||
= form_for(hanger, :url => user_item_closet_hanger_path(current_user, @item)) do |f|
|
||||
- if hanger.new_record?
|
||||
= f.hidden_field :quantity
|
||||
= f.hidden_field :owned
|
||||
= f.submit "I #{hanger.verb(:you)} this item!"
|
||||
- else
|
||||
= f.hidden_field :owned
|
||||
= f.label :quantity, "How many of these do you #{hanger.verb(:you)}?"
|
||||
= f.number_field :quantity, :min => 0, :required => true
|
||||
= f.submit "Save"
|
||||
%p= @item.description
|
||||
|
||||
#item-zones
|
||||
|
|
10
db/migrate/20110722180616_add_owned_to_closet_hangers.rb
Normal file
10
db/migrate/20110722180616_add_owned_to_closet_hangers.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class AddOwnedToClosetHangers < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :closet_hangers, :owned, :boolean, :null => false, :default => true
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :closet_hangers, :owned
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110720183722) do
|
||||
ActiveRecord::Schema.define(:version => 20110722180616) do
|
||||
|
||||
create_table "auth_servers", :force => true do |t|
|
||||
t.string "short_name", :limit => 10, :null => false
|
||||
|
@ -26,6 +26,7 @@ ActiveRecord::Schema.define(:version => 20110720183722) do
|
|||
t.integer "quantity"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "owned", :default => true, :null => false
|
||||
end
|
||||
|
||||
create_table "contributions", :force => true do |t|
|
||||
|
@ -177,6 +178,7 @@ ActiveRecord::Schema.define(:version => 20110720183722) do
|
|||
t.boolean "forum_admin", :default => false, :null => false
|
||||
t.boolean "forum_moderator"
|
||||
t.boolean "image_mode_tester", :default => false, :null => false
|
||||
t.text "closet_description", :null => false
|
||||
t.string "neopets_username"
|
||||
end
|
||||
|
||||
|
@ -188,4 +190,3 @@ ActiveRecord::Schema.define(:version => 20110720183722) do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -620,7 +620,7 @@ body.closet_hangers-index #closet-hangers-contact {
|
|||
}
|
||||
/* line 38, ../../../app/stylesheets/closet_hangers/_index.sass */
|
||||
body.closet_hangers-index #closet-hangers-contact a {
|
||||
background-image: url('/images/neomail.png?1311187553');
|
||||
background-image: url('/images/neomail.png?1311362308');
|
||||
background-position: left center;
|
||||
background-repeat: no-repeat;
|
||||
padding-left: 18px;
|
||||
|
@ -1202,31 +1202,29 @@ body.items-show .nc-icon {
|
|||
width: 16px;
|
||||
}
|
||||
/* line 66, ../../../app/stylesheets/items/_show.sass */
|
||||
body.items-show #closet-hanger-form {
|
||||
body.items-show #closet-hangers {
|
||||
border: 1px solid #006600;
|
||||
float: right;
|
||||
font-size: 85%;
|
||||
padding: 1em 0.5em 0.5em;
|
||||
padding: 1em;
|
||||
width: 18em;
|
||||
}
|
||||
/* line 73, ../../../app/stylesheets/items/_show.sass */
|
||||
body.items-show #closet-hanger-form label, body.items-show #closet-hanger-form header {
|
||||
body.items-show #closet-hangers label, body.items-show #closet-hangers header {
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* line 77, ../../../app/stylesheets/items/_show.sass */
|
||||
body.items-show #closet-hanger-form input[type=number] {
|
||||
width: 4em;
|
||||
body.items-show #closet-hangers header {
|
||||
font-size: 125%;
|
||||
}
|
||||
/* line 80, ../../../app/stylesheets/items/_show.sass */
|
||||
body.items-show #closet-hanger-form #closet-hanger-form-your-items {
|
||||
display: block;
|
||||
margin-top: 0.5em;
|
||||
text-align: right;
|
||||
body.items-show #closet-hangers form {
|
||||
padding: 0.5em 0;
|
||||
}
|
||||
/* line 85, ../../../app/stylesheets/items/_show.sass */
|
||||
body.items-show #closet-hanger-form p {
|
||||
font-family: "Droid Sans", Helvetica, Arial, Verdana, sans-serif;
|
||||
/* line 83, ../../../app/stylesheets/items/_show.sass */
|
||||
body.items-show #closet-hangers input[type=number] {
|
||||
width: 4em;
|
||||
}
|
||||
|
||||
@import url(../shared/jquery.jgrowl.css);
|
||||
|
@ -1807,7 +1805,7 @@ body.outfits-edit .object:hover ul, body.outfits-edit .object:hover .object-info
|
|||
}
|
||||
/* line 418, ../../../app/stylesheets/outfits/_edit.sass */
|
||||
body.outfits-edit .nc-icon {
|
||||
background: url('/images/nc.png?1310666180') no-repeat;
|
||||
background: url('/images/nc.png?1311362308') no-repeat;
|
||||
height: 16px;
|
||||
position: absolute;
|
||||
right: 16px;
|
||||
|
|
Loading…
Reference in a new issue