Module ItemsHelper
In: app/helpers/items_helper.rb

Methods

Public Instance methods

[Source]

   # File app/helpers/items_helper.rb, line 2
2:   def country_select_tag
3:       select_tag 'country', countries, :onchange => "Back.no();Message.notify('#{t('actions.loading')}');#{remote_function(:url => { :action => :country }, :with => "#{question_with}+#{option_with_('country', '&')}")}"
4:   end

[Source]

    # File app/helpers/items_helper.rb, line 45
45:   def fast_link_to_item(image_name, item_id, width)
46:     fast_link(rounded(image_tag(image_name, {:width => width, :title => ''})), "items/#{item_id}")
47:   end

[Source]

    # File app/helpers/items_helper.rb, line 78
78:   def google_item_chart(item, question)
79:     percents = []
80:     country_names = @groups.map do |group|
81:       stat = Stat.get(item, group, question)
82:       percents << stat.win_percent.to_i
83:       "#{group.name} (#{stat.ratings})"
84:     end
85:     country_names.unshift("All (#{item.ratings(question.id)})")
86:     title = question.name.strip_tags.gsub(' ', '+')
87:     percents.unshift(item.win_percent(question.id).to_i)
88:     image_tag("http://chart.apis.google.com/chart?cht=bvs&chbh=60,40,10&chtt=#{title}&chxt=y&chd=t:#{percents.join(',')}&chs=420x300&chl=#{country_names.join('|')}")
89:   end

[Source]

     # File app/helpers/items_helper.rb, line 91
 91:   def google_map_votes(item, question_id = nil)
 92:     wins, losses = [], []
 93:     options = {
 94:       :select => "items_responses.item_id, responses.visit_id, ip_latitude, ip_longitude",
 95:       :conditions => { :active => true },
 96:       :joins => "INNER JOIN visits ON (visits.id=responses.visit_id) INNER JOIN items_responses ON (items_responses.response_id=responses.id) INNER JOIN items_prompts ON (items_prompts.item_id=#{item.id} AND responses.prompt_id=items_prompts.prompt_id)"
 97:     }
 98:     options[:joins] += " INNER JOIN prompts ON (responses.prompt_id=prompts.id AND prompts.question_id=#{question_id})" if question_id
 99:     Response.all(options).each do |response|
100:       geo = [response.ip_latitude, response.ip_longitude]
101:       unless geo.any? { |pos| pos.nil? }
102:         geo = geo.join(',')
103:         if response.item_id.to_i == item.id
104:           wins << geo
105:         else
106:           losses << geo
107:         end
108:       end
109:     end
110:     wins = wins.length > 0 ? "[#{wins.join('],[')}]" : ''
111:     losses = losses.length > 0 ? "[#{losses.join('],[')}]" : ''
112:     javascript_tag("
113:       Google.map([#{wins}], [#{losses}], 'world_map');
114:       Google.map([#{wins}], [#{losses}], 'asia_map', [38,105, 3]);
115:       Google.map([#{wins}], [#{losses}], 'us_map', [42,-90, 3]);
116:     ")
117:   end

[Source]

    # File app/helpers/items_helper.rb, line 33
33:   def item_display(item, thumb = :compare, options = {})
34:     return unless item
35:     if thumb == :thumb && options[:height] && item.attachment
36:       img = item.attachment.thumbnails.find_by_thumbnail('thumb')
37:       options.delete(:height) if img.height < options[:height]
38:     end
39:     path = item.attachment.public_filename(thumb)
40:     # we sometime get a bad path, fix it
41:     path = path[path =~ /\/system/, path.length] unless path[0,7] == "/system"
42:     item.attachment ? image_tag(path, options.merge(:title => '')) : item.description
43:   end

[Source]

    # File app/helpers/items_helper.rb, line 49
49:   def link_to_item(item, size = :thumb, options = {})
50:     link_to(rounded(item_display(item, size, options)), item)
51:   end

[Source]

    # File app/helpers/items_helper.rb, line 21
21:   def order_link(type, question_id, name = nil)
22:     active = ' active' if type == 'rank'
23:     link_to_remote(name || t("items.order.#{type}"), :url => { :action => :list, :order => type }, :with => question_with, :html => { :id => "#{type}_#{question_id}", :class => "order#{active}" })
24:   end

[Source]

    # File app/helpers/items_helper.rb, line 14
14:   def order_options
15:     options_for_select([ [t('items.order.date'), 'new'],
16:       [t('items.order.score'), 'score'],
17:       [t('items.order.percent'), 'percent']
18:     ], 'percent')
19:   end

[Source]

    # File app/helpers/items_helper.rb, line 61
61:   def pic_for_country(country_code)
62:     image_tag((country_code && !country_code.empty? && "#{country_code.downcase}.jpg") || "world.jpg")
63:   end

[Source]

   # File app/helpers/items_helper.rb, line 6
6:   def question_select_tag
7:     select_tag 'question', options_for_select(groups_for_select, @active_question_id), :onchange => "Back.no();$('.question').each(function(el) { $(this).hide() });$('#items_' + this.value).show();"
8:   end

[Source]

    # File app/helpers/items_helper.rb, line 69
69:   def ratings(item, question)
70:     if (@country_code && !@country_code.empty?)
71:       item.ratings_for_country(@country_code, question.id, false)
72:     else
73:       iq = item.items_questions.find_by_question_id(question.id)
74:       iq.wins + iq.losses
75:     end
76:   end

[Source]

    # File app/helpers/items_helper.rb, line 10
10:   def sort_select_tag
11:     select_tag 'sort', order_options, :onchange => remote_function(:url => { :action => :list }, :with => "#{question_with}+#{option_with_('sort', '&')}")
12:   end

[Source]

    # File app/helpers/items_helper.rb, line 53
53:   def type_instructions(type)
54:     t("item.submit.instructions.#{type}")
55:   end

[Source]

    # File app/helpers/items_helper.rb, line 57
57:   def type_style(type)
58:     @item_type != type && 'display:none'
59:   end

[Source]

    # File app/helpers/items_helper.rb, line 26
26:   def upload_links(type)
27:     ['upload', 'flickr', 'url'].map do |el|
28:       options = type == el ? { :class => 'active' } : {}
29:       build_upload_link(el, options)
30:     end.join(' ')
31:   end

[Source]

    # File app/helpers/items_helper.rb, line 65
65:   def wins(item, question)
66:     (@country_code && !@country_code.empty?) ? item.wins_for_country(@country_code, question_id) : item.items_questions.find_by_question_id(question.id).wins
67:   end

[Validate]