forked from OpenNeo/impress
localize outfits#edit search helpers
This commit is contained in:
parent
9c37e894f7
commit
8c348d4535
4 changed files with 32 additions and 18 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -1260,9 +1260,13 @@ View.Search = function (wardrobe) {
|
|||
|
||||
function prepBuildHelper(type, getSet) {
|
||||
return function (objs) {
|
||||
var select = $('<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 = $('<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++) {
|
||||
$('<option/>', {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;
|
||||
}));
|
||||
|
||||
|
|
Loading…
Reference in a new issue