show outfit page

This commit is contained in:
Emi Matchu 2010-11-13 17:26:14 -05:00
parent b2b9722d6a
commit 9b0cf8b597
12 changed files with 150 additions and 17 deletions

View file

@ -1,5 +1,5 @@
class OutfitsController < ApplicationController class OutfitsController < ApplicationController
before_filter :find_outfit, :only => [:show, :update, :destroy] before_filter :find_authorized_outfit, :only => [:update, :destroy]
def create def create
if user_signed_in? if user_signed_in?
@ -31,7 +31,11 @@ class OutfitsController < ApplicationController
end end
def show def show
render :json => @outfit @outfit = Outfit.find(params[:id])
respond_to do |format|
format.html { render }
format.json { render :json => @outfit }
end
end end
def update def update
@ -48,7 +52,7 @@ class OutfitsController < ApplicationController
end end
end end
def find_outfit def find_authorized_outfit
raise ActiveRecord::RecordNotFound unless user_signed_in? raise ActiveRecord::RecordNotFound unless user_signed_in?
@outfit = current_user.outfits.find(params[:id]) @outfit = current_user.outfits.find(params[:id])
end end

View file

@ -1,5 +1,8 @@
class Outfit < ActiveRecord::Base class Outfit < ActiveRecord::Base
has_many :item_outfit_relationships, :dependent => :destroy has_many :item_outfit_relationships, :dependent => :destroy
has_many :worn_item_outfit_relationships, :class_name => 'ItemOutfitRelationship',
:conditions => {:is_worn => true}
has_many :worn_items, :through => :worn_item_outfit_relationships, :source => :item
belongs_to :pet_state belongs_to :pet_state
belongs_to :user belongs_to :user
@ -13,6 +16,10 @@ class Outfit < ActiveRecord::Base
:methods => [:color_id, :species_id, :worn_and_unworn_item_ids] :methods => [:color_id, :species_id, :worn_and_unworn_item_ids]
end end
def closet_item_ids
item_outfit_relationships.map(&:item_id)
end
def color_id def color_id
pet_state.pet_type.color_id pet_state.pet_type.color_id
end end
@ -21,6 +28,16 @@ class Outfit < ActiveRecord::Base
pet_state.pet_type.species_id pet_state.pet_type.species_id
end end
def to_query
{
:closet => closet_item_ids,
:color => color_id,
:objects => worn_item_ids,
:species => species_id,
:state => pet_state_id
}.to_query
end
def worn_and_unworn_item_ids def worn_and_unworn_item_ids
{:worn => [], :unworn => []}.tap do |output| {:worn => [], :unworn => []}.tap do |output|
item_outfit_relationships.each do |rel| item_outfit_relationships.each do |rel|
@ -43,4 +60,8 @@ class Outfit < ActiveRecord::Base
end end
self.item_outfit_relationships = new_rels self.item_outfit_relationships = new_rels
end end
def worn_item_ids
worn_and_unworn_item_ids[:worn]
end
end end

View file

@ -67,7 +67,7 @@ $container_width: 800px
#container #container
margin: 1em auto margin: 1em auto
padding-top: 3em padding-top: $container-top-padding
position: relative position: relative
width: $container_width width: $container_width

View file

@ -0,0 +1,29 @@
body.outfits-show
#title
float: left
#outfit-wardrobe-link
float: left
font-size: 85%
margin:
left: 2em
top: .75em
#outfit-user
float: right
margin-top: 1em
#preview-wrapper
clear: both
height: 400px
margin: 0 auto 1em
position: relative
width: 400px
#preview-swf
left: 0
position: absolute
top: 0
#outfit-items
text-align: center

View file

@ -26,3 +26,5 @@ $object-img-size: 80px
$object-width: 100px $object-width: 100px
$object-padding: 6px $object-padding: 6px
$nc-icon-size: 16px $nc-icon-size: 16px
$container-top-padding: 3em

View file

@ -12,6 +12,7 @@
@import items/show @import items/show
@import outfits/edit @import outfits/edit
@import outfits/new @import outfits/new
@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

@ -95,7 +95,7 @@
%button.outfit-delete &times; %button.outfit-delete &times;
.outfit-star .outfit-star
%h4 ${name} %h4 ${name}
%input.outfit-url{:type => 'text', :value => 'http://impress.openneo.net/outfits/FIXME'} %input.outfit-url{:type => 'text', :value => "http://#{request.host}/outfits/${id}"}
.outfit-delete-confirmation .outfit-delete-confirmation
%span Delete forever? %span Delete forever?
%a.outfit-delete-confirmation-yes{:href => '#'} yes %a.outfit-delete-confirmation-yes{:href => '#'} yes

View file

@ -0,0 +1,16 @@
- title @outfit.name
%a.button#outfit-wardrobe-link{:href => wardrobe_path(:anchor => @outfit.to_query)}
Edit a copy
#outfit-user
Created by
== #{link_to @outfit.user.name, user_contributions_path(@outfit.user)},
%span{:title => @outfit.created_at}= time_ago_in_words @outfit.created_at
ago
#preview-wrapper
#preview-swf
#outfit-items= render @outfit.worn_items
- content_for :javascripts do
:javascript
var INITIAL_OUTFIT_DATA = #{@outfit.to_json};
= include_javascript_libraries :jquery, :swfobject
= include_javascripts :show_outfit_package

