<%!
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}">${h.literal(acontent) if (badge == 'dummy' or badge.type == "thumbnail") else 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>

<%def name="select_form(badges, title, none_text, input_name, input_type='checkbox', no_text='')">
<fieldset>
    <legend>${title}</legend>

    %if badges:
    <ul class="nobullet">
        %if input_type == 'radio':
        <li>
            <label>
                <input type="${input_type}" value=""
                       name="${input_name}" />
                ${no_text if no_text else _('No Badge')}
            </label>
        </li>
        %endif
        %for b in badges:
        <li>
            <label>
                <input type="${input_type}" value="${b.id}"
                       name="${input_name}" />
                ${badge(b, force_visible=True)}
                %if not b.visible:
                <em>(${_('invisible')})</em>
                %endif
            </label>
        </li>
        %endfor
    </ul>
    %else:
    <p>${_(u"No Badges")}</p>
    %endif
</fieldset>
</%def>
