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
|
def index
|
||||||
@user = User.find params[:user_id]
|
@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)
|
@public_perspective = params.has_key?(:public) || !user_is?(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,14 +28,17 @@ class ClosetHangersController < ApplicationController
|
||||||
# expectations, though, and I can't really think of a genuinely RESTful way
|
# expectations, though, and I can't really think of a genuinely RESTful way
|
||||||
# to pull this off.
|
# to pull this off.
|
||||||
def update
|
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]
|
@closet_hanger.attributes = params[:closet_hanger]
|
||||||
|
|
||||||
unless @closet_hanger.quantity == 0 # save the hanger, new record or not
|
unless @closet_hanger.quantity == 0 # save the hanger, new record or not
|
||||||
if @closet_hanger.save
|
if @closet_hanger.save
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
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)
|
redirect_back!(@item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +47,7 @@ class ClosetHangersController < ApplicationController
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
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)
|
redirect_back!(@item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +77,7 @@ class ClosetHangersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_after_destroy!
|
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)
|
redirect_back!(@item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,8 +40,11 @@ class ItemsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@item = Item.find params[:id]
|
@item = Item.find params[:id]
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
@hanger = current_user.closet_hangers.find_or_initialize_by_item_id(@item.id)
|
@hangers = [true, false].map do |owned|
|
||||||
@hanger.quantity ||= 1
|
hanger = current_user.closet_hangers.find_or_initialize_by_item_id_and_owned(@item.id, owned)
|
||||||
|
hanger.quantity ||= 1
|
||||||
|
hanger
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,19 @@ class ClosetHanger < ActiveRecord::Base
|
||||||
belongs_to :item
|
belongs_to :item
|
||||||
belongs_to :user
|
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 :quantity, :numericality => {:greater_than => 0}
|
||||||
validates_presence_of :item, :user
|
validates_presence_of :item, :user
|
||||||
|
|
||||||
scope :alphabetical_by_item_name, joins(:item).order(Item.arel_table[:name])
|
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
|
end
|
||||||
|
|
||||||
|
|
|
@ -63,25 +63,23 @@ body.items-show
|
||||||
height: 16px
|
height: 16px
|
||||||
width: 16px
|
width: 16px
|
||||||
|
|
||||||
#closet-hanger-form
|
#closet-hangers
|
||||||
border: 1px solid $module-border-color
|
border: 1px solid $module-border-color
|
||||||
float: right
|
float: right
|
||||||
font-size: 85%
|
font-size: 85%
|
||||||
padding: 1em .5em .5em
|
padding: 1em
|
||||||
width: 18em
|
width: 18em
|
||||||
|
|
||||||
label, header
|
label, header
|
||||||
display: block
|
display: block
|
||||||
font-weight: bold
|
font-weight: bold
|
||||||
|
|
||||||
|
header
|
||||||
|
font-size: 125%
|
||||||
|
|
||||||
|
form
|
||||||
|
padding: .5em 0
|
||||||
|
|
||||||
input[type=number]
|
input[type=number]
|
||||||
width: 4em
|
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})
|
== Rarity: #{@item.rarity_index} (#{@item.rarity})
|
||||||
= link_to 'NeoItems', neoitems_url_for(@item), :class => 'button'
|
= link_to 'NeoItems', neoitems_url_for(@item), :class => 'button'
|
||||||
|
|
||||||
- if @hanger
|
- if @hangers
|
||||||
= form_for(@hanger, :url => user_item_closet_hanger_path(current_user, @item), :html => {:id => 'closet-hanger-form'}) do |f|
|
#closet-hangers
|
||||||
- if @hanger.new_record?
|
%header
|
||||||
%header Do you own this item?
|
Track this in
|
||||||
%p
|
= link_to 'Your Items', user_closet_hangers_path(current_user)
|
||||||
We can help you track your closet.
|
- @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 :quantity
|
||||||
= f.submit "I own this item!"
|
= f.hidden_field :owned
|
||||||
|
= f.submit "I #{hanger.verb(:you)} this item!"
|
||||||
- else
|
- else
|
||||||
= f.label :quantity, "How many of these do you own?"
|
= 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.number_field :quantity, :min => 0, :required => true
|
||||||
= f.submit "Save"
|
= f.submit "Save"
|
||||||
= link_to 'Your Items →'.html_safe, user_closet_hangers_path(current_user), :id => 'closet-hanger-form-your-items'
|
|
||||||
%p= @item.description
|
%p= @item.description
|
||||||
|
|
||||||
#item-zones
|
#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.
|
# 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|
|
create_table "auth_servers", :force => true do |t|
|
||||||
t.string "short_name", :limit => 10, :null => false
|
t.string "short_name", :limit => 10, :null => false
|
||||||
|
@ -26,6 +26,7 @@ ActiveRecord::Schema.define(:version => 20110720183722) do
|
||||||
t.integer "quantity"
|
t.integer "quantity"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.boolean "owned", :default => true, :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "contributions", :force => true do |t|
|
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_admin", :default => false, :null => false
|
||||||
t.boolean "forum_moderator"
|
t.boolean "forum_moderator"
|
||||||
t.boolean "image_mode_tester", :default => false, :null => false
|
t.boolean "image_mode_tester", :default => false, :null => false
|
||||||
|
t.text "closet_description", :null => false
|
||||||
t.string "neopets_username"
|
t.string "neopets_username"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -188,4 +190,3 @@ ActiveRecord::Schema.define(:version => 20110720183722) do
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -620,7 +620,7 @@ body.closet_hangers-index #closet-hangers-contact {
|
||||||
}
|
}
|
||||||
/* line 38, ../../../app/stylesheets/closet_hangers/_index.sass */
|
/* line 38, ../../../app/stylesheets/closet_hangers/_index.sass */
|
||||||
body.closet_hangers-index #closet-hangers-contact a {
|
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-position: left center;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
padding-left: 18px;
|
padding-left: 18px;
|
||||||
|
@ -1202,31 +1202,29 @@ body.items-show .nc-icon {
|
||||||
width: 16px;
|
width: 16px;
|
||||||
}
|
}
|
||||||
/* line 66, ../../../app/stylesheets/items/_show.sass */
|
/* line 66, ../../../app/stylesheets/items/_show.sass */
|
||||||
body.items-show #closet-hanger-form {
|
body.items-show #closet-hangers {
|
||||||
border: 1px solid #006600;
|
border: 1px solid #006600;
|
||||||
float: right;
|
float: right;
|
||||||
font-size: 85%;
|
font-size: 85%;
|
||||||
padding: 1em 0.5em 0.5em;
|
padding: 1em;
|
||||||
width: 18em;
|
width: 18em;
|
||||||
}
|
}
|
||||||
/* line 73, ../../../app/stylesheets/items/_show.sass */
|
/* 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;
|
display: block;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
/* line 77, ../../../app/stylesheets/items/_show.sass */
|
/* line 77, ../../../app/stylesheets/items/_show.sass */
|
||||||
body.items-show #closet-hanger-form input[type=number] {
|
body.items-show #closet-hangers header {
|
||||||
width: 4em;
|
font-size: 125%;
|
||||||
}
|
}
|
||||||
/* line 80, ../../../app/stylesheets/items/_show.sass */
|
/* line 80, ../../../app/stylesheets/items/_show.sass */
|
||||||
body.items-show #closet-hanger-form #closet-hanger-form-your-items {
|
body.items-show #closet-hangers form {
|
||||||
display: block;
|
padding: 0.5em 0;
|
||||||
margin-top: 0.5em;
|
|
||||||
text-align: right;
|
|
||||||
}
|
}
|
||||||
/* line 85, ../../../app/stylesheets/items/_show.sass */
|
/* line 83, ../../../app/stylesheets/items/_show.sass */
|
||||||
body.items-show #closet-hanger-form p {
|
body.items-show #closet-hangers input[type=number] {
|
||||||
font-family: "Droid Sans", Helvetica, Arial, Verdana, sans-serif;
|
width: 4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
@import url(../shared/jquery.jgrowl.css);
|
@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 */
|
/* line 418, ../../../app/stylesheets/outfits/_edit.sass */
|
||||||
body.outfits-edit .nc-icon {
|
body.outfits-edit .nc-icon {
|
||||||
background: url('/images/nc.png?1310666180') no-repeat;
|
background: url('/images/nc.png?1311362308') no-repeat;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 16px;
|
right: 16px;
|
||||||
|
|
Loading…
Reference in a new issue