View file

@ -13,3 +13,7 @@ javascripts:
new_outfit_package: new_outfit_package:
- public/javascripts/pet_query.js - public/javascripts/pet_query.js
- public/javascripts/outfits/new.js - public/javascripts/outfits/new.js
show_outfit_package:
- public/javascripts/wardrobe.js
- public/javascripts/outfits/show.js

View file

@ -0,0 +1,10 @@
var main_wardrobe = new Wardrobe(), View = Wardrobe.getStandardView({
Preview: {
swf_url: '/swfs/preview.swf?v=0.12',
wrapper: $('#preview-wrapper'),
placeholder: $('#preview-swf')
}
});
main_wardrobe.registerViews(View);
main_wardrobe.initialize();
main_wardrobe.outfit.loadData(INITIAL_OUTFIT_DATA);

View file

@ -705,9 +705,12 @@ function Wardrobe() {
this.events = {}; this.events = {};
function fireEvent(event_name, subarguments) { function fireEvent(event_name, subarguments) {
$.each(controller.events[event_name], function () { var events = controller.events[event_name];
this.apply(controller, subarguments); if(typeof events !== 'undefined') {
}); for(var i = 0; i < events.length; i++) {
events[i].apply(controller, subarguments);
}
}
} }
this.bind = function (event, callback) { this.bind = function (event, callback) {
@ -739,6 +742,18 @@ function Wardrobe() {
this.in_transaction = false; this.in_transaction = false;
function setFullOutfit(new_outfit) {
outfit = new_outfit;
controller.in_transaction = true;
controller.setPetTypeByColorAndSpecies(outfit.color_id, outfit.species_id);
controller.setPetStateById(outfit.pet_state_id);
controller.setClosetItemsByIds(outfit.getClosetItemIds());
controller.setWornItemsByIds(outfit.getWornItemIds());
controller.events.trigger('setOutfit', outfit);
controller.in_transaction = false;
controller.events.trigger('loadOutfit', outfit);
}
function setOutfitIdentity(new_outfit) { function setOutfitIdentity(new_outfit) {
new_outfit.cloneAttributesFrom(outfit); new_outfit.cloneAttributesFrom(outfit);
outfit = new_outfit; outfit = new_outfit;
@ -773,18 +788,14 @@ function Wardrobe() {
this.load = function (new_outfit_id) { this.load = function (new_outfit_id) {
Outfit.find(new_outfit_id, function (new_outfit) { Outfit.find(new_outfit_id, function (new_outfit) {
outfit = new_outfit.clone(); setFullOutfit(new_outfit.clone());
controller.in_transaction = true;
controller.setPetTypeByColorAndSpecies(outfit.color_id, outfit.species_id);
controller.setPetStateById(outfit.pet_state_id);
controller.setClosetItemsByIds(outfit.getClosetItemIds());
controller.setWornItemsByIds(outfit.getWornItemIds());
controller.events.trigger('setOutfit', outfit);
controller.in_transaction = false;
controller.events.trigger('loadOutfit', outfit);
}); });
} }
this.loadData = function (new_outfit_data) {
setFullOutfit(new Outfit(new_outfit_data));
}
this.create = function (attributes) { this.create = function (attributes) {
if(attributes) { if(attributes) {
outfit.starred = attributes.starred; outfit.starred = attributes.starred;

View file

@ -1879,6 +1879,41 @@ body.outfits-new #tell-the-world img {
width: 16px; width: 16px;
} }
/* line 2, ../../../app/stylesheets/outfits/_show.sass */
body.outfits-show #title {
float: left;
}
/* line 5, ../../../app/stylesheets/outfits/_show.sass */
body.outfits-show #outfit-wardrobe-link {
float: left;
font-size: 85%;
margin-left: 2em;
margin-top: 0.75em;
}
/* line 12, ../../../app/stylesheets/outfits/_show.sass */
body.outfits-show #outfit-user {
float: right;
margin-top: 1em;
}
/* line 16, ../../../app/stylesheets/outfits/_show.sass */
body.outfits-show #preview-wrapper {
clear: both;
height: 400px;
margin: 0 auto 1em;
position: relative;
width: 400px;
}
/* line 23, ../../../app/stylesheets/outfits/_show.sass */
body.outfits-show #preview-wrapper #preview-swf {
left: 0;
position: absolute;
top: 0;
}
/* line 28, ../../../app/stylesheets/outfits/_show.sass */
body.outfits-show #outfit-items {
text-align: center;
}
/* line 1, ../../../app/stylesheets/pets/_bulk.sass */ /* line 1, ../../../app/stylesheets/pets/_bulk.sass */
body.pets-bulk { body.pets-bulk {
text-align: center; text-align: center;