from mako import runtime, filters, cache
UNDEFINED = runtime.UNDEFINED
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 5
_modified_time = 1287725327.091922
_template_filename='templates/root/tool_menu.mako'
_template_uri='/root/tool_menu.mako'
_template_cache=cache.Cache(__name__, _modified_time)
_source_encoding=None
_exports = ['render_label', 'render_tool', 'render_workflow']


def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        _ = context.get('_', UNDEFINED)
        h = context.get('h', UNDEFINED)
        def render_label(label):
            return render_render_label(context.locals_(__M_locals),label)
        t = context.get('t', UNDEFINED)
        str = context.get('str', UNDEFINED)
        recent_tools = context.get('recent_tools', UNDEFINED)
        toolbox = context.get('toolbox', UNDEFINED)
        trans = context.get('trans', UNDEFINED)
        def render_tool(tool,section):
            return render_render_tool(context.locals_(__M_locals),tool,section)
        def render_workflow(key,workflow,section):
            return render_render_workflow(context.locals_(__M_locals),key,workflow,section)
        __M_writer = context.writer()
        # SOURCE LINE 25
        __M_writer(u'\n\n')
        # SOURCE LINE 37
        __M_writer(u'\n\n')
        # SOURCE LINE 44
        __M_writer(u'\n\n<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html>\n    <head>\n        <title>')
        # SOURCE LINE 49
        __M_writer(unicode(_('Galaxy Tools')))
        __M_writer(u'</title>\n        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n        <link href="')
        # SOURCE LINE 51
        __M_writer(unicode(h.url_for('/static/style/base.css')))
        __M_writer(u'" rel="stylesheet" type="text/css" />\n        <link href="')
        # SOURCE LINE 52
        __M_writer(unicode(h.url_for('/static/style/tool_menu.css')))
        __M_writer(u'" rel="stylesheet" type="text/css" />\n\n')
        # SOURCE LINE 55
        __M_writer(u'        ')
        __M_writer(unicode(h.js( "jquery", "galaxy.base", "json2" )))
        __M_writer(u'\n\n        <script type="text/javascript">\n            // Set up GalaxyAsync object.\n            var galaxy_async = new GalaxyAsync(')
        # SOURCE LINE 59
        __M_writer(unicode(str(trans.app.config.log_actions).lower()))
        __M_writer(u');\n            galaxy_async.set_func_url(galaxy_async.log_user_action, "')
        # SOURCE LINE 60
        __M_writer(unicode(h.url_for( controller='user', action='log_user_action_async' )))
        __M_writer(u'");\n        \n            $(document).ready(function() { \n                // Init showing/hiding of tool sections.\n                $( "div.toolSectionBody" ).hide();\n                $( "div.toolSectionTitle > span" ).wrap( "<a href=\'#\'></a>" )\n                var last_expanded = null;\n                $( "div.toolSectionTitle" ).each( function() { \n                   var body = $(this).next( "div.toolSectionBody" );\n                   $(this).click( function() {\n                       if ( body.is( ":hidden" ) ) {\n                            if ( last_expanded ) {\n                                last_expanded.slideUp( "fast" );\n                            }\n                            last_expanded = body;\n                            body.slideDown( "fast" );\n                       }\n                       else {\n                           body.slideUp( "fast" );\n                           last_expanded = null;\n                       }\n                       return false;\n                   });\n                });\n                \n                // Log clicks on tools.\n                $("div.toolTitle > a").click( function() \n                {\n                    var tool_title = $(this).attr(\'id\').split("-")[1];\n                    var section_title = $(this).parents("div.toolSectionWrapper").find("div.toolSectionTitle").text().trim();\n                    var search_active = $(this).parents("div.toolTitle").hasClass("search_match");\n                    \n                    // Log action.\n                    galaxy_async.log_user_action("tool_menu_click." + tool_title, section_title, \n                                                    JSON.stringify({"search_active" : search_active}));\n                });\n                \n                $( "a[minsizehint]" ).click( function() {\n                    if ( parent.handle_minwidth_hint ) {\n                        parent.handle_minwidth_hint( $(this).attr( "minsizehint" ) );\n                    }\n                });\n                \n                // Init searching.\n                $("#tool-search-query").click( function (){\n                    $(this).focus();\n                    $(this).select();\n                })\n                .keyup( function () {\n                    // Remove italics.\n                    $(this).css("font-style", "normal");\n                    \n                    // Don\'t update if same value as last time\n                    if ( this.value.length < 3 ) {\n                        reset_tool_search(false);\n                    } else if ( this.value != this.lastValue ) {\n                        // Add class to denote that searching is active.\n                        $(this).addClass("search_active");\n                        // input.addClass(config.loadingClass);\n                        // Add \'*\' to facilitate partial matching.\n                        var q = this.value + \'*\';\n                        // Stop previous ajax-request\n                        if (this.timer) {\n                            clearTimeout(this.timer);\n                        }\n                        // Start a new ajax-request in X ms\n                        $("#search-spinner").show();\n                        this.timer = setTimeout(function () {\n                            $.get("')
        # SOURCE LINE 128
        __M_writer(unicode(h.url_for( controller='root', action='tool_search' )))
        __M_writer(u'", { query: q }, function (data) {\n                                // input.removeClass(config.loadingClass);\n                                // Show live-search if results and search-term aren\'t empty\n                                $("#search-no-results").hide();\n                                // Hide all tool sections.\n                                $(".toolSectionWrapper").hide();\n                                // This hides all tools but not workflows link (which is in a .toolTitle div).\n                                $(".toolSectionWrapper").find(".toolTitle").hide();\n                                if ( data.length != 0 ) {\n                                    // Map tool ids to element ids and join them.\n                                    var s = $.map( data, function( n, i ) { return "#link-" + n; } ).join( ", " );\n                                    \n                                    // First pass to show matching tools and their parents.\n                                    $(s).each( function() {\n                                        // Add class to denote match.\n                                        $(this).parent().addClass("search_match");\n                                        if ($(this).parents("#recently_used_wrapper").length == 0)\n                                            // Default behavior.\n                                            $(this).parent().show().parent().parent().show().parent().show();\n                                        else if ($(this).parents(".user_pref_visible").length != 0)\n                                            // RU menu is visible, so filter it as normal.\n                                            $(this).parent().show().parent().parent().show().parent().show();\n                                        else \n                                        {\n                                            // RU menu is not visible, so set up classes and visibility so that if menu shown matching is \n                                            // aleady in place.\n                                            $(this).parent().show();\n                                        }\n                                    });\n                                    \n                                    // Hide labels that have no visible children.\n                                    $(".toolPanelLabel").each( function() {\n                                       var this_label = $(this);                                   \n                                       var next = this_label.next();\n                                       var no_visible_tools = true;\n                                       // Look through tools following label and, if none are visible, hide label.\n                                       while (next.length != 0 && next.hasClass("toolTitle"))\n                                       {\n                                           if (next.is(":visible"))\n                                           {\n                                               no_visible_tools = false;\n                                               break;\n                                           }\n                                           else\n                                               next = next.next();\n                                        }\n                                        if (no_visible_tools)\n                                            this_label.hide();\n                                    });\n                                } else {\n                                    $("#search-no-results").show();\n                                }\n                                $("#search-spinner").hide();\n                            }, "json" );\n                        }, 200 );\n                    }\n                    this.lastValue = this.value;\n                });                \n            });            \n\n            // Update recently used tools menu. Function inserts a new item and removes the last item.\n            function update_recently_used()\n            {\n                $.ajax({\n                    url: "')
        # SOURCE LINE 192
        __M_writer(unicode(h.url_for( controller='/user', action='get_most_recently_used_tool_async' )))
        __M_writer(u'",\n                    dataType: \'json\',\n                    error: function() { \n                        // console.log( "Failed to update recently used list." );\n                    },\n                    success: function(new_tool_info) {\n                        var recently_used_elts = $("#recently_used").find(".toolTitle");\n                        var first_elt = $(recently_used_elts.first());\n                        var found_in_list = false;\n            \n                        // Look for new tool in current list. If found, rearrange list to move tool to top.\n                        recently_used_elts.each( function(index) {\n                            var anchor = $(this).find("a");\n                            var tool_id = anchor.attr("id").split("-")[1];\n                            if (tool_id == new_tool_info.id)\n                            {\n                                found_in_list = true;\n                    \n                                // If tool is first, do nothing.\n                                if (index == 0)\n                                    return;\n                                else \n                                {\n                                    // Tool not first; reorder.\n                                    $(this).remove();\n                                    first_elt.before($(this));\n                                }\n                            }\n                        });\n            \n                        // If tool not in list, create new element, remove last element, and put new element first in list.\n                        if (!found_in_list)\n                        {\n                            new_tool_elt = $("<div class=\'toolTitle\'> ')
        # SOURCE LINE 226
        __M_writer(u'                                                <a id=\'link-" + new_tool_info.id + "\' href=\'" + new_tool_info.link + "\' target=\'" + \n                                                new_tool_info.target + "\' minsizehint=\'" + new_tool_info.minsizehint + "\'>" +\n                                                new_tool_info.name + "</a> " + new_tool_info.description + " ')
        # SOURCE LINE 229
        __M_writer(u'                                              </div>");\n                            recently_used_elts.last().remove();\n                            recently_used_elts.first().before(new_tool_elt);                            \n                        }\n                    }\n                });                \n            }\n        </script>\n    </head>\n\n    <body class="toolMenuPage">\n        <div class="toolMenu">\n            \n')
        # SOURCE LINE 243
        __M_writer(u'                ')

        show_tool_search = False
        if trans.user:
            show_tool_search = trans.user.preferences.get( "show_tool_search", "False" )
        
        if show_tool_search == "True":
            display = "block"
        else:
            display = "none"
                        
        
        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['display','show_tool_search'] if __M_key in __M_locals_builtin()]))
        # SOURCE LINE 252
        __M_writer(u'\n                <div id="tool-search" style="padding-bottom: 5px; position: relative; display: ')
        # SOURCE LINE 253
        __M_writer(unicode(display))
        __M_writer(u'; width: 100%">\n                    <input type="text" name="query" value="search tools" id="tool-search-query" style="width: 100%; font-style:italic; font-size: inherit"/>\n                    <img src="')
        # SOURCE LINE 255
        __M_writer(unicode(h.url_for('/static/images/loading_small_white_bg.gif')))
        __M_writer(u'" id="search-spinner" style="display: none; position: absolute; right: 0; top: 5px;"/>\n                </div>\n                \n')
        # SOURCE LINE 259
        if trans.user:
            # SOURCE LINE 260
            __M_writer(u'                    ')

            if trans.user.preferences.get( 'show_recently_used_menu', 'False' ) == 'True':
                display = "block"
                pref_class = "user_pref_visible"
            else:
                display = "none"
                pref_class = "user_pref_hidden"
            
            
            __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['pref_class','display'] if __M_key in __M_locals_builtin()]))
            # SOURCE LINE 267
            __M_writer(u'\n                    <div class="toolSectionWrapper ')
            # SOURCE LINE 268
            __M_writer(unicode(pref_class))
            __M_writer(u'" id="recently_used_wrapper" \n                            style="display: ')
            # SOURCE LINE 269
            __M_writer(unicode(display))
            __M_writer(u'; padding-bottom: 5px">\n                        <div class="toolSectionTitle">\n                            <span>Recently Used</span>\n                        </div>\n                        <div id="recently_used" class="toolSectionBody">\n                            <div class="toolSectionBg">\n')
            # SOURCE LINE 275
            for tool in recent_tools:
                # SOURCE LINE 276
                __M_writer(u'                                    ')
                __M_writer(unicode(render_tool( tool, True )))
                __M_writer(u'\n')
            # SOURCE LINE 278
            __M_writer(u'                            </div>\n                        </div>\n                        <div class="toolSectionPad"></div>\n                    </div>\n')
        # SOURCE LINE 283
        __M_writer(u'                \n')
        # SOURCE LINE 285
        for key, val in toolbox.tool_panel.items():
            # SOURCE LINE 286
            __M_writer(u'                    <div class="toolSectionWrapper">\n')
            # SOURCE LINE 287
            if key.startswith( 'tool' ):
                # SOURCE LINE 288
                __M_writer(u'                        ')
                __M_writer(unicode(render_tool( val, False )))
                __M_writer(u'\n')
                # SOURCE LINE 289
            elif key.startswith( 'workflow' ):
                # SOURCE LINE 290
                __M_writer(u'                        ')
                __M_writer(unicode(render_workflow( key, val, False )))
                __M_writer(u'\n')
                # SOURCE LINE 291
            elif key.startswith( 'section' ):
                # SOURCE LINE 292
                __M_writer(u'                        ')
                section = val 
                
                __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['section'] if __M_key in __M_locals_builtin()]))
                __M_writer(u'\n                        <div class="toolSectionTitle" id="title_')
                # SOURCE LINE 293
                __M_writer(unicode(section.id))
                __M_writer(u'">\n                            <span>')
                # SOURCE LINE 294
                __M_writer(unicode(section.name))
                __M_writer(u'</span>\n                        </div>\n                        <div id="')
                # SOURCE LINE 296
                __M_writer(unicode(section.id))
                __M_writer(u'" class="toolSectionBody">\n                            <div class="toolSectionBg">\n')
                # SOURCE LINE 298
                for section_key, section_val in section.elems.items():
                    # SOURCE LINE 299
                    if section_key.startswith( 'tool' ):
                        # SOURCE LINE 300
                        __M_writer(u'                                        ')
                        __M_writer(unicode(render_tool( section_val, True )))
                        __M_writer(u'\n')
                        # SOURCE LINE 301
                    elif section_key.startswith( 'workflow' ):
                        # SOURCE LINE 302
                        __M_writer(u'                                        ')
                        __M_writer(unicode(render_workflow( section_key, section_val, True )))
                        __M_writer(u'\n')
                        # SOURCE LINE 303
                    elif section_key.startswith( 'label' ):
                        # SOURCE LINE 304
                        __M_writer(u'                                        ')
                        __M_writer(unicode(render_label( section_val )))
                        __M_writer(u'\n')
                # SOURCE LINE 307
                __M_writer(u'                            </div>\n                        </div>\n')
                # SOURCE LINE 309
            elif key.startswith( 'label' ):
                # SOURCE LINE 310
                __M_writer(u'                        ')
                __M_writer(unicode(render_label( val )))
                __M_writer(u'\n')
            # SOURCE LINE 312
            __M_writer(u'                    <div class="toolSectionPad"></div>\n                    </div>\n')
        # SOURCE LINE 315
        __M_writer(u'                \n')
        # SOURCE LINE 317
        __M_writer(u'                <div id="search-no-results" style="display: none; padding-top: 5px">\n                    <em><strong>Search did not match any tools.</strong></em>\n                </div>\n                \n')
        # SOURCE LINE 324
        __M_writer(u'                \n')
        # SOURCE LINE 325
        if t.user:
            # SOURCE LINE 326
            __M_writer(u'                    <div class="toolSectionPad"></div>\n                    <div class="toolSectionPad"></div>\n                    <div class="toolSectionTitle" id="title_XXinternalXXworkflow">\n                      <span>Workflows</span>\n                    </div>\n                    <div id="XXinternalXXworkflow" class="toolSectionBody">\n                        <div class="toolSectionBg">\n')
            # SOURCE LINE 333
            if t.user.stored_workflow_menu_entries:
                # SOURCE LINE 334
                for m in t.user.stored_workflow_menu_entries:
                    # SOURCE LINE 335
                    __M_writer(u'                                    <div class="toolTitle">\n                                        <a href="')
                    # SOURCE LINE 336
                    __M_writer(unicode(h.url_for( controller='workflow', action='run', id=trans.security.encode_id(m.stored_workflow_id) )))
                    __M_writer(u'" target="galaxy_main">')
                    __M_writer(unicode(m.stored_workflow.name))
                    __M_writer(u'</a>\n                                    </div>\n')
            # SOURCE LINE 340
            __M_writer(u'                            <div class="toolTitle">\n                                <a href="')
            # SOURCE LINE 341
            __M_writer(unicode(h.url_for( controller='workflow', action='list_for_run')))
            __M_writer(u'" target="galaxy_main">All workflows</a>\n                            </div>\n                        </div>\n                    </div>\n')
        # SOURCE LINE 346
        __M_writer(u'                \n            </div>\n        </div>\n    </body>\n</html>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_render_label(context,label):
    context.caller_stack._push_frame()
    try:
        __M_writer = context.writer()
        # SOURCE LINE 40
        __M_writer(u'\n    <div class="toolPanelLabel" id="title_')
        # SOURCE LINE 41
        __M_writer(unicode(label.id))
        __M_writer(u'">\n        <span>')
        # SOURCE LINE 42
        __M_writer(unicode(label.text))
        __M_writer(u'</span>\n    </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_render_tool(context,tool,section):
    context.caller_stack._push_frame()
    try:
        h = context.get('h', UNDEFINED)
        t = context.get('t', UNDEFINED)
        _ = context.get('_', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 2
        __M_writer(u'\n')
        # SOURCE LINE 3
        if not tool.hidden:
            # SOURCE LINE 4
            if section:
                # SOURCE LINE 5
                __M_writer(u'            <div class="toolTitle">\n')
                # SOURCE LINE 6
            else:
                # SOURCE LINE 7
                __M_writer(u'            <div class="toolTitleNoSection">\n')
            # SOURCE LINE 9
            __M_writer(u'            ')

            if tool.input_required:
                link = h.url_for( controller='tool_runner', tool_id=tool.id )
            else:
                link = h.url_for( tool.action, ** tool.get_static_param_values( t ) )
                        
            
            # SOURCE LINE 14
            __M_writer(u'\n')
            # SOURCE LINE 18
            if tool.name:
                # SOURCE LINE 19
                __M_writer(u'                <a id="link-')
                __M_writer(unicode(tool.id))
                __M_writer(u'" href="')
                __M_writer(unicode(link))
                __M_writer(u'" target=')
                __M_writer(unicode(tool.target))
                __M_writer(u' minsizehint="')
                __M_writer(unicode(tool.uihints.get( 'minwidth', -1 )))
                __M_writer(u'">')
                __M_writer(unicode(_(tool.name)))
                __M_writer(u'</a> ')
                __M_writer(unicode(tool.description))
                __M_writer(u' \n')
                # SOURCE LINE 20
            else:
                # SOURCE LINE 21
                __M_writer(u'                <a id="link-')
                __M_writer(unicode(tool.id))
                __M_writer(u'" href="')
                __M_writer(unicode(link))
                __M_writer(u'" target=')
                __M_writer(unicode(tool.target))
                __M_writer(u' minsizehint="')
                __M_writer(unicode(tool.uihints.get( 'minwidth', -1 )))
                __M_writer(u'">')
                __M_writer(unicode(tool.description))
                __M_writer(u'</a>\n')
            # SOURCE LINE 23
            __M_writer(u'        </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_render_workflow(context,key,workflow,section):
    context.caller_stack._push_frame()
    try:
        h = context.get('h', UNDEFINED)
        _ = context.get('_', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 28
        __M_writer(u'\n')
        # SOURCE LINE 29
        if section:
            # SOURCE LINE 30
            __M_writer(u'        <div class="toolTitle">\n')
            # SOURCE LINE 31
        else:
            # SOURCE LINE 32
            __M_writer(u'        <div class="toolTitleNoSection">\n')
        # SOURCE LINE 34
        __M_writer(u'        ')
        encoded_id = key.lstrip( 'workflow_' ) 
        
        __M_writer(u'\n        <a id="link-')
        # SOURCE LINE 35
        __M_writer(unicode(workflow.id))
        __M_writer(u'" href="')
        __M_writer(unicode( h.url_for( controller='workflow', action='run', id=encoded_id, check_user=False )))
        __M_writer(u'" target="_parent"}">')
        __M_writer(unicode(_(workflow.name)))
        __M_writer(u'</a>\n    </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


