From 6e80c228c120db4a9476191ed83524ec2641af41 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 30 Mar 2014 22:37:33 -0500 Subject: [PATCH] include prank message on wardrobe page --- app/assets/javascripts/outfits/edit.js | 32 +++++++++++++++++++++++ app/assets/stylesheets/outfits/_edit.sass | 3 +++ app/models/color.rb | 2 +- app/views/outfits/edit.html.haml | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/outfits/edit.js b/app/assets/javascripts/outfits/edit.js index ae5d898a..3a70094b 100644 --- a/app/assets/javascripts/outfits/edit.js +++ b/app/assets/javascripts/outfits/edit.js @@ -1289,6 +1289,38 @@ View.Search = function (wardrobe) { //wardrobe.pet_attributes.bind('update', prepBuildHelper('only', getSpecies)); } +View.PrankColorMessage = function(wardrobe) { + var el = $('#prank-color-message'); + var nameEls = el.find('.prank-color-message-name'); + var colorsById = null; + var petType = null; + + function updateMessage() { + if (colorsById !== null && petType !== null) { + var color = colorsById[petType.color_id]; + if (color.prank) { + nameEls.text(color.unfunny_name); + el.show(); + } else { + el.hide(); + } + } + } + + wardrobe.pet_attributes.bind('update', function(attributes) { + colorsById = {}; + attributes.color.forEach(function(color) { + colorsById[color.id] = color; + }); + updateMessage(); + }); + + wardrobe.outfits.bind('updatePetType', function(newPetType) { + petType = newPetType; + updateMessage(); + }); +} + var userbar_sessions_link = $('#userbar a:last'); var userbar_message_el = $('#userbar-session-message').prependTo('#userbar'); diff --git a/app/assets/stylesheets/outfits/_edit.sass b/app/assets/stylesheets/outfits/_edit.sass index d59f1ec4..1f5d35ff 100644 --- a/app/assets/stylesheets/outfits/_edit.sass +++ b/app/assets/stylesheets/outfits/_edit.sass @@ -826,3 +826,6 @@ body.outfits-edit #current-outfit-permalink display: none !important + #prank-color-message + display: none + margin: 0 1em diff --git a/app/models/color.rb b/app/models/color.rb index 625dd2d8..746eded6 100644 --- a/app/models/color.rb +++ b/app/models/color.rb @@ -10,7 +10,7 @@ class Color < ActiveRecord::Base validates :name, presence: true def as_json(options={}) - {:id => id, :name => human_name} + {id: id, name: human_name, unfunny_name: unfunny_human_name, prank: prank?} end def human_name diff --git a/app/views/outfits/edit.html.haml b/app/views/outfits/edit.html.haml index 378c31d9..976b2e76 100644 --- a/app/views/outfits/edit.html.haml +++ b/app/views/outfits/edit.html.haml @@ -48,7 +48,7 @@ #save-success= t '.sidebar.notifications.outfits.save.success' #save-error #preview-closet.sidebar-view - = prank_color_message('%{color}') + = prank_color_message(''.html_safe) %ul #preview-outfits.sidebar-view %ul#preview-outfits-list