2010-11-05 15:45:05 -07:00
|
|
|
module OutfitsHelper
|
|
|
|
def destination_tag(value)
|
|
|
|
hidden_field_tag 'destination', value, :id => nil
|
|
|
|
end
|
2012-12-29 22:46:36 -08:00
|
|
|
|
|
|
|
def latest_contribution_description(contribution)
|
|
|
|
user = contribution.user
|
|
|
|
contributed = contribution.contributed
|
2013-01-09 16:40:35 -08:00
|
|
|
t 'outfits.new.latest_contribution.description_html',
|
2012-12-29 22:46:36 -08:00
|
|
|
:user_link => link_to(user.name, user_contributions_path(user)),
|
|
|
|
:contributed_description => contributed_description(contributed, false)
|
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
|
|
|
def link_to_edit_outfit(content_or_outfit, outfit_or_options, options={})
|
|
|
|
if block_given?
|
|
|
|
content = capture_haml(&Proc.new)
|
|
|
|
outfit = content_or_outfit
|
|
|
|
options = outfit_or_options
|
|
|
|
else
|
|
|
|
content = content_or_outfit
|
|
|
|
outfit = outfit_or_options
|
|
|
|
end
|
|
|
|
query = outfit.to_query
|
2012-08-09 15:32:33 -07:00
|
|
|
query << "&outfit=#{outfit.id}" if user_signed_in? && outfit.user_id == current_user.id
|
2011-03-23 15:23:01 -07:00
|
|
|
link_to content, wardrobe_path(:anchor => query), options
|
|
|
|
end
|
2012-12-29 22:56:58 -08:00
|
|
|
|
2013-01-26 09:11:42 -08:00
|
|
|
def search_helper(filter, standard_key)
|
2013-01-04 17:28:00 -08:00
|
|
|
key = translate("#{filter}.key")
|
|
|
|
default_value = translate("#{filter}.default_value")
|
|
|
|
content_tag :span, default_value, :class => 'search-helper',
|
2013-01-26 09:11:42 -08:00
|
|
|
'data-search-filter-key' => standard_key,
|
|
|
|
'data-search-filter-name' => key
|
2013-01-04 17:28:00 -08:00
|
|
|
end
|
|
|
|
|
2013-01-26 09:11:42 -08:00
|
|
|
def search_query_description(base, standard_key)
|
2013-01-04 17:28:00 -08:00
|
|
|
translate "#{base}.description_html",
|
2013-01-26 09:11:42 -08:00
|
|
|
:default_value => search_helper("#{base}.filter", standard_key)
|
2013-01-04 17:28:00 -08:00
|
|
|
end
|
|
|
|
|
2013-01-26 09:11:42 -08:00
|
|
|
def search_query_with_helper(base, standard_key)
|
2013-01-04 17:28:00 -08:00
|
|
|
translate "#{base}.query_html",
|
|
|
|
:filter_key => content_tag(:span, translate("#{base}.filter.key")),
|
2013-01-26 09:11:42 -08:00
|
|
|
: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))
|
2013-01-04 17:28:00 -08:00
|
|
|
end
|
2013-12-08 20:59:36 -08:00
|
|
|
|
|
|
|
def remote_load_pet_path
|
|
|
|
"http://#{Rails.configuration.neopia_host}/api/1/pet/customization"
|
|
|
|
end
|
2013-12-14 15:19:27 -08:00
|
|
|
|
|
|
|
def render_predicted_missing_species_by_color(species_by_color)
|
2013-12-26 20:36:48 -08:00
|
|
|
# Transform the Color => Array<Species> map into an Array<Pair<Color's
|
|
|
|
# human name (empty if standard), Array<Species>>>.
|
2013-12-14 15:19:27 -08:00
|
|
|
# TODO: i18n
|
|
|
|
standard = species_by_color.delete(:standard)
|
|
|
|
sorted_pairs = species_by_color.to_a.map { |k, v| [k.human_name, v] }.
|
|
|
|
sort_by { |k, v| k }
|
|
|
|
sorted_pairs.unshift(['', standard]) if standard
|
2013-12-26 20:36:48 -08:00
|
|
|
species_by_color[:standard] = standard # undo parameter mutation
|
2013-12-14 15:19:27 -08:00
|
|
|
|
|
|
|
first = true
|
|
|
|
contents = sorted_pairs.map { |color_human_name, species|
|
|
|
|
species_sentence = species.map(&:human_name).sort.to_sentence(
|
|
|
|
two_words_connector: ' or ', last_word_connector: ', or ')
|
|
|
|
content = first ? "Have you seen the #{color_human_name} #{species_sentence} wearing this item?" : "Or maybe the #{color_human_name} #{species_sentence}?"
|
|
|
|
first = false
|
|
|
|
content
|
|
|
|
}
|
|
|
|
contents.last << " If so, please model it above! Thanks!"
|
|
|
|
content_tags = contents.map { |c| content_tag(:p, c) }
|
|
|
|
content_tags.join('').html_safe
|
|
|
|
end
|
2013-01-04 17:28:00 -08:00
|
|
|
|
2012-12-29 22:56:58 -08:00
|
|
|
def outfit_creation_summary(outfit)
|
|
|
|
user = outfit.user
|
|
|
|
user_link = link_to(user.name, user_contributions_path(user))
|
|
|
|
created_at_ago = content_tag(:abbr, time_ago_in_words(@outfit.created_at),
|
|
|
|
:title => @outfit.created_at)
|
|
|
|
translate 'outfits.show.creation_summary_html',
|
|
|
|
:user_link => user_link,
|
|
|
|
:created_at_ago => created_at_ago
|
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
|
|
|
def outfit_li_for(outfit)
|
|
|
|
class_name = outfit.starred? ? 'starred' : nil
|
|
|
|
content_tag :li, :class => class_name, &Proc.new
|
|
|
|
end
|
|
|
|
|
2010-11-05 15:45:05 -07:00
|
|
|
def pet_attribute_select(name, collection, value=nil)
|
|
|
|
select_tag name,
|
|
|
|
options_from_collection_for_select(collection, :id, :human_name, value)
|
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|
2010-11-07 14:19:47 -08:00
|
|
|
def pet_name_tag(options={})
|
|
|
|
options = {:spellcheck => false, :id => nil}.merge(options)
|
|
|
|
text_field_tag 'name', nil, options
|
2010-11-05 15:45:05 -07:00
|
|
|
end
|
|
|
|
end
|
2011-03-23 15:23:01 -07:00
|
|
|
|