<%namespace name="lib" file="//lib.html" import="traceback"/>
\
% if has_layout:
    <li class="chunk">
% endif
% if error:
    <%self:events_error error="${error}"/>\
% else:
    % if events:
        <%self:events_list events="${events}"/>\
    % else:
        <%self:events_empty job="${job}"/>\
    % endif
% endif
% if has_layout:
    </li>
% endif
\
<%def name="events_list(events)">
    % if has_layout:
        <ol class="list" s:latestoffset="${events[0].offset}" s:earliestoffset="${events[-1].offset}">
    % endif
        % for i, event in enumerate(events):
            <% renderer_namespace = "splEvent-%s" % event.renderer.get('css_class', event.renderer.get('eventtype', '__undefined__')) %>\
            % if has_layout:
                <li class="item default ${renderer_namespace|h}" s:renderernamespace="${renderer_namespace|h}" s:offset="${event.offset}">
            % endif
                <%self:event_item event="${event}" renderer_namespace="${renderer_namespace}"/>\
            % if has_layout:
                </li>
            % endif
        % endfor
    % if has_layout:
        </ol>
    % endif
</%def>\
\
<%def name="event_item(event, renderer_namespace)">
    <%
    try:
        buffer = capture(self.include_file, event.renderer['template'], 
            # search objects
            job=job,
            event=event,
            
            # request context
            request={
                'host_app':host_app, 
                'client_app':client_app, 
                'field_list':field_list, 
                'min_lines':min_lines, 
                'max_lines':max_lines,
                'max_lines_constraint':max_lines_constraint,
                'segmentation':segmentation, 
                'earliest_time':earliest_time, 
                'latest_time':latest_time,
                'post_process':post_process
            },
            
            # UI options
            options={
                'display_row_numbers':display_row_numbers,
                'enable_event_actions':enable_event_actions,
                'enable_field_actions':enable_field_actions,
                'max_lines_constraint': max_lines_constraint,
                'replace_newlines' : replace_newlines,
                'pretty_print' : pretty_print
            }
        )
        
    except:
        header = 'Event Renderer Error: %s ' % event.renderer['template']
        buffer = lib.template.get_def('traceback').render(header=header, parent_element_class_name='tb', row_highlight_class_name='a')
    %>\
    ${buffer}
</%def>\
\
<%def name="events_empty(job)">
    % if has_layout:
        <li class="empty">
    % endif
    <!-- events empty -->
    % if has_layout:
        </li>
    % endif
</%def>\
\
<%def name="events_error(error)">
    % if has_layout:
        <li class="error">
    % endif
        <li>
        <p class="resultStatusMessage">${error | h}</p>
        </li>
    % if has_layout:
        </li>
    % endif
</%def>
