%! from cgi import escape from galaxy.web.framework.helpers import iff from random import random from sys import maxint from math import floor from galaxy.model import Tag, ItemTagAssociation %> ## Render a tagging element if there is a tagged_item. %if tagged_item is not None: %if tag_type == "individual": ${render_individual_tagging_element( user=user, tagged_item=tagged_item, elt_context=elt_context, in_form=in_form, input_size=input_size, tag_click_fn=tag_click_fn, use_toggle_link=use_toggle_link )} %elif tag_type == "community": ${render_community_tagging_element(tagged_item=tagged_item, elt_context=elt_context, tag_click_fn=tag_click_fn)} %endif %endif ## Render HTML for a list of tags. <%def name="render_tagging_element_html(elt_id=None, tags=None, editable=True, use_toggle_link=True, input_size='15', in_form=False, tag_type='individual', render_add_tag_button=True)"> ## Useful attributes. <% num_tags = len( tags ) %>
%def> ## Render community tagging element. <%def name="render_community_tagging_element(tagged_item=None, elt_context=None, use_toggle_link=False, tag_click_fn='default_tag_click_fn')"> ## Build HTML. <% elt_id = int ( floor ( random()*maxint ) ) community_tags = trans.app.tag_handler.get_community_tags( trans, item=tagged_item, limit=5 ) %> ${self.render_tagging_element_html(elt_id=elt_id, \ tags=community_tags, \ use_toggle_link=use_toggle_link, \ editable=False, tag_type="community")} ## Set up tag click function. %def> ## Render individual tagging element. <%def name="render_individual_tagging_element(user=None, tagged_item=None, elt_context=None, use_toggle_link=True, in_form=False, input_size='15', tag_click_fn='default_tag_click_fn', get_toggle_link_text_fn='default_get_toggle_link_text_fn', editable=True, render_add_tag_button=True)"> ## Useful attributes. <% # Useful ids. tagged_item_id = str( trans.security.encode_id ( tagged_item.id ) ) elt_id = int ( floor ( random()*maxint ) ) # Get list of user's item tags. TODO: this could be moved to a database query for speed purposes. item_tags = [ tag for tag in tagged_item.tags if ( tag.user == user ) ] %> ## Build HTML. ${self.render_tagging_element_html(elt_id=elt_id, tags=item_tags, editable=editable, use_toggle_link=use_toggle_link, input_size=input_size, in_form=in_form, render_add_tag_button=render_add_tag_button)} ## Build script that augments tags using progressive javascript. ## Use style to hide/display the tag area. %def>