<%!
from adhocracy.lib.helpers.badge_helper import generate_thumbnail_tag
%>
<%def name="badge(badge, force_visible=False)">
<%
# dummy badge
if badge == 'dummy':
   spanclass = 'abadge badge_dummy'
   aclass    = ''
   atitle    = 'badge'
   acontent  = 'badge'

else:
    # invisible badge
   if not badge.visible and not force_visible:
      return ''

   # thumbnail badge
   if badge.type == "thumbnail":
      spanclass = "thumbnailbadge badge_%s" % badge.id
      aclass    = 'ttip'
      atitle    = '%s - %s' % (badge.title, badge.description)
      acontent  = generate_thumbnail_tag(badge)

   # common badge
   else:
       spanclass = "abadge badge_%s" % badge.id
       aclass    = badge.description.strip() and 'ttip' or ''
       atitle    = badge.description
       acontent  = badge.title
%>
<span class="${spanclass}">
    <span class="${aclass}" title="${atitle}">${(badge == 'dummy' or badge.type == "thumbnail") and h.literal(acontent) or acontent}</span>
</span>
</%def>

<%def name="badges(badges)">
    %for badge_ in badges:
        ${badge(badge_)}
    %endfor
</%def>

<%def name="badge_styles(badges)">
<style type="text/css" media="screen">
    %for badge_ in badges:
    .badge_${badge_.id}.abadge:before { color: ${badge_.color}; }
    %endfor
</style>

</%def>

<%def name="badge_selector(badges, field_name)">
%for b in badges:
    <label>
    <input type="checkbox" name="${field_name}" value="${b.id}"/>
    ${badge(b, force_visible=True)}
    </label>
%endfor
</%def>

