diff --git a/app/helpers/outfits_helper.rb b/app/helpers/outfits_helper.rb
index 5dd74503..06220510 100644
--- a/app/helpers/outfits_helper.rb
+++ b/app/helpers/outfits_helper.rb
@@ -25,22 +25,29 @@ module OutfitsHelper
link_to content, wardrobe_path(:anchor => query), options
end
- def search_helper(filter)
+ def search_helper(filter, standard_key)
key = translate("#{filter}.key")
default_value = translate("#{filter}.default_value")
content_tag :span, default_value, :class => 'search-helper',
- 'data-search-filter' => key
+ 'data-search-filter-key' => standard_key,
+ 'data-search-filter-name' => key
end
- def search_query_description(base)
+ def search_query_description(base, standard_key)
translate "#{base}.description_html",
- :default_value => search_helper("#{base}.filter")
+ :default_value => search_helper("#{base}.filter", standard_key)
end
- def search_query_with_helper(base)
+ def search_query_with_helper(base, standard_key)
translate "#{base}.query_html",
:filter_key => content_tag(:span, translate("#{base}.filter.key")),
- :filter_value => search_helper("#{base}.filter")
+ :filter_value => search_helper("#{base}.filter", standard_key)
+ end
+
+ def search_query(translation_key, filter_key)
+ base = "outfits.edit.search.examples.#{translation_key}"
+ content_tag(:dt, search_query_with_helper(base, filter_key)) +
+ content_tag(:dd, search_query_description(base, filter_key))
end
def outfit_creation_summary(outfit)
diff --git a/app/views/outfits/edit.html.haml b/app/views/outfits/edit.html.haml
index 56d882cf..f0e36d0f 100644
--- a/app/views/outfits/edit.html.haml
+++ b/app/views/outfits/edit.html.haml
@@ -109,12 +109,8 @@
%div
%dt= t '.search.examples.flags.query'
%dd= t '.search.examples.flags.description'
- %div
- %dt= search_query_with_helper '.search.examples.species'
- %dd= search_query_description '.search.examples.species'
- %div
- %dt= search_query_with_helper '.search.examples.type'
- %dd= search_query_description '.search.examples.type'
+ %div= search_query 'species', 'species'
+ %div= search_query 'type', 'occupies'
#preview-search-form-loading= t '.search.loading'
#preview-search-form-error.possible-error
#preview-search-form-no-results
diff --git a/config/locales/pt.yml b/config/locales/pt.yml
index 6e032d42..b3c32857 100644
--- a/config/locales/pt.yml
+++ b/config/locales/pt.yml
@@ -202,7 +202,7 @@ pt:
query: espécies:shoyru
description: mostra qualquer item que um Shoyru pode vestir
type:
- query: ocupa:chapéu -restringe:cabelo
+ query: ocupa:chapéus -restringe:cabelo
description: 'mostra qualquer item que ocupa a zona do "chapéu", mas não se restringe a zona do "cabelo" '
newest_items:
header: Novos itens
@@ -462,7 +462,7 @@ pt:
type:
filter:
key: ocupa
- default_value: fundo
+ default_value: fundosdeimagem
query_html: "%{filter_key}:%{filter_value}"
description_html: 'mostra como resultado qualquer item que ocupe a zona de %{default_value} '
userbar:
diff --git a/public/javascripts/outfits/edit.js b/public/javascripts/outfits/edit.js
index 39049a5c..281a1cc4 100644
--- a/public/javascripts/outfits/edit.js
+++ b/public/javascripts/outfits/edit.js
@@ -1260,9 +1260,13 @@ View.Search = function (wardrobe) {
function prepBuildHelper(type, getSet) {
return function (objs) {
- var select = $('',
- {'class': 'search-helper', 'data-search-filter': type}),
- span = $('span.search-helper[data-search-filter=' + type + ']');
+ var span = $('span.search-helper[data-search-filter-key=' + type + ']');
+ var filterName = span.attr('data-search-filter-name');
+ var select = $('', {
+ 'class': 'search-helper',
+ 'data-search-filter': filterName
+ });
+ var defaultValue = span.get(0).innerText;
objs = getSet(objs);
for(var i = 0, l = objs.length; i < l; i++) {
$('', {text: objs[i].name}).appendTo(select);
@@ -1270,12 +1274,19 @@ View.Search = function (wardrobe) {
span.replaceWith(function () {
return select.clone().fadeIn('fast');
});
+
+ // have to set selected after it's already in the DOM; not sure why :/
+ $('select.search-helper[data-search-filter=' + filterName + '] option').each(function () {
+ if(this.innerText == defaultValue) {
+ this.selected = "selected";
+ }
+ });
}
}
function getSpecies(x) { return x.species }
- wardrobe.item_zone_sets.bind('update', prepBuildHelper('type', function (x) {
+ wardrobe.item_zone_sets.bind('update', prepBuildHelper('occupies', function (x) {
return x;
}));