From 7f2ce2839bc560e23643b2f7c9c3bb530686bed3 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 31 Jan 2013 19:46:34 -0600 Subject: [PATCH] appearance dropdown - wow, that was easy --- app/models/pet_state.rb | 8 +- app/models/pet_type.rb | 6 +- app/stylesheets/outfits/_edit.sass | 12 +- app/views/outfits/edit.html.haml | 2 +- config/locales/en-MEEP.yml | 15 +- config/locales/en.yml | 3 +- public/javascripts/outfits/edit.js | 34 +- public/javascripts/wardrobe.js | 27 +- public/stylesheets/compiled/screen.css | 424 +++++++++++-------------- 9 files changed, 246 insertions(+), 285 deletions(-) diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb index 292e1775..b2bf06b8 100644 --- a/app/models/pet_state.rb +++ b/app/models/pet_state.rb @@ -35,6 +35,10 @@ class PetState < ActiveRecord::Base group("pet_states.id"). order("(mood_id = 1) DESC, COUNT(effect_assets.remote_id) ASC, COUNT(parents_swf_assets.swf_asset_id) DESC, female ASC, SUM(parents_swf_assets.swf_asset_id) ASC") + def as_json(options={}) + serializable_hash :only => [:id], :methods => [:gender_mood_description] + end + def reassign_children_to!(main_pet_state) self.contributions.each do |contribution| contribution.contributed = main_pet_state @@ -117,7 +121,9 @@ class PetState < ActiveRecord::Base end def gender_mood_description - if labeled? + if unconverted? + I18n.translate('pet_states.description.unconverted') + elsif labeled? I18n.translate('pet_states.description.main', :gender => gender_name, :mood => mood_name) else diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 66f679f1..93156c4e 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -50,7 +50,7 @@ class PetType < ActiveRecord::Base { :id => id, :body_id => body_id, - :pet_state_ids => pet_state_ids + :pet_states => pet_states.emotion_order.as_json } else {:image_hash => image_hash} @@ -105,10 +105,6 @@ class PetType < ActiveRecord::Base pet_state = PetState.from_pet_type_and_biology_info(self, biology) pet_state end - - def pet_state_ids - pet_states.select('pet_states.id').emotion_order.map(&:id) - end before_save do if @origin_pet && @origin_pet.name =~ IMAGE_CPN_ACCEPTABLE_NAME diff --git a/app/stylesheets/outfits/_edit.sass b/app/stylesheets/outfits/_edit.sass index 249b5d35..6638a8d1 100644 --- a/app/stylesheets/outfits/_edit.sass +++ b/app/stylesheets/outfits/_edit.sass @@ -55,17 +55,7 @@ body.outfits-edit #pet-info form display: inline #pet-state-form - ul - list-style: none - &, li - display: inline - input - display: none - label - +awesome-button - margin: 0 .25em - li.selected button - +awesome-button-color($marked_button_color) + font-size: 85% &.hidden visibility: hidden #save-outfit-wrapper diff --git a/app/views/outfits/edit.html.haml b/app/views/outfits/edit.html.haml index 42fcf2d9..570f0b13 100644 --- a/app/views/outfits/edit.html.haml +++ b/app/views/outfits/edit.html.haml @@ -9,7 +9,7 @@ %input{:type => "submit", :value => t('.pet_type.form.submit')} %form#pet-state-form = t '.pet_state_form.header' - %ul + %select #save-outfit-wrapper %a#current-outfit-permalink{:target => '_blank'} = image_tag 'link_go.png', :alt => t('.outfit.permalink.name'), diff --git a/config/locales/en-MEEP.yml b/config/locales/en-MEEP.yml index cecea409..4eca87cd 100644 --- a/config/locales/en-MEEP.yml +++ b/config/locales/en-MEEP.yml @@ -480,7 +480,7 @@ en-MEEP: form: submit: Meep pet_state_form: - header: "Gender/Emeepshuns:" + header: "Meepearance:" outfit: permalink: name: Permameep @@ -657,6 +657,19 @@ en-MEEP: clone: Meep a copy creation_summary_html: Meeped by %{user_link}, %{created_at_ago} ago + pet_states: + description: + main: "%{gender} %{mood}" + gender: + female: Feepmale + male: Meep + mood: + happy: ":)" + sad: ":(" + sick: "X(" + unconverted: Unconveeped + unlabeled: Unleeped + pets: bulk: needed_items: diff --git a/config/locales/en.yml b/config/locales/en.yml index 5d35bfab..39518b4a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -511,7 +511,7 @@ en: form: submit: Go pet_state_form: - header: "Gender/Emotions:" + header: "Appearance:" outfit: permalink: name: Permalink @@ -716,6 +716,7 @@ en: happy: Happy sad: Sad sick: Sick + unconverted: Unconverted unlabeled: Unlabeled pets: diff --git a/public/javascripts/outfits/edit.js b/public/javascripts/outfits/edit.js index 9e6ea9b9..206c3c49 100644 --- a/public/javascripts/outfits/edit.js +++ b/public/javascripts/outfits/edit.js @@ -370,7 +370,7 @@ View.Hash = function (wardrobe) { singleOutfitResponse('updatePetState', function (pet_state) { var pet_type = wardrobe.outfits.getPetType(); - if(pet_state.id != data.state && pet_type && (data.state || pet_state.id != pet_type.pet_state_ids[0])) { + if(pet_state.id != data.state && pet_type && (data.state || pet_state.id != pet_type.pet_states[0].id)) { changeQuery({state: pet_state.id}); } }); @@ -929,37 +929,33 @@ View.Outfits = function (wardrobe) { View.PetStateForm = function (wardrobe) { var INPUT_NAME = 'pet_state_id', form_query = '#pet-state-form', form = $(form_query), - ul = form.children('ul'), - button_query = form_query + ' button'; - $(button_query).live('click', function (e) { - e.preventDefault(); - wardrobe.outfits.setPetStateById(+$(this).data('value')); + select = form.children('select'); + + select.change(function (e) { + var id = parseInt(select.children(':selected').val(), 10); + wardrobe.outfits.setPetStateById(id); }); function updatePetState(pet_state) { if(pet_state) { - ul.children('li.selected').removeClass('selected'); - $(button_query + '[data-value=' + pet_state.id + ']').parent().addClass('selected'); + select.val(pet_state.id); } } wardrobe.outfits.bind('petTypeLoaded', function (pet_type) { - var ids = pet_type.pet_state_ids, i, id, li, button, label; - ul.children().remove(); - if(ids.length == 1) { + var pet_states = pet_type.pet_states, i, id, option; + select.children().remove(); + if(pet_states.length == 1) { form.addClass('hidden'); } else { form.removeClass('hidden'); - for(var i = 0; i < ids.length; i++) { + for(var i = 0; i < pet_states.length; i++) { id = 'pet-state-button-' + i; - li = $('
  • '); - button = $('