2010-05-15 10:47:46 -07:00
|
|
|
module ItemsHelper
|
2017-06-17 12:28:07 -07:00
|
|
|
JNItemsURLFormat = 'https://items.jellyneo.net/search/?name=%s&name_type=3'
|
2012-10-21 13:57:17 -07:00
|
|
|
|
2010-06-08 07:39:23 -07:00
|
|
|
module PetTypeImage
|
2023-10-25 15:16:46 -07:00
|
|
|
Format = 'https://pets.neopets.com/cp/%s/%i/%i.png'
|
2011-05-02 15:07:56 -07:00
|
|
|
|
2010-06-08 07:39:23 -07:00
|
|
|
Emotions = {
|
|
|
|
:happy => 1,
|
|
|
|
:sad => 2,
|
|
|
|
:angry => 3,
|
|
|
|
:ill => 4
|
|
|
|
}
|
2011-05-02 15:07:56 -07:00
|
|
|
|
2010-06-08 07:39:23 -07:00
|
|
|
Sizes = {
|
|
|
|
:face => 1,
|
|
|
|
:thumb => 2,
|
|
|
|
:zoom => 3,
|
|
|
|
:full => 4
|
|
|
|
}
|
|
|
|
end
|
2011-05-02 15:07:56 -07:00
|
|
|
|
2010-06-08 07:39:23 -07:00
|
|
|
def standard_species_search_links
|
2013-01-21 12:55:48 -08:00
|
|
|
build_on_pet_types(Species.alphabetical) do |pet_type|
|
2010-06-08 07:39:23 -07:00
|
|
|
image = pet_type_image(pet_type, :happy, :zoom)
|
|
|
|
query = "species:#{pet_type.species.name}"
|
|
|
|
link_to(image, items_path(:q => query))
|
|
|
|
end
|
|
|
|
end
|
2011-10-10 19:43:46 -07:00
|
|
|
|
|
|
|
def closet_list_verb(owned)
|
|
|
|
ClosetHanger.verb(:you, owned)
|
|
|
|
end
|
2012-08-06 18:15:31 -07:00
|
|
|
|
|
|
|
def owned_icon
|
2013-01-01 19:15:17 -08:00
|
|
|
image_tag 'owned.png', :title => t('items.item.owned.description'),
|
|
|
|
:alt => t('items.item.owned.abbr')
|
2012-08-06 18:15:31 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def wanted_icon
|
2013-01-01 19:15:17 -08:00
|
|
|
image_tag 'wanted.png', :title => t('items.item.wanted.description'),
|
|
|
|
:alt => t('items.item.wanted.abbr')
|
2012-08-06 18:15:31 -07:00
|
|
|
end
|
2011-07-12 22:21:48 -07:00
|
|
|
|
2011-07-22 13:18:15 -07:00
|
|
|
def closeted_icons_for(item)
|
|
|
|
content = ''.html_safe
|
|
|
|
|
2012-08-06 18:15:31 -07:00
|
|
|
content << owned_icon if item.owned?
|
|
|
|
content << wanted_icon if item.wanted?
|
2011-07-22 13:18:15 -07:00
|
|
|
|
|
|
|
content_tag :div, content, :class => 'closeted-icons'
|
2011-07-12 22:21:48 -07:00
|
|
|
end
|
2012-08-06 18:15:31 -07:00
|
|
|
|
|
|
|
def nc_icon
|
2013-01-01 19:10:49 -08:00
|
|
|
image_tag 'nc.png', :title => t('items.item.nc.description'),
|
|
|
|
:alt => t('items.item.nc.abbr'), :class => 'nc-icon'
|
2012-08-06 18:15:31 -07:00
|
|
|
end
|
2011-05-02 15:07:56 -07:00
|
|
|
|
2010-09-08 19:49:39 -07:00
|
|
|
def nc_icon_for(item)
|
2012-08-06 18:15:31 -07:00
|
|
|
nc_icon if item.nc?
|
2010-09-08 19:49:39 -07:00
|
|
|
end
|
2011-05-02 15:07:56 -07:00
|
|
|
|
2012-10-21 13:57:17 -07:00
|
|
|
def jn_items_url_for(item)
|
|
|
|
sprintf(JNItemsURLFormat, CGI::escape(item.name))
|
2010-09-08 19:49:39 -07:00
|
|
|
end
|
2012-05-23 17:09:35 -07:00
|
|
|
|
|
|
|
def shop_wizard_url_for(item)
|
2023-10-25 15:16:46 -07:00
|
|
|
"https://www.neopets.com/market.phtml?type=wizard&string=#{CGI::escape item.name}"
|
2012-05-23 17:09:35 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def super_shop_wizard_url_for(item)
|
2023-10-25 15:16:46 -07:00
|
|
|
"https://www.neopets.com/portal/supershopwiz.phtml?string=#{CGI::escape item.name}"
|
2012-05-23 17:09:35 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def trading_post_url_for(item)
|
2023-10-25 15:16:46 -07:00
|
|
|
"https://www.neopets.com/island/tradingpost.phtml?type=browse&criteria=item_exact&search_string=#{CGI::escape item.name}"
|
2012-05-23 17:09:35 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def auction_genie_url_for(item)
|
2023-10-25 15:16:46 -07:00
|
|
|
"https://www.neopets.com/genie.phtml?type=process_genie&criteria=exact&auctiongenie=#{CGI::escape item.name}"
|
2012-05-23 17:09:35 -07:00
|
|
|
end
|
2011-05-02 15:07:56 -07:00
|
|
|
|
2024-01-21 00:39:20 -08:00
|
|
|
def render_trades(trades)
|
|
|
|
trades.map do |trade|
|
|
|
|
link_to trade.user.name, user_closet_hangers_path(trade.user)
|
2011-07-30 21:19:28 -07:00
|
|
|
end.to_sentence.html_safe
|
|
|
|
end
|
2012-10-24 20:09:05 -07:00
|
|
|
|
|
|
|
def format_contribution_count(count)
|
2012-10-24 20:16:01 -07:00
|
|
|
" (×#{count})".html_safe if count > 1
|
2012-10-24 20:09:05 -07:00
|
|
|
end
|
2011-07-30 21:19:28 -07:00
|
|
|
|
2013-06-22 16:31:46 -07:00
|
|
|
def render_item_link(item)
|
2023-08-02 11:34:27 -07:00
|
|
|
render(partial: 'items/item_link', locals: {item: item})
|
2013-06-22 16:31:46 -07:00
|
|
|
end
|
|
|
|
|
2023-11-03 16:20:02 -07:00
|
|
|
def nc_trade_value_updated_at_text(nc_trade_value)
|
|
|
|
return nil if nc_trade_value.updated_at.nil?
|
|
|
|
|
|
|
|
# Render both "[X] [days] ago", and also the exact date, only including the
|
|
|
|
# year if it's not this same year.
|
|
|
|
time_ago_str = time_ago_in_words nc_trade_value.updated_at
|
|
|
|
date_str = nc_trade_value.updated_at.year != Date.today.year ?
|
|
|
|
nc_trade_value.updated_at.strftime("%b %-d") :
|
|
|
|
nc_trade_value.updated_at.strftime("%b %-d, %Y")
|
|
|
|
|
|
|
|
"Last updated: #{date_str} (#{time_ago_str} ago)"
|
|
|
|
end
|
|
|
|
|
2010-06-08 07:39:23 -07:00
|
|
|
private
|
2011-05-02 15:07:56 -07:00
|
|
|
|
|
|
|
def build_on_pet_types(species, special_color=nil, &block)
|
|
|
|
species_ids = species.map(&:id)
|
|
|
|
pet_types = special_color ?
|
2013-01-21 17:34:39 -08:00
|
|
|
PetType.where(:color_id => special_color.id, :species_id => species_ids).
|
|
|
|
order(:species_id).includes_child_translations :
|
2011-05-02 15:07:56 -07:00
|
|
|
PetType.random_basic_per_species(species.map(&:id))
|
|
|
|
pet_types.map(&block).join.html_safe
|
2010-06-08 07:39:23 -07:00
|
|
|
end
|
2011-05-02 15:07:56 -07:00
|
|
|
|
2010-06-08 07:39:23 -07:00
|
|
|
def pet_type_image(pet_type, emotion, size)
|
|
|
|
emotion_id = PetTypeImage::Emotions[emotion]
|
|
|
|
size_id = PetTypeImage::Sizes[size]
|
2010-11-14 20:14:04 -08:00
|
|
|
src = sprintf(PetTypeImage::Format, pet_type.basic_image_hash, emotion_id, size_id)
|
2010-06-08 07:39:23 -07:00
|
|
|
human_name = pet_type.species.name.humanize
|
|
|
|
image_tag(src, :alt => human_name, :title => human_name)
|
2010-05-16 12:01:38 -07:00
|
|
|
end
|
2010-05-15 10:47:46 -07:00
|
|
|
end
|
2011-05-02 15:07:56 -07:00
|
|
|
|