from mako import runtime, filters, cache
UNDEFINED = runtime.UNDEFINED
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 5
_modified_time = 1287725781.101141
_template_filename='templates/tool_form.mako'
_template_uri='tool_form.mako'
_template_cache=cache.Cache(__name__, _modified_time)
_source_encoding=None
_exports = ['do_inputs', 'row_for_param']


def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        add_frame = context.get('add_frame', UNDEFINED)
        errors = context.get('errors', UNDEFINED)
        h = context.get('h', UNDEFINED)
        tool = context.get('tool', UNDEFINED)
        def do_inputs(inputs,tool_state,errors,prefix,other_values=None):
            return render_do_inputs(context.locals_(__M_locals),inputs,tool_state,errors,prefix,other_values)
        len = context.get('len', UNDEFINED)
        util = context.get('util', UNDEFINED)
        unicode = context.get('unicode', UNDEFINED)
        type = context.get('type', UNDEFINED)
        tool_state = context.get('tool_state', UNDEFINED)
        trans = context.get('trans', UNDEFINED)
        AttributeError = context.get('AttributeError', UNDEFINED)
        app = context.get('app', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 1
        __M_writer(u'<!-- -->\n<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n\n')
        # SOURCE LINE 4

        from galaxy.util.expressions import ExpressionContext 
        
        
        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['ExpressionContext'] if __M_key in __M_locals_builtin()]))
        # SOURCE LINE 6
        __M_writer(u'\n\n<html>\n\n<head>\n<title>Galaxy</title>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n')
        # SOURCE LINE 13
        __M_writer(unicode(h.css( "base", "autocomplete_tagging" )))
        __M_writer(u'\n')
        # SOURCE LINE 14
        __M_writer(unicode(h.js( "jquery", "galaxy.base", "jquery.autocomplete" )))
        __M_writer(u'\n<script type="text/javascript">\n$(function() {\n    $(window).bind("refresh_on_change", function() {\n        $(\':file\').each( function() {\n            var file = $(this);\n            var file_value = file.val();\n            if (file_value) {\n                // disable file input, since we don\'t want to upload the file on refresh\n                var file_name = $(this).attr("name");\n                file.attr( { name: \'replaced_file_input_\' + file_name, disabled: true } );\n                // create a new hidden field which stores the filename and has the original name of the file input\n                var new_file_input = $(document.createElement(\'input\'));\n                new_file_input.attr( { "type", "hidden", "value": file_value, "name": file_name } );\n                file.after(new_file_input);\n            }\n        });\n    });\n});\n\n')
        # SOURCE LINE 34
        if not add_frame.debug:
            # SOURCE LINE 35
            __M_writer(u'    if( window.name != "galaxy_main" ) {\n        location.replace( \'')
            # SOURCE LINE 36
            __M_writer(unicode(h.url_for( controller='root', action='index', tool_id=tool.id )))
            __M_writer(u"' );\n    }\n")
        # SOURCE LINE 39
        __M_writer(u'function checkUncheckAll( name, check )\n{\n    if ( check == 0 )\n    {\n        $("input[name=" + name + "][type=\'checkbox\']").attr(\'checked\', false);\n    }\n    else\n    {\n        $("input[name=" + name + "][type=\'checkbox\']").attr(\'checked\', true );\n    }\n}\n\n</script>\n</head>\n\n<body>\n    ')
        # SOURCE LINE 128
        __M_writer(u'\n    \n    ')
        # SOURCE LINE 169
        __M_writer(u'\n    \n')
        # SOURCE LINE 171
        if add_frame.from_noframe:
            # SOURCE LINE 172
            __M_writer(u'        <div class="warningmessage">\n        <strong>Welcome to Galaxy</strong>\n        <hr/>\n        It appears that you found this tool from a link outside of Galaxy.\n        If you\'re not familiar with Galaxy, please consider visiting the\n        <a href="')
            # SOURCE LINE 177
            __M_writer(unicode(h.url_for( controller='root' )))
            __M_writer(u'" target="_top">welcome page</a>.\n        To learn more about what Galaxy is and what it can do for you, please visit\n        the <a href="$add_frame.wiki_url" target="_top">Galaxy wiki</a>.\n        </div>\n        <br/>\n')
        # SOURCE LINE 183
        __M_writer(u'    \n')
        # SOURCE LINE 186
        __M_writer(u'    ')

        try:   
            tool_url = h.url_for(tool.action)
        except AttributeError:
            assert len(tool.action) == 2
            tool_url = tool.action[0] + h.url_for(tool.action[1])
            
        
        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['tool_url'] if __M_key in __M_locals_builtin()]))
        # SOURCE LINE 192
        __M_writer(u'<div class="toolForm" id="')
        __M_writer(unicode(tool.id))
        __M_writer(u'">\n')
        # SOURCE LINE 193
        if tool.has_multiple_pages:
            # SOURCE LINE 194
            __M_writer(u'            <div class="toolFormTitle">')
            __M_writer(unicode(tool.name))
            __M_writer(u' (step ')
            __M_writer(unicode(tool_state.page+1))
            __M_writer(u' of ')
            __M_writer(unicode(tool.npages))
            __M_writer(u')</div>\n')
            # SOURCE LINE 195
        else:
            # SOURCE LINE 196
            __M_writer(u'            <div class="toolFormTitle">')
            __M_writer(unicode(tool.name))
            __M_writer(u'</div>\n')
        # SOURCE LINE 198
        __M_writer(u'        <div class="toolFormBody">\n            <form id="tool_form" name="tool_form" action="')
        # SOURCE LINE 199
        __M_writer(unicode(tool_url))
        __M_writer(u'" enctype="')
        __M_writer(unicode(tool.enctype))
        __M_writer(u'" target="')
        __M_writer(unicode(tool.target))
        __M_writer(u'" method="')
        __M_writer(unicode(tool.method))
        __M_writer(u'">\n                <input type="hidden" name="tool_id" value="')
        # SOURCE LINE 200
        __M_writer(unicode(tool.id))
        __M_writer(u'">\n                <input type="hidden" name="tool_state" value="')
        # SOURCE LINE 201
        __M_writer(unicode(util.object_to_string( tool_state.encode( tool, app ) )))
        __M_writer(u'">\n')
        # SOURCE LINE 202
        if tool.display_by_page[tool_state.page]:
            # SOURCE LINE 203
            __M_writer(u'                    ')
            __M_writer(unicode(trans.fill_template_string( tool.display_by_page[tool_state.page], context=tool.get_param_html_map( trans, tool_state.page, tool_state.inputs ) )))
            __M_writer(u'\n                    <input type="submit" class="primary-button" name="runtool_btn" value="Execute">\n')
            # SOURCE LINE 205
        else:
            # SOURCE LINE 206
            __M_writer(u'                    ')
            __M_writer(unicode(do_inputs( tool.inputs_by_page[ tool_state.page ], tool_state.inputs, errors, "" )))
            __M_writer(u'\n                    <div class="form-row">\n')
            # SOURCE LINE 208
            if tool_state.page == tool.last_page:
                # SOURCE LINE 209
                __M_writer(u'                            <input type="submit" class="primary-button" name="runtool_btn" value="Execute">\n')
                # SOURCE LINE 210
            else:
                # SOURCE LINE 211
                __M_writer(u'                            <input type="submit" class="primary-button" name="runtool_btn" value="Next step">\n')
            # SOURCE LINE 213
            __M_writer(u'                    </div>\n')
        # SOURCE LINE 215
        __M_writer(u'            </form>\n        </div>\n    </div>\n')
        # SOURCE LINE 218
        if tool.help:
            # SOURCE LINE 219
            __M_writer(u'        <div class="toolHelp">\n            <div class="toolHelpBody">\n                ')
            # SOURCE LINE 221

            if tool.has_multiple_pages:
                tool_help = tool.help_by_page[tool_state.page]
            else:
                tool_help = tool.help
            
            # Convert to unicode to display non-ascii characters.
            if type( tool_help ) is not unicode:
                tool_help = unicode( tool_help, 'utf-8')
                            
            
            __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['tool_help'] if __M_key in __M_locals_builtin()]))
            # SOURCE LINE 230
            __M_writer(u'\n                ')
            # SOURCE LINE 231
            __M_writer(unicode(tool_help))
            __M_writer(u'\n            </div>        \n        </div>\n')
        # SOURCE LINE 235
        __M_writer(u'</body>\n\n<script type="text/javascript">\n')
        # SOURCE LINE 239
        __M_writer(u"   $( function() {\n       $( 'li > ul' ).each( function( i ) {\n           if ( $( this )[0].className == 'toolParameterExpandableCollapsable' )\n           {\n               var parent_li = $( this ).parent( 'li' );\n               var sub_ul = $( this ).remove();\n               parent_li.find( 'span' ).wrapInner( '<a/>' ).find( 'a' ).click( function() {\n                 sub_ul.toggle();\n                 $( this )[0].innerHTML = ( sub_ul[0].style.display=='none' ) ? '[+]' : '[-]';\n               });\n               parent_li.append( sub_ul );\n           }\n       });\n       $( 'ul ul' ).each( function(i) {\n           if ( $( this )[0].className == 'toolParameterExpandableCollapsable' && this.attributes.getNamedItem( 'default_state' ).value == 'collapsed' )\n           {\n               $( this ).hide();\n           }\n       });\n   });\n\n")
        # SOURCE LINE 261
        __M_writer(u'$( function() {\n    $("div.checkUncheckAllPlaceholder").each( function( i ) {\n        $( this )[0].innerHTML = \'<a class="action-button" onclick="checkUncheckAll( \\\'\' + this.attributes.getNamedItem( \'checkbox_name\' ).value + \'\\\', 1 );"><span>Select All</span></a> <a class="action-button" onclick="checkUncheckAll( \\\'\' + this.attributes.getNamedItem( \'checkbox_name\' ).value + \'\\\', 0 );"><span>Unselect All</span></a>\';\n    });\n});\n\n</script>\n\n</html>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_do_inputs(context,inputs,tool_state,errors,prefix,other_values=None):
    context.caller_stack._push_frame()
    try:
        def row_for_param(prefix,param,parent_state,parent_errors,other_values):
            return render_row_for_param(context,prefix,param,parent_state,parent_errors,other_values)
        h = context.get('h', UNDEFINED)
        def do_inputs(inputs,tool_state,errors,prefix,other_values=None):
            return render_do_inputs(context,inputs,tool_state,errors,prefix,other_values)
        len = context.get('len', UNDEFINED)
        range = context.get('range', UNDEFINED)
        dict = context.get('dict', UNDEFINED)
        str = context.get('str', UNDEFINED)
        enumerate = context.get('enumerate', UNDEFINED)
        trans = context.get('trans', UNDEFINED)
        ExpressionContext = context.get('ExpressionContext', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 55
        __M_writer(u'\n      ')
        # SOURCE LINE 56
        other_values = ExpressionContext( tool_state, other_values ) 
        
        __M_writer(u'\n')
        # SOURCE LINE 57
        for input_index, input in enumerate( inputs.itervalues() ):
            # SOURCE LINE 58
            if input.type == "repeat":
                # SOURCE LINE 59
                __M_writer(u'              <div class="repeat-group">\n                  <div class="form-title-row"><b>')
                # SOURCE LINE 60
                __M_writer(unicode(input.title_plural))
                __M_writer(u'</b></div>\n                  ')
                # SOURCE LINE 61
                repeat_state = tool_state[input.name] 
                
                __M_writer(u'\n')
                # SOURCE LINE 62
                for i in range( len( repeat_state ) ):
                    # SOURCE LINE 63
                    __M_writer(u'                    <div class="repeat-group-item">\n                    ')
                    # SOURCE LINE 64

                    if input.name in errors:
                        rep_errors = errors[input.name][i]
                    else:
                        rep_errors = dict()
                    index = repeat_state[i]['__index__']
                    
                    
                    # SOURCE LINE 70
                    __M_writer(u'\n                    <div class="form-title-row"><b>')
                    # SOURCE LINE 71
                    __M_writer(unicode(input.title))
                    __M_writer(u' ')
                    __M_writer(unicode(i + 1))
                    __M_writer(u'</b></div>\n                    ')
                    # SOURCE LINE 72
                    __M_writer(unicode(do_inputs( input.inputs, repeat_state[i], rep_errors, prefix + input.name + "_" + str(index) + "|", other_values )))
                    __M_writer(u'\n                    <div class="form-row"><input type="submit" name="')
                    # SOURCE LINE 73
                    __M_writer(unicode(prefix))
                    __M_writer(unicode(input.name))
                    __M_writer(u'_')
                    __M_writer(unicode(index))
                    __M_writer(u'_remove" value="Remove ')
                    __M_writer(unicode(input.title))
                    __M_writer(u' ')
                    __M_writer(unicode(i+1))
                    __M_writer(u'"></div>\n                    </div>\n')
                    # SOURCE LINE 75
                    if rep_errors.has_key( '__index__' ):
                        # SOURCE LINE 76
                        __M_writer(u'                        <div><img style="vertical-align: middle;" src="')
                        __M_writer(unicode(h.url_for('/static/style/error_small.png')))
                        __M_writer(u'">&nbsp;<span style="vertical-align: middle;">')
                        __M_writer(unicode(rep_errors['__index__']))
                        __M_writer(u'</span></div>\n')
                # SOURCE LINE 79
                __M_writer(u'                  <div class="form-row"><input type="submit" name="')
                __M_writer(unicode(prefix))
                __M_writer(unicode(input.name))
                __M_writer(u'_add" value="Add new ')
                __M_writer(unicode(input.title))
                __M_writer(u'"></div>\n              </div>\n')
                # SOURCE LINE 81
            elif input.type == "conditional":
                # SOURCE LINE 82
                __M_writer(u'                ')

                group_state = tool_state[input.name]
                group_errors = errors.get( input.name, {} )
                current_case = group_state['__current_case__']
                group_prefix = prefix + input.name + "|"
                
                
                # SOURCE LINE 87
                __M_writer(u'\n')
                # SOURCE LINE 88
                if input.value_ref_in_group:
                    # SOURCE LINE 89
                    __M_writer(u'                    ')
                    __M_writer(unicode(row_for_param( group_prefix, input.test_param, group_state, group_errors, other_values )))
                    __M_writer(u'\n')
                # SOURCE LINE 91
                __M_writer(u'                ')
                __M_writer(unicode(do_inputs( input.cases[current_case].inputs, group_state, group_errors, group_prefix, other_values )))
                __M_writer(u'\n')
                # SOURCE LINE 92
            elif input.type == "upload_dataset":
                # SOURCE LINE 93
                if input.get_datatype( trans, other_values ).composite_type is None: #have non-composite upload appear as before
                    # SOURCE LINE 94
                    __M_writer(u'                    ')

                    if input.name in errors:
                        rep_errors = errors[input.name][0]
                    else:
                        rep_errors = dict()
                    
                    
                    # SOURCE LINE 99
                    __M_writer(u'\n                  ')
                    # SOURCE LINE 100
                    __M_writer(unicode(do_inputs( input.inputs, tool_state[input.name][0], rep_errors, prefix + input.name + "_" + str( 0 ) + "|", other_values )))
                    __M_writer(u'\n')
                    # SOURCE LINE 101
                else:
                    # SOURCE LINE 102
                    __M_writer(u'                    <div class="repeat-group">\n                        <div class="form-title-row"><b>')
                    # SOURCE LINE 103
                    __M_writer(unicode(input.group_title( other_values )))
                    __M_writer(u'</b></div>\n                        ')
                    # SOURCE LINE 104
 
                    repeat_state = tool_state[input.name] 
                    
                    
                    # SOURCE LINE 106
                    __M_writer(u'\n')
                    # SOURCE LINE 107
                    for i in range( len( repeat_state ) ):
                        # SOURCE LINE 108
                        __M_writer(u'                          <div class="repeat-group-item">\n                          ')
                        # SOURCE LINE 109

                        if input.name in errors:
                            rep_errors = errors[input.name][i]
                        else:
                            rep_errors = dict()
                        index = repeat_state[i]['__index__']
                        
                        
                        # SOURCE LINE 115
                        __M_writer(u'\n                          <div class="form-title-row"><b>File Contents for ')
                        # SOURCE LINE 116
                        __M_writer(unicode(input.title_by_index( trans, i, other_values )))
                        __M_writer(u'</b></div>\n                          ')
                        # SOURCE LINE 117
                        __M_writer(unicode(do_inputs( input.inputs, repeat_state[i], rep_errors, prefix + input.name + "_" + str(index) + "|", other_values )))
                        __M_writer(u'\n')
                        # SOURCE LINE 119
                        __M_writer(u'                          </div>\n')
                    # SOURCE LINE 122
                    __M_writer(u'                    </div>\n')
                # SOURCE LINE 124
            else:
                # SOURCE LINE 125
                __M_writer(u'                ')
                __M_writer(unicode(row_for_param( prefix, input, tool_state, errors, other_values )))
                __M_writer(u'\n')
        # SOURCE LINE 128
        __M_writer(u'    ')
        return ''
    finally:
        context.caller_stack._pop_frame()


def render_row_for_param(context,prefix,param,parent_state,parent_errors,other_values):
    context.caller_stack._push_frame()
    try:
        h = context.get('h', UNDEFINED)
        trans = context.get('trans', UNDEFINED)
        type = context.get('type', UNDEFINED)
        unicode = context.get('unicode', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 130
        __M_writer(u'\n        ')
        # SOURCE LINE 131

        if parent_errors.has_key( param.name ):
            cls = "form-row form-row-error"
        else:
            cls = "form-row"
        
        
        # SOURCE LINE 136
        __M_writer(u'\n        <div class="')
        # SOURCE LINE 137
        __M_writer(unicode(cls))
        __M_writer(u'">\n            ')
        # SOURCE LINE 138
        label = param.get_label() 
        
        __M_writer(u'\n')
        # SOURCE LINE 139
        if label:
            # SOURCE LINE 140
            __M_writer(u'                <label>\n                    ')
            # SOURCE LINE 141
            __M_writer(unicode(label))
            __M_writer(u':\n                </label>\n')
        # SOURCE LINE 144
        __M_writer(u'            ')

        field = param.get_html_field( trans, parent_state[ param.name ], other_values )
        field.refresh_on_change = param.refresh_on_change
        
        # Field may contain characters submitted by user and these characters may be unicode; handle non-ascii characters gracefully.
        field_html = field.get_html( prefix )
        if type( field_html ) is not unicode:
            field_html = unicode( field_html, 'utf-8' )
                    
        
        # SOURCE LINE 152
        __M_writer(u'\n            <div class="form-row-input">')
        # SOURCE LINE 153
        __M_writer(unicode(field_html))
        __M_writer(u'</div>\n')
        # SOURCE LINE 154
        if parent_errors.has_key( param.name ):
            # SOURCE LINE 155
            __M_writer(u'            <div class="form-row-error-message">\n                <div><img style="vertical-align: middle;" src="')
            # SOURCE LINE 156
            __M_writer(unicode(h.url_for('/static/style/error_small.png')))
            __M_writer(u'">&nbsp;<span style="vertical-align: middle;">')
            __M_writer(unicode(parent_errors[param.name]))
            __M_writer(u'</span></div>\n            </div>\n')
        # SOURCE LINE 159
        __M_writer(u'            \n')
        # SOURCE LINE 160
        if param.help:
            # SOURCE LINE 161
            __M_writer(u'            <div class="toolParamHelp" style="clear: both;">\n                ')
            # SOURCE LINE 162
            __M_writer(unicode(param.help))
            __M_writer(u'\n            </div>\n')
        # SOURCE LINE 165
        __M_writer(u'    \n            <div style="clear: both"></div>\n                    \n        </div>\n    ')
        return ''
    finally:
        context.caller_stack._pop_frame()


