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


def _mako_get_namespace(context, name):
    try:
        return context.namespaces[(__name__, name)]
    except KeyError:
        _mako_generate_namespaces(context)
        return context.namespaces[(__name__, name)]
def _mako_generate_namespaces(context):
    # SOURCE LINE 364
    ns = runtime.Namespace('__anon_0x110c0db10', context._clean_inheritance_tokens(), templateuri=u'../tagging_common.mako', callables=None, calling_uri=_template_uri, module=None)
    context.namespaces[(__name__, '__anon_0x110c0db10')] = ns

    # SOURCE LINE 365
    ns = runtime.Namespace('__anon_0x110c0dc10', context._clean_inheritance_tokens(), templateuri=u'history_common.mako', callables=None, calling_uri=_template_uri, module=None)
    context.namespaces[(__name__, '__anon_0x110c0dc10')] = ns

def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        _import_ns = {}
        _mako_get_namespace(context, '__anon_0x110c0db10')._populate(_import_ns, [u'render_individual_tagging_element'])
        _mako_get_namespace(context, '__anon_0x110c0dc10')._populate(_import_ns, [u'render_dataset'])
        datasets = _import_ns.get('datasets', context.get('datasets', UNDEFINED))
        show_deleted = _import_ns.get('show_deleted', context.get('show_deleted', UNDEFINED))
        h = _import_ns.get('h', context.get('h', UNDEFINED))
        reversed = _import_ns.get('reversed', context.get('reversed', UNDEFINED))
        render_dataset = _import_ns.get('render_dataset', context.get('render_dataset', UNDEFINED))
        trans = _import_ns.get('trans', context.get('trans', UNDEFINED))
        dict = _import_ns.get('dict', context.get('dict', UNDEFINED))
        show_hidden = _import_ns.get('show_hidden', context.get('show_hidden', UNDEFINED))
        render_individual_tagging_element = _import_ns.get('render_individual_tagging_element', context.get('render_individual_tagging_element', UNDEFINED))
        n_ = _import_ns.get('n_', context.get('n_', UNDEFINED))
        hda_id = _import_ns.get('hda_id', context.get('hda_id', UNDEFINED))
        bool = _import_ns.get('bool', context.get('bool', UNDEFINED))
        annotation = _import_ns.get('annotation', context.get('annotation', UNDEFINED))
        history = _import_ns.get('history', context.get('history', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 1
        _=n_ 
        
        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['_'] if __M_key in __M_locals_builtin()]))
        __M_writer(u'\n<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n\n<html>\n\n<head>\n<title>')
        # SOURCE LINE 7
        __M_writer(unicode(_('Galaxy History')))
        __M_writer(u'</title>\n\n')
        # SOURCE LINE 10
        if bool( [ data for data in history.active_datasets if data.state in ['running', 'queued', '', None ] ] ):
            # SOURCE LINE 11
            __M_writer(u'<!-- running: do not change this comment, used by TwillTestCase.wait -->\n')
        # SOURCE LINE 13
        __M_writer(u'\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n<meta http-equiv="Pragma" content="no-cache">\n\n')
        # SOURCE LINE 17
        __M_writer(unicode(h.css( "base", "history", "autocomplete_tagging" )))
        __M_writer(u'\n')
        # SOURCE LINE 18
        __M_writer(unicode(h.js( "jquery", "jquery.tipsy", "galaxy.base", "json2", "class", "jquery.jstore", "jquery.autocomplete", "autocomplete_tagging" )))
        __M_writer(u'\n\n<script type="text/javascript">\n\n')
        # SOURCE LINE 22
        TERMINAL_STATES = ["ok", "error", "empty", "deleted", "discarded", "failed_metadata"] 
        
        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin()[__M_key]) for __M_key in ['TERMINAL_STATES'] if __M_key in __M_locals_builtin()]))
        __M_writer(u'\nTERMINAL_STATES = ')
        # SOURCE LINE 23
        __M_writer(unicode( h.to_json_string(TERMINAL_STATES) ))
        __M_writer(u';\n\n$(function() {\n    var historywrapper = $("div.historyItemWrapper");\n    init_history_items(historywrapper);\n    historywrapper.each( function() {\n        // Delete link\n        $(this).find( "div.historyItemButtons > .delete" ).each( function() {\n            var data_id = this.id.split( "-" )[1];\n            $(this).click( function() {\n                $( \'#historyItem-\' + data_id + "> div.historyItemTitleBar" ).addClass( "spinner" );\n                $.ajax({\n                    url: "')
        # SOURCE LINE 35
        __M_writer(unicode(h.url_for( action='delete_async', id='XXX' )))
        __M_writer(u'".replace( \'XXX\', data_id ),\n                    error: function() { alert( "Delete failed" ); },\n                    success: function(msg) {\n                        if (msg === "OK") {\n')
        # SOURCE LINE 39
        if show_deleted:
            # SOURCE LINE 40
            __M_writer(u'                            var to_update = {};\n                            to_update[data_id] = "none";\n                            updater( to_update );\n')
            # SOURCE LINE 43
        else:
            # SOURCE LINE 44
            __M_writer(u'                            $( "#historyItem-" + data_id ).fadeOut( "fast", function() {\n                                $( "#historyItemContainer-" + data_id ).remove();\n                                if ( $( "div.historyItemContainer" ).length < 1 ) {\n                                    $( "#emptyHistoryMessage" ).show();\n                                }\n                            });\n')
        # SOURCE LINE 51
        __M_writer(u'                            $(".tipsy").remove();\n                        } else {\n                            alert( "Delete failed" );\n                        }\n                    }\n                });\n                return false;\n            });\n        });\n        // Undelete link\n        $(this).find( "a.historyItemUndelete" ).each( function() {\n            var data_id = this.id.split( "-" )[1];\n            $(this).click( function() {\n                $( \'#historyItem-\' + data_id + " > div.historyItemTitleBar" ).addClass( "spinner" );\n                $.ajax({\n                    url: "')
        # SOURCE LINE 66
        __M_writer(unicode(h.url_for( controller='dataset', action='undelete_async', id='XXX' )))
        __M_writer(u'".replace( \'XXX\', data_id ),\n                    error: function() { alert( "Undelete failed" ) },\n                    success: function() {\n                        var to_update = {};\n                        to_update[data_id] = "none";\n                        updater( to_update );\n                    }\n                });\n                return false;\n            });\n        });\n\n        // Tag handling.\n        $(this).find( "a.icon-button.tags").each( function() {\n            // Use links parameters but custom URL as ajax URL.\n            $(this).click( function() {\n                // Get tag area, tag element.\n                var history_item = $(this).parents(".historyItem");\n                var tag_area = history_item.find(".tag-area");\n                var tag_elt = history_item.find(".tag-elt");\n\n                // Show or hide tag area; if showing tag area and it\'s empty, fill it.\n                if ( tag_area.is( ":hidden" ) ) {\n                    if (!tag_elt.html()) {\n                        // Need to fill tag element.\n                        var href_parms = $(this).attr("href").split("?")[1];\n                        var ajax_url = "')
        # SOURCE LINE 92
        __M_writer(unicode(h.url_for( controller='tag', action='get_tagging_elt_async' )))
        __M_writer(u'?" + href_parms;\n                        $.ajax({\n                            url: ajax_url,\n                            error: function() { alert( "Tagging failed" ) },\n                            success: function(tag_elt_html) {\n                                tag_elt.html(tag_elt_html);\n                                tag_elt.find(".tooltip").tipsy( { gravity: \'s\' } );\n                                tag_area.slideDown("fast");\n                            }\n                        });\n                    } else {\n                        // Tag element is filled; show.\n                        tag_area.slideDown("fast");\n                    }\n                } else {\n                    // Hide.\n                    tag_area.slideUp("fast");\n                }\n                return false;        \n            });\n        });\n\n        // Annotation handling.\n        $(this).find( "a.icon-button.annotate").each( function() {\n            // Use links parameters but custom URL as ajax URL.\n            $(this).click( function() {\n                // Get tag area, tag element.\n                var history_item = $(this).parents(".historyItem");\n                var annotation_area = history_item.find(".annotation-area");\n                var annotation_elt = history_item.find(".annotation-elt");\n\n                // Show or hide annotation area; if showing annotation area and it\'s empty, fill it.\n                if ( annotation_area.is( ":hidden" ) ) {\n                    if (!annotation_elt.html()) {\n                        // Need to fill annotation element.\n                        var href_parms = $(this).attr("href").split("?")[1];\n                        var ajax_url = "')
        # SOURCE LINE 128
        __M_writer(unicode(h.url_for( controller='dataset', action='get_annotation_async' )))
        __M_writer(u'?" + href_parms;\n                        $.ajax({\n                            url: ajax_url,\n                            error: function() { alert( "Annotations failed" ) },\n                            success: function(annotation) {\n                                if (annotation == "") {\n                                    annotation = "<em>Describe or add notes to dataset</em>";\n                                }\n                                annotation_elt.html(annotation);\n                                annotation_area.find(".tooltip").tipsy( { gravity: \'s\' } );\n                                async_save_text(\n                                    annotation_elt.attr("id"), annotation_elt.attr("id"),\n                                    "')
        # SOURCE LINE 140
        __M_writer(unicode(h.url_for( controller="/dataset", action="annotate_async")))
        __M_writer(u'?" + href_parms,\n                                    "new_annotation", 18, true, 4);\n                                annotation_area.slideDown("fast");\n                            }\n                        });\n                    } else {\n                        // Annotation element is filled; show.\n                        annotation_area.slideDown("fast");\n                    }\n                } else {\n                    // Hide.\n                    annotation_area.slideUp("fast");\n                }\n                return false;        \n            });\n        });\n    });\n    \n    // Trackster links\n    function init_trackster_links() {\n        $("a.trackster").live( "click", function() {\n            var link = $(this),\n                hid = link.attr("id").split("_")[1]; // visualize_{id}\n\n            $.ajax({\n                url: "')
        # SOURCE LINE 165
        __M_writer(unicode(h.url_for( controller='tracks', action='list_tracks' )))
        __M_writer(u'",\n                data: {\'hid\': hid},\n                error: function() { alert( "Visualization error" ); },\n                success: function(html) {\n                    show_modal("Add Track &mdash; Select Dataset(s)", html, {\n                        "New Browser": function() {\n                            hide_modal();\n                        },\n                        "Insert": function() {\n                            hide_modal();\n                        },\n                        "Cancel": function() {\n                            hide_modal();\n                        }\n                    });\n                }\n            });\n        });    \n    }\n    \n    init_trackster_links();\n    \n    // History rename functionality.\n    async_save_text("history-name-container", "history-name", "')
        # SOURCE LINE 188
        __M_writer(unicode(h.url_for( controller="/history", action="rename_async", id=trans.security.encode_id(history.id) )))
        __M_writer(u'", "new_name", 18);\n    \n    // History tagging functionality.\n    var historyTagArea = $(\'#history-tag-area\');\n    $(\'#history-tag\').click( function() {\n        if ( historyTagArea.is( ":hidden" ) ) {\n            historyTagArea.slideDown("fast");\n        } else {\n            historyTagArea.slideUp("fast");\n        }\n        return false;\n    });\n    \n    // History annotation functionality.\n    var historyAnnotationArea = $(\'#history-annotation-area\');\n    $(\'#history-annotate\').click( function() {\n        if ( historyAnnotationArea.is( ":hidden" ) ) {\n            historyAnnotationArea.slideDown("fast");\n        } else {\n            historyAnnotationArea.slideUp("fast");\n        }\n        return false;\n    });\n    async_save_text("history-annotation-container", "history-annotation", "')
        # SOURCE LINE 211
        __M_writer(unicode(h.url_for( controller="/history", action="annotate_async", id=trans.security.encode_id(history.id) )))
        __M_writer(u'", "new_annotation", 18, true, 4);\n    \n    // Updater\n    updater(\n        ')
        # SOURCE LINE 215
        __M_writer(unicode( h.to_json_string( dict([(data.id, data.state) for data in reversed( datasets ) if data.visible and data.state not in TERMINAL_STATES]) ) ))
        __M_writer(u'\n    );\n    \n    // Navigate to a dataset.\n')
        # SOURCE LINE 219
        if hda_id:
            # SOURCE LINE 220
            __M_writer(u'        self.location = "#')
            __M_writer(unicode(hda_id))
            __M_writer(u'";\n')
        # SOURCE LINE 222
        __M_writer(u'});\n\n// Looks for changes in dataset state using an async request. Keeps\n// calling itself (via setTimeout) until all datasets are in a terminal\n// state.\nvar updater = function ( tracked_datasets ) {\n    // Check if there are any items left to track\n    var empty = true;\n    for ( i in tracked_datasets ) {\n        empty = false;\n        break;\n    }\n    if ( !empty ) {\n        setTimeout( function() { updater_callback( tracked_datasets ) }, 4000 );\n    }\n};\nvar updater_callback = function ( tracked_datasets ) {\n    // Build request data\n    var ids = [],\n        states = [],\n        force_history_refresh = false;\n        \n    $.each( tracked_datasets, function ( id, state ) {\n        ids.push( id );\n        states.push( state );\n    });\n    // Make ajax call\n    $.ajax( {\n        type: "POST",\n        url: "')
        # SOURCE LINE 251
        __M_writer(unicode(h.url_for( controller='root', action='history_item_updates' )))
        __M_writer(u'",\n        dataType: "json",\n        data: { ids: ids.join( "," ), states: states.join( "," ) },\n        success : function ( data ) {\n            $.each( data, function( id, val ) {\n                // Replace HTML\n                var container = $("#historyItemContainer-" + id);\n                container.html( val.html );\n                init_history_items( $("div.historyItemWrapper"), "noinit" );\n                // If new state is terminal, stop tracking\n                if (TERMINAL_STATES.indexOf(val.state) !== -1) {\n                    if ( val.force_history_refresh ){\n                        force_history_refresh = true;\n                    }\n                    delete tracked_datasets[ parseInt(id) ];\n                } else {\n                    tracked_datasets[ parseInt(id) ] = val.state;\n                }\n            });\n            if ( force_history_refresh ) {\n                parent.frames.galaxy_history.location.reload();\n            } else {\n                // Keep going (if there are still any items to track)\n                updater( tracked_datasets ); \n            }\n        },\n        error: function() {\n            // Just retry, like the old method, should try to be smarter\n            updater( tracked_datasets );\n        }\n    });\n};\n\n</script>\n\n<style>\n.historyItemBody {\n    display: none;\n}\ndiv.form-row {\n    padding: 5px 5px 5px 0px;\n}\n#top-links {\n    margin-bottom: 15px;\n}\n#history-name-container {\n    display: inline-block;\n    color: gray;\n    font-weight: bold;\n}\n.editable-text {\n    border: solid transparent 1px;\n    padding: 3px;\n    margin: -4px;\n}\n</style>\n\n<noscript>\n<style>\n.historyItemBody {\n    display: block;\n}\n</style>\n</noscript>\n\n</head>\n\n<body class="historyPage">\n<div id="top-links" class="historyLinks">\n    \n    <a title="')
        # SOURCE LINE 321
        __M_writer(unicode(_('refresh')))
        __M_writer(u'" class="icon-button arrow-circle tooltip" href="')
        __M_writer(unicode(h.url_for('history', show_deleted=show_deleted)))
        __M_writer(u'"></a>\n    <a title=\'')
        # SOURCE LINE 322
        __M_writer(unicode(_('collapse all')))
        __M_writer(u'\' class=\'icon-button toggle tooltip\' href=\'#\' style="display: none;"></a>\n    \n')
        # SOURCE LINE 324
        if trans.get_user():
            # SOURCE LINE 325
            __M_writer(u'    <div style="width: 40px; float: right; white-space: nowrap;">\n        <a id="history-tag" title="Edit history tags" class="icon-button tags tooltip" target="galaxy_main" href="')
            # SOURCE LINE 326
            __M_writer(unicode(h.url_for( controller='history', action='tag' )))
            __M_writer(u'"></a>\n        <a id="history-annotate" title="Edit history annotation" class="icon-button annotate tooltip" target="galaxy_main" href="')
            # SOURCE LINE 327
            __M_writer(unicode(h.url_for( controller='history', action='annotate' )))
            __M_writer(u'"></a>\n    </div>\n')
        # SOURCE LINE 330
        __M_writer(u'\n</div>\n\n<div style="clear: both;"></div>\n\n')
        # SOURCE LINE 335
        if show_deleted:
            # SOURCE LINE 336
            __M_writer(u'<div class="historyLinks">\n    <a href="')
            # SOURCE LINE 337
            __M_writer(unicode(h.url_for('history', show_deleted=False)))
            __M_writer(u'">')
            __M_writer(unicode(_('hide deleted')))
            __M_writer(u'</a>\n</div>\n')
        # SOURCE LINE 340
        __M_writer(u'\n')
        # SOURCE LINE 341
        if show_hidden:
            # SOURCE LINE 342
            __M_writer(u'<div class="historyLinks">\n    <a href="')
            # SOURCE LINE 343
            __M_writer(unicode(h.url_for('history', show_hidden=False)))
            __M_writer(u'">')
            __M_writer(unicode(_('hide hidden')))
            __M_writer(u'</a>\n</div>\n')
        # SOURCE LINE 346
        __M_writer(u'\n<div id="history-name-area" class="historyLinks">\n    \n')
        # SOURCE LINE 349
        if trans.get_user():
            # SOURCE LINE 350
            __M_writer(u'    <div id="history-name-container">\n        <div id="history-name" class="tooltip editable-text" title="Click to rename history">')
            # SOURCE LINE 351
            __M_writer(filters.html_escape(unicode(history.get_display_name() )))
            __M_writer(u'</div>\n    </div>\n')
        # SOURCE LINE 354
        __M_writer(u'                               \n</div>\n\n')
        # SOURCE LINE 357
        if history.deleted:
            # SOURCE LINE 358
            __M_writer(u'    <div class="warningmessagesmall">\n        ')
            # SOURCE LINE 359
            __M_writer(unicode(_('You are currently viewing a deleted history!')))
            __M_writer(u'\n    </div>\n    <p></p>\n')
        # SOURCE LINE 363
        __M_writer(u'\n')
        # SOURCE LINE 364
        __M_writer(u'\n')
        # SOURCE LINE 365
        __M_writer(u'\n\n')
        # SOURCE LINE 367
        if trans.get_user() is not None:
            # SOURCE LINE 368
            __M_writer(u'    <div style="margin: 0px 5px 10px 5px">\n')
            # SOURCE LINE 370
            __M_writer(u'        <div id="history-tag-area" style="display: none">\n            <b>Tags:</b>\n            ')
            # SOURCE LINE 372
            __M_writer(unicode(render_individual_tagging_element(user=trans.get_user(), tagged_item=history, elt_context="history.mako", use_toggle_link=False, input_size="20")))
            __M_writer(u'\n        </div>\n    \n')
            # SOURCE LINE 376
            __M_writer(u'        <div id="history-annotation-area" style="display: none">\n   \t        <b>Annotation / Notes:</b>\n   \t        <div id="history-annotation-container">\n\t\t    <div id="history-annotation" class="tooltip editable-text" title="Click to edit annotation">\n')
            # SOURCE LINE 380
            if annotation:
                # SOURCE LINE 381
                __M_writer(u'                    ')
                __M_writer(filters.html_escape(unicode(h.to_unicode( annotation ) )))
                __M_writer(u'\n')
                # SOURCE LINE 382
            else:
                # SOURCE LINE 383
                __M_writer(u'                    <em>Describe or add notes to history</em>\n')
            # SOURCE LINE 385
            __M_writer(u'\t\t    </div>\n            </div>\n        </div>\n        \n    </div>\n')
        # SOURCE LINE 391
        __M_writer(u'\n')
        # SOURCE LINE 392
        if not datasets:
            # SOURCE LINE 393
            __M_writer(u'\n    <div class="infomessagesmall" id="emptyHistoryMessage">\n\n')
            # SOURCE LINE 396
        else:    
            # SOURCE LINE 397
            __M_writer(u'\n')
            # SOURCE LINE 399
            for data in reversed( datasets ):
                # SOURCE LINE 400
                if data.visible or show_hidden:
                    # SOURCE LINE 401
                    __M_writer(u'            <div class="historyItemContainer" id="historyItemContainer-')
                    __M_writer(unicode(data.id))
                    __M_writer(u'">\n                ')
                    # SOURCE LINE 402
                    __M_writer(unicode(render_dataset( data, data.hid, show_deleted_on_refresh = show_deleted, for_editing = True )))
                    __M_writer(u'\n            </div>\n')
            # SOURCE LINE 406
            __M_writer(u'\n    <div class="infomessagesmall" id="emptyHistoryMessage" style="display:none;">\n')
        # SOURCE LINE 409
        __M_writer(u'        ')
        __M_writer(unicode(_("Your history is empty. Click 'Get Data' on the left pane to start")))
        __M_writer(u'\n    </div>\n\n</body>\n</html>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()


