2011-07-20 12:16:22 -07:00
|
|
|
require 'cgi'
|
|
|
|
|
2011-07-12 17:03:04 -07:00
|
|
|
module ClosetHangersHelper
|
2013-01-01 18:42:58 -08:00
|
|
|
def closet_hangers_help_class(user)
|
|
|
|
'hidden' unless user.closet_hangers.empty?
|
2011-07-31 16:04:21 -07:00
|
|
|
end
|
|
|
|
|
2011-08-03 07:33:13 -07:00
|
|
|
def closet_hanger_partial_class(hanger)
|
|
|
|
'object'.tap do |class_name|
|
|
|
|
class_name << ' user-owns' if hanger.item.owned?
|
|
|
|
class_name << ' user-wants' if hanger.item.wanted?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-20 12:16:22 -07:00
|
|
|
def send_neomail_url(user)
|
|
|
|
"http://www.neopets.com/neomessages.phtml?type=send&recipient=#{CGI.escape @user.neopets_username}"
|
|
|
|
end
|
|
|
|
|
2011-07-30 16:45:28 -07:00
|
|
|
def hangers_group_visibility_field_name(owned)
|
|
|
|
owned ? :owned_closet_hangers_visibility : :wanted_closet_hangers_visibility
|
|
|
|
end
|
|
|
|
|
2011-07-30 19:34:27 -07:00
|
|
|
def closet_visibility_choices(*args)
|
2011-07-30 16:45:28 -07:00
|
|
|
ClosetVisibility.levels.map do |level|
|
2011-07-30 19:34:27 -07:00
|
|
|
[level.send(*args), level.id]
|
2011-07-30 16:45:28 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-01 18:42:58 -08:00
|
|
|
def closet_visibility_descriptions(subject=:items)
|
2011-07-30 19:08:38 -07:00
|
|
|
content = ''
|
|
|
|
ClosetVisibility.levels.each do |level|
|
2011-07-30 19:47:06 -07:00
|
|
|
content << content_tag(:li, level.description(subject), 'data-id' => level.id)
|
2011-07-30 19:08:38 -07:00
|
|
|
end
|
|
|
|
content_tag :ul, content.html_safe, :class => 'visibility-descriptions'
|
|
|
|
end
|
|
|
|
|
2011-07-29 07:52:04 -07:00
|
|
|
# Do we have either unlisted hangers that are owned/wanted, or non-empty
|
|
|
|
# owned/wanted lists?
|
|
|
|
def has_hangers?(owned)
|
|
|
|
# If we have unlisted hangers of this type, pass.
|
|
|
|
return true if @unlisted_closet_hangers_by_owned.has_key?(owned)
|
|
|
|
|
|
|
|
# Additionally, if we have no lists of this type, fail.
|
|
|
|
lists = @closet_lists_by_owned[owned]
|
|
|
|
return false unless lists
|
|
|
|
|
|
|
|
# If any of those lists are non-empty, pass.
|
|
|
|
lists.each do |list|
|
|
|
|
return true unless list.hangers.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Otherwise, all of the lists are empty. Fail.
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_lists?(owned)
|
|
|
|
@closet_lists_by_owned.has_key?(owned)
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_to_add_closet_list(content, options)
|
|
|
|
owned = options.delete(:owned)
|
|
|
|
path = new_user_closet_list_path current_user,
|
|
|
|
:closet_list => {:hangers_owned => owned}
|
|
|
|
link_to(content, path, options)
|
|
|
|
end
|
2013-01-01 18:42:58 -08:00
|
|
|
|
|
|
|
def long_closet_visibility_choices(subject)
|
|
|
|
ClosetVisibility.levels.map do |level|
|
|
|
|
["#{level.human_name}: #{level.description(subject)}", level.id]
|
|
|
|
end
|
|
|
|
end
|
2011-07-29 07:52:04 -07:00
|
|
|
|
2011-07-30 23:48:16 -07:00
|
|
|
def nc_icon_url
|
|
|
|
"http://#{request.host}#{image_path 'nc.png'}"
|
|
|
|
end
|
2012-04-08 13:59:51 -07:00
|
|
|
|
|
|
|
def petpage_closet_list_checked(closet_list, owned)
|
|
|
|
@visible_closet_lists_by_owned.has_key?(owned) &&
|
|
|
|
@visible_closet_lists_by_owned[owned].include?(closet_list)
|
|
|
|
end
|
|
|
|
|
|
|
|
def petpage_group_checked(owned)
|
|
|
|
@visible_groups.include?(owned)
|
|
|
|
end
|
2011-07-30 23:48:16 -07:00
|
|
|
|
|
|
|
def petpage_item_name(item)
|
2012-04-08 12:53:26 -07:00
|
|
|
item.name.gsub(/ On/i, ' O<b></b>n').html_safe
|
2011-07-30 23:48:16 -07:00
|
|
|
end
|
|
|
|
|
2011-08-02 17:01:48 -07:00
|
|
|
PETPAGE_IMAGE_URL_BLACKLIST = %w(window. ondrop)
|
|
|
|
def petpage_item_thumbnail_url(item)
|
|
|
|
url = item.thumbnail_url
|
|
|
|
|
|
|
|
# If the URL includes any of the blacklisted terms, use our redirect URL
|
|
|
|
PETPAGE_IMAGE_URL_BLACKLIST.each do |term|
|
|
|
|
if url.include?(term)
|
|
|
|
url = item_url(item, :format => :gif)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
url
|
|
|
|
end
|
|
|
|
|
2011-07-20 09:39:18 -07:00
|
|
|
def public_perspective?
|
|
|
|
@public_perspective
|
|
|
|
end
|
2011-07-22 14:55:05 -07:00
|
|
|
|
2011-07-30 23:48:16 -07:00
|
|
|
PETPAGE_HANGER_BATCH_SIZE = 5
|
|
|
|
def render_batched_petpage_hangers(hangers)
|
|
|
|
output do |html|
|
|
|
|
hangers.in_groups_of(PETPAGE_HANGER_BATCH_SIZE) do |batch|
|
|
|
|
content = batch.map do |hanger|
|
|
|
|
render 'petpage_hanger', :hanger => hanger if hanger
|
|
|
|
end.join.html_safe
|
|
|
|
html << content_tag(:div, content, :class => 'dti-item-row')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-29 07:52:04 -07:00
|
|
|
def render_closet_lists(lists)
|
|
|
|
if lists
|
|
|
|
render :partial => 'closet_lists/closet_list', :collection => lists,
|
|
|
|
:locals => {:show_controls => !public_perspective?}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_unlisted_closet_hangers(owned)
|
2011-07-30 16:45:28 -07:00
|
|
|
hangers_content = render :partial => 'closet_hanger',
|
|
|
|
:collection => @unlisted_closet_hangers_by_owned[owned],
|
|
|
|
:locals => {:show_controls => !public_perspective?}
|
2011-07-22 14:55:05 -07:00
|
|
|
end
|
2011-07-30 16:47:04 -07:00
|
|
|
|
|
|
|
def unlisted_hangers_count(owned)
|
|
|
|
hangers = @unlisted_closet_hangers_by_owned[owned]
|
|
|
|
hangers ? hangers.size : 0
|
|
|
|
end
|
2012-12-30 11:15:55 -08:00
|
|
|
|
|
|
|
def closet_lists_group_name(subject, owned)
|
|
|
|
ownership_key = owned ? 'owned_by' : 'wanted_by'
|
|
|
|
if subject == :you
|
|
|
|
translate "closet_lists.groups.#{ownership_key}.you"
|
|
|
|
else
|
|
|
|
translate "closet_lists.groups.#{ownership_key}.another_user",
|
2013-01-01 18:42:58 -08:00
|
|
|
:user_name => subject
|
2012-12-30 11:15:55 -08:00
|
|
|
end
|
|
|
|
end
|
2013-01-01 18:42:58 -08:00
|
|
|
|
|
|
|
def closet_hangers_subject(user)
|
|
|
|
public_perspective? ? user.name : :you
|
|
|
|
end
|
2011-07-12 17:03:04 -07:00
|
|
|
end
|
2011-07-20 09:39:18 -07:00
|
|
|
|