[3] | 1 | from mako import runtime, filters, cache |
---|
| 2 | UNDEFINED = runtime.UNDEFINED |
---|
| 3 | __M_dict_builtin = dict |
---|
| 4 | __M_locals_builtin = locals |
---|
| 5 | _magic_number = 5 |
---|
| 6 | _modified_time = 1287725327.3571129 |
---|
| 7 | _template_filename=u'templates/tagging_common.mako' |
---|
| 8 | _template_uri=u'root/../tagging_common.mako' |
---|
| 9 | _template_cache=cache.Cache(__name__, _modified_time) |
---|
| 10 | _source_encoding=None |
---|
| 11 | _exports = ['render_tagging_element_html', 'render_individual_tagging_element', 'render_community_tagging_element'] |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | # SOURCE LINE 1 |
---|
| 15 | |
---|
| 16 | from cgi import escape |
---|
| 17 | from galaxy.web.framework.helpers import iff |
---|
| 18 | from random import random |
---|
| 19 | from sys import maxint |
---|
| 20 | from math import floor |
---|
| 21 | from galaxy.model import Tag, ItemTagAssociation |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | def render_body(context,**pageargs): |
---|
| 25 | context.caller_stack._push_frame() |
---|
| 26 | try: |
---|
| 27 | __M_locals = __M_dict_builtin(pageargs=pageargs) |
---|
| 28 | in_form = context.get('in_form', UNDEFINED) |
---|
| 29 | def render_community_tagging_element(tagged_item=None,elt_context=None,use_toggle_link=False,tag_click_fn='default_tag_click_fn'): |
---|
| 30 | return render_render_community_tagging_element(context.locals_(__M_locals),tagged_item,elt_context,use_toggle_link,tag_click_fn) |
---|
| 31 | elt_context = context.get('elt_context', UNDEFINED) |
---|
| 32 | use_toggle_link = context.get('use_toggle_link', UNDEFINED) |
---|
| 33 | user = context.get('user', UNDEFINED) |
---|
| 34 | def 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): |
---|
| 35 | return render_render_individual_tagging_element(context.locals_(__M_locals),user,tagged_item,elt_context,use_toggle_link,in_form,input_size,tag_click_fn,get_toggle_link_text_fn,editable,render_add_tag_button) |
---|
| 36 | tag_click_fn = context.get('tag_click_fn', UNDEFINED) |
---|
| 37 | input_size = context.get('input_size', UNDEFINED) |
---|
| 38 | tagged_item = context.get('tagged_item', UNDEFINED) |
---|
| 39 | tag_type = context.get('tag_type', UNDEFINED) |
---|
| 40 | __M_writer = context.writer() |
---|
| 41 | # SOURCE LINE 8 |
---|
| 42 | __M_writer(u'\n\n') |
---|
| 43 | # SOURCE LINE 11 |
---|
| 44 | if tagged_item is not None: |
---|
| 45 | # SOURCE LINE 12 |
---|
| 46 | if tag_type == "individual": |
---|
| 47 | # SOURCE LINE 13 |
---|
| 48 | __M_writer(u' ') |
---|
| 49 | __M_writer(unicode(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 ))) |
---|
| 50 | __M_writer(u'\n') |
---|
| 51 | # SOURCE LINE 14 |
---|
| 52 | elif tag_type == "community": |
---|
| 53 | # SOURCE LINE 15 |
---|
| 54 | __M_writer(u' ') |
---|
| 55 | __M_writer(unicode(render_community_tagging_element(tagged_item=tagged_item, elt_context=elt_context, tag_click_fn=tag_click_fn))) |
---|
| 56 | __M_writer(u'\n') |
---|
| 57 | # SOURCE LINE 18 |
---|
| 58 | __M_writer(u'\n') |
---|
| 59 | # SOURCE LINE 85 |
---|
| 60 | __M_writer(u'\n\n') |
---|
| 61 | # SOURCE LINE 103 |
---|
| 62 | __M_writer(u'\n\n\n') |
---|
| 63 | return '' |
---|
| 64 | finally: |
---|
| 65 | context.caller_stack._pop_frame() |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | def render_render_tagging_element_html(context,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): |
---|
| 69 | context.caller_stack._push_frame() |
---|
| 70 | try: |
---|
| 71 | h = context.get('h', UNDEFINED) |
---|
| 72 | unicode = context.get('unicode', UNDEFINED) |
---|
| 73 | isinstance = context.get('isinstance', UNDEFINED) |
---|
| 74 | len = context.get('len', UNDEFINED) |
---|
| 75 | str = context.get('str', UNDEFINED) |
---|
| 76 | __M_writer = context.writer() |
---|
| 77 | # SOURCE LINE 20 |
---|
| 78 | __M_writer(u'\n') |
---|
| 79 | # SOURCE LINE 22 |
---|
| 80 | __M_writer(u' ') |
---|
| 81 | |
---|
| 82 | num_tags = len( tags ) |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | # SOURCE LINE 24 |
---|
| 86 | __M_writer(u'\n <div class="tag-element"\n') |
---|
| 87 | # SOURCE LINE 26 |
---|
| 88 | if elt_id: |
---|
| 89 | # SOURCE LINE 27 |
---|
| 90 | __M_writer(u' id="') |
---|
| 91 | __M_writer(unicode(elt_id)) |
---|
| 92 | __M_writer(u'"\n') |
---|
| 93 | # SOURCE LINE 30 |
---|
| 94 | if num_tags == 0 and not editable: |
---|
| 95 | # SOURCE LINE 31 |
---|
| 96 | __M_writer(u' style="display: none"\n') |
---|
| 97 | # SOURCE LINE 33 |
---|
| 98 | __M_writer(u' >\n') |
---|
| 99 | # SOURCE LINE 34 |
---|
| 100 | if use_toggle_link: |
---|
| 101 | # SOURCE LINE 35 |
---|
| 102 | __M_writer(u' <a class="toggle-link" href="#">') |
---|
| 103 | __M_writer(unicode(num_tags)) |
---|
| 104 | __M_writer(u' Tag') |
---|
| 105 | __M_writer(unicode(iff( num_tags == 1, "", "s"))) |
---|
| 106 | __M_writer(u'</a>\n') |
---|
| 107 | # SOURCE LINE 37 |
---|
| 108 | __M_writer(u' <div class="tag-area \n') |
---|
| 109 | # SOURCE LINE 38 |
---|
| 110 | if tag_type == 'individual': |
---|
| 111 | # SOURCE LINE 39 |
---|
| 112 | __M_writer(u' individual-tag-area\n') |
---|
| 113 | # SOURCE LINE 41 |
---|
| 114 | __M_writer(u' ">\n\n') |
---|
| 115 | # SOURCE LINE 44 |
---|
| 116 | for tag in tags: |
---|
| 117 | # SOURCE LINE 45 |
---|
| 118 | __M_writer(u' ') |
---|
| 119 | |
---|
| 120 | ## Handle both Tag and ItemTagAssociation objects. |
---|
| 121 | if isinstance( tag, Tag ): |
---|
| 122 | tag_name = tag.name |
---|
| 123 | tag_value = None |
---|
| 124 | elif isinstance( tag, ItemTagAssociation ): |
---|
| 125 | tag_name = tag.user_tname |
---|
| 126 | tag_value = tag.user_value |
---|
| 127 | ## Convert tag name, value to unicode. |
---|
| 128 | if isinstance( tag_name, str ): |
---|
| 129 | tag_name = unicode( escape( tag_name ), 'utf-8' ) |
---|
| 130 | if tag_value: |
---|
| 131 | tag_value = unicode( escape( tag_value ), 'utf-8' ) |
---|
| 132 | if tag_value: |
---|
| 133 | tag_str = tag_name + ":" + tag_value |
---|
| 134 | else: |
---|
| 135 | tag_str = tag_name |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | # SOURCE LINE 62 |
---|
| 139 | __M_writer(u'\n <span class="tag-button">\n <span class="tag-name">') |
---|
| 140 | # SOURCE LINE 64 |
---|
| 141 | __M_writer(unicode(tag_str)) |
---|
| 142 | __M_writer(u'</span>\n') |
---|
| 143 | # SOURCE LINE 65 |
---|
| 144 | if editable: |
---|
| 145 | # SOURCE LINE 66 |
---|
| 146 | __M_writer(u' <img class="delete-tag-img" src="') |
---|
| 147 | __M_writer(unicode(h.url_for('/static/images/delete_tag_icon_gray.png'))) |
---|
| 148 | __M_writer(u'"/>\n') |
---|
| 149 | # SOURCE LINE 68 |
---|
| 150 | __M_writer(u' </span>\n') |
---|
| 151 | # SOURCE LINE 70 |
---|
| 152 | __M_writer(u' \n') |
---|
| 153 | # SOURCE LINE 72 |
---|
| 154 | if editable: |
---|
| 155 | # SOURCE LINE 73 |
---|
| 156 | if in_form: |
---|
| 157 | # SOURCE LINE 74 |
---|
| 158 | __M_writer(u' <textarea class="tag-input" rows=\'1\' cols=\'') |
---|
| 159 | __M_writer(unicode(input_size)) |
---|
| 160 | __M_writer(u"'></textarea>\n") |
---|
| 161 | # SOURCE LINE 75 |
---|
| 162 | else: |
---|
| 163 | # SOURCE LINE 76 |
---|
| 164 | __M_writer(u' <input class="tag-input" type=\'text\' size=\'') |
---|
| 165 | __M_writer(unicode(input_size)) |
---|
| 166 | __M_writer(u"'/>\n") |
---|
| 167 | # SOURCE LINE 79 |
---|
| 168 | if render_add_tag_button: |
---|
| 169 | # SOURCE LINE 80 |
---|
| 170 | __M_writer(u" <img src='") |
---|
| 171 | __M_writer(unicode(h.url_for('/static/images/fugue/tag--plus.png'))) |
---|
| 172 | __M_writer(u'\' class="add-tag-button tooltip" title="Add tags"/>\n') |
---|
| 173 | # SOURCE LINE 83 |
---|
| 174 | __M_writer(u' </div>\n </div>\n') |
---|
| 175 | return '' |
---|
| 176 | finally: |
---|
| 177 | context.caller_stack._pop_frame() |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | def render_render_individual_tagging_element(context,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): |
---|
| 181 | context.caller_stack._push_frame() |
---|
| 182 | try: |
---|
| 183 | isinstance = context.get('isinstance', UNDEFINED) |
---|
| 184 | unicode = context.get('unicode', UNDEFINED) |
---|
| 185 | int = context.get('int', UNDEFINED) |
---|
| 186 | h = context.get('h', UNDEFINED) |
---|
| 187 | self = context.get('self', UNDEFINED) |
---|
| 188 | dict = context.get('dict', UNDEFINED) |
---|
| 189 | str = context.get('str', UNDEFINED) |
---|
| 190 | trans = context.get('trans', UNDEFINED) |
---|
| 191 | __M_writer = context.writer() |
---|
| 192 | # SOURCE LINE 107 |
---|
| 193 | __M_writer(u'\n') |
---|
| 194 | # SOURCE LINE 109 |
---|
| 195 | __M_writer(u' ') |
---|
| 196 | |
---|
| 197 | # Useful ids. |
---|
| 198 | tagged_item_id = str( trans.security.encode_id ( tagged_item.id ) ) |
---|
| 199 | elt_id = int ( floor ( random()*maxint ) ) |
---|
| 200 | |
---|
| 201 | # Get list of user's item tags. TODO: this could be moved to a database query for speed purposes. |
---|
| 202 | item_tags = [ tag for tag in tagged_item.tags if ( tag.user == user ) ] |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | # SOURCE LINE 116 |
---|
| 206 | __M_writer(u'\n \n') |
---|
| 207 | # SOURCE LINE 119 |
---|
| 208 | __M_writer(u' ') |
---|
| 209 | __M_writer(unicode(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))) |
---|
| 210 | __M_writer(u'\n \n') |
---|
| 211 | # SOURCE LINE 122 |
---|
| 212 | __M_writer(u' <script type="text/javascript">\n //\n // Set up autocomplete tagger.\n //\n\n //\n // Default function get text to display on the toggle link.\n //\n var default_get_toggle_link_text_fn = function(tags)\n {\n var text = "";\n var num_tags = obj_length(tags);\n if (num_tags != 0)\n {\n text = num_tags + (num_tags != 1 ? " Tags" : " Tag");\n /*\n // Show first N tags; hide the rest.\n var max_to_show = 1;\n \n // Build tag string.\n var tag_strs = new Array();\n var count = 0;\n for (tag_name in tags)\n {\n tag_value = tags[tag_name];\n tag_strs[tag_strs.length] = build_tag_str(tag_name, tag_value);\n if (++count == max_to_show)\n break;\n }\n tag_str = tag_strs.join(", ");\n \n // Finalize text.\n var num_tags_hiding = num_tags - max_to_show;\n text = "Tags: " + tag_str + \n (num_tags_hiding != 0 ? " and " + num_tags_hiding + " more" : "");\n */\n }\n else\n {\n // No tags.\n text = "Add tags";\n }\n return text;\n };\n \n // Default function to handle a tag click.\n var default_tag_click_fn = function(tag_name, tag_value) { };\n \n ') |
---|
| 213 | # SOURCE LINE 170 |
---|
| 214 | |
---|
| 215 | ## Build dict of tag name, values. |
---|
| 216 | tag_names_and_values = dict() |
---|
| 217 | for tag in item_tags: |
---|
| 218 | tag_name = tag.user_tname |
---|
| 219 | tag_value = "" |
---|
| 220 | if tag.value is not None: |
---|
| 221 | tag_value = tag.user_value |
---|
| 222 | ## Tag names and values may be string or unicode object. |
---|
| 223 | if isinstance( tag_name, str ): |
---|
| 224 | tag_names_and_values[unicode(tag_name, 'utf-8')] = unicode(tag_value, 'utf-8') |
---|
| 225 | else: ## isInstance( tag_name, unicode ): |
---|
| 226 | tag_names_and_values[tag_name] = tag_value |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | # SOURCE LINE 183 |
---|
| 230 | __M_writer(u'\n var options =\n {\n tags : ') |
---|
| 231 | # SOURCE LINE 186 |
---|
| 232 | __M_writer(unicode(h.to_json_string(tag_names_and_values))) |
---|
| 233 | __M_writer(u',\n editable : ') |
---|
| 234 | # SOURCE LINE 187 |
---|
| 235 | __M_writer(unicode(iff( editable, 'true', 'false' ))) |
---|
| 236 | __M_writer(u',\n get_toggle_link_text_fn: ') |
---|
| 237 | # SOURCE LINE 188 |
---|
| 238 | __M_writer(unicode(get_toggle_link_text_fn)) |
---|
| 239 | __M_writer(u',\n tag_click_fn: ') |
---|
| 240 | # SOURCE LINE 189 |
---|
| 241 | __M_writer(unicode(tag_click_fn)) |
---|
| 242 | __M_writer(u',\n') |
---|
| 243 | # SOURCE LINE 191 |
---|
| 244 | __M_writer(u' ajax_autocomplete_tag_url: "') |
---|
| 245 | __M_writer(unicode(h.url_for( controller='/tag', action='tag_autocomplete_data', item_id=tagged_item_id, item_class=tagged_item.__class__.__name__ ))) |
---|
| 246 | __M_writer(u'",\n ajax_add_tag_url: "') |
---|
| 247 | # SOURCE LINE 192 |
---|
| 248 | __M_writer(unicode(h.url_for( controller='/tag', action='add_tag_async', item_id=tagged_item_id, item_class=tagged_item.__class__.__name__, context=elt_context ))) |
---|
| 249 | __M_writer(u'",\n ajax_delete_tag_url: "') |
---|
| 250 | # SOURCE LINE 193 |
---|
| 251 | __M_writer(unicode(h.url_for( controller='/tag', action='remove_tag_async', item_id=tagged_item_id, item_class=tagged_item.__class__.__name__, context=elt_context ))) |
---|
| 252 | __M_writer(u'",\n delete_tag_img: "') |
---|
| 253 | # SOURCE LINE 194 |
---|
| 254 | __M_writer(unicode(h.url_for('/static/images/delete_tag_icon_gray.png'))) |
---|
| 255 | __M_writer(u'",\n delete_tag_img_rollover: "') |
---|
| 256 | # SOURCE LINE 195 |
---|
| 257 | __M_writer(unicode(h.url_for('/static/images/delete_tag_icon_white.png'))) |
---|
| 258 | __M_writer(u'",\n use_toggle_link: ') |
---|
| 259 | # SOURCE LINE 196 |
---|
| 260 | __M_writer(unicode(iff( use_toggle_link, 'true', 'false' ))) |
---|
| 261 | __M_writer(u"\n };\n \n $('#") |
---|
| 262 | # SOURCE LINE 199 |
---|
| 263 | __M_writer(unicode(elt_id)) |
---|
| 264 | __M_writer(u"').autocomplete_tagging(options);\n </script>\n \n") |
---|
| 265 | # SOURCE LINE 203 |
---|
| 266 | __M_writer(u' <style>\n .tag-area {\n display: ') |
---|
| 267 | # SOURCE LINE 205 |
---|
| 268 | __M_writer(unicode(iff( use_toggle_link, "none", "block" ))) |
---|
| 269 | __M_writer(u';\n }\n </style>\n\n <noscript>\n <style>\n .tag-area {\n display: block;\n }\n </style>\n </noscript>\n') |
---|
| 270 | return '' |
---|
| 271 | finally: |
---|
| 272 | context.caller_stack._pop_frame() |
---|
| 273 | |
---|
| 274 | |
---|
| 275 | def render_render_community_tagging_element(context,tagged_item=None,elt_context=None,use_toggle_link=False,tag_click_fn='default_tag_click_fn'): |
---|
| 276 | context.caller_stack._push_frame() |
---|
| 277 | try: |
---|
| 278 | int = context.get('int', UNDEFINED) |
---|
| 279 | self = context.get('self', UNDEFINED) |
---|
| 280 | trans = context.get('trans', UNDEFINED) |
---|
| 281 | __M_writer = context.writer() |
---|
| 282 | # SOURCE LINE 88 |
---|
| 283 | __M_writer(u'\n') |
---|
| 284 | # SOURCE LINE 90 |
---|
| 285 | __M_writer(u' ') |
---|
| 286 | |
---|
| 287 | elt_id = int ( floor ( random()*maxint ) ) |
---|
| 288 | community_tags = trans.app.tag_handler.get_community_tags( trans, item=tagged_item, limit=5 ) |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | # SOURCE LINE 93 |
---|
| 292 | __M_writer(u'\n ') |
---|
| 293 | # SOURCE LINE 94 |
---|
| 294 | __M_writer(unicode(self.render_tagging_element_html(elt_id=elt_id, \ |
---|
| 295 | tags=community_tags, \ |
---|
| 296 | use_toggle_link=use_toggle_link, \ |
---|
| 297 | editable=False, tag_type="community"))) |
---|
| 298 | # SOURCE LINE 97 |
---|
| 299 | __M_writer(u'\n \n') |
---|
| 300 | # SOURCE LINE 100 |
---|
| 301 | __M_writer(u' <script type="text/javascript">\n init_tag_click_function($(\'#') |
---|
| 302 | # SOURCE LINE 101 |
---|
| 303 | __M_writer(unicode(elt_id)) |
---|
| 304 | __M_writer(u"'), ") |
---|
| 305 | __M_writer(unicode(tag_click_fn)) |
---|
| 306 | __M_writer(u');\n </script>\n') |
---|
| 307 | return '' |
---|
| 308 | finally: |
---|
| 309 | context.caller_stack._pop_frame() |
---|
| 310 | |
---|
| 311 | |
---|