<%def name="select_field(field)">
    % if simplelist.search_field==field:
        selected \
    % endif
</%def>
<%def name="set_css_arrow(simplelist, field)">
    % if simplelist.order_field==field:
        <i class="fa fa-arrow-${simplelist.order_class[simplelist.order]}" aria-hidden="true"></i>
    % endif
</%def>
% if simplelist.yes_search:
<div class="form">
<form method="get" action="${simplelist.url}">
    ${lang('common','search', 'Search')}: <input type="text" name="search_text" value="${simplelist.search_text|n}"> 
    <select name="search_field">
    % for field in simplelist.search_fields:
        <option value="${simplelist.model.fields[field].name}" ${select_field(field)}>${simplelist.model.fields[field].label}</option>
    % endfor 
    </select>
    <input type="submit" value="${lang('common', 'search', 'Search')}" />
</form>
</div>
% endif
% if not simplelist.table_div:

<table class="table_list" id="${simplelist.model.name}_table">
    <tr class="title_list">
        % for field in simplelist.fields_showed:
            <td class="${simplelist.model.fields[field].name}_td"><a href="${add_get_parameters(simplelist.url, order_field=field, begin_page=simplelist.begin_page, order=simplelist.change_order[field], search_text=simplelist.search_text, search_field=simplelist.search_field)}" class="">${set_css_arrow(simplelist, field)}${simplelist.model.fields[field].label}</a></td>
        % endfor 
        % for extra_field in simplelist.arr_extra_fields:
            <td class="options_td">${ extra_field }</td>
        % endfor
    </tr>
    <%
    pos=0
    %>
    % for row in list:
    <%
        if not 'pos' in row:
            row['pos']=pos
    %>
    <tr class="row_list">
        % for field in simplelist.fields_showed:
            % if simplelist.model.fields[field].escape==True:
                %if type(simplelist.model.fields[field]).__name__!='ForeignKeyField':
                <td class="${simplelist.model.fields[field].name}_td">${simplelist.model.fields[field].show_formatted(row[field])}</td>
                % else:
                <td class="${simplelist.model.fields[field].name}_td">${simplelist.model.fields[field].show_formatted(row[field])}${str(simplelist.model.fields[field].related_model.fields[simplelist.model.fields[field].named_field].show_formatted(row[field]))}</td>
                % endif
            % else:
                %if type(simplelist.model.fields[field]).__name__!='ForeignKeyField':
                <td class="${simplelist.model.fields[field].name}_td">${str(simplelist.model.fields[field].show_formatted(row[field]))|n}</td>
                % else:
                <td class="${simplelist.model.fields[field].name}_td">${str(simplelist.model.fields[field].related_model.fields[simplelist.model.fields[field].named_field].show_formatted(row[field]))|n}</td>
                % endif
            % endif
        % endfor
        
        % for extra_field_func in simplelist.arr_extra_options:
            <td class="options_td">${ simplelist.set_options(extra_field_func, row)|n }</td>
        % endfor 
    </tr>
    <%
    pos+=1
    %>
    % endfor 
</table>

% else:

<%

size_td=round(100/(len(simplelist.fields_showed)+len(simplelist.arr_extra_options)))

%>

<div class="table_list" id="${simplelist.model.name}_table">
    <div class="${simplelist.model.name}_tr tr_list_div">
        % for field in simplelist.fields_showed:
            <div class="${simplelist.model.fields[field].name}_td fields_span_title" style="width: ${size_td}%;"><a href="${add_get_parameters(simplelist.url, order_field=field, begin_page=simplelist.begin_page, order=simplelist.change_order[field], search_text=simplelist.search_text, search_field=simplelist.search_field)}" class="">${set_css_arrow(simplelist, field)}${simplelist.model.fields[field].label}</a></div>
        % endfor 
        % for extra_field in simplelist.arr_extra_fields:
            <div class="fields_span_title options_td" style="width: ${size_td}%;">${ extra_field }</div>
        % endfor
    </div>
    <div class="table_rows ${simplelist.model.name}_table_rows" id="${simplelist.model.name}_table_rows">
        <%
        pos=0
        %>
        % for row in list:
        <div id="${simplelist.model.name}_table_${row['id']}" class="${simplelist.model.name}_table_row" style="clear: both;overflow: hidden;">        
        <%
            if not 'pos' in row:
                row['pos']=pos
        %>

            % for field in simplelist.fields_showed:
                % if simplelist.model.fields[field].escape==True: 
                <div class="${simplelist.model.fields[field].name}_td fields_span_table_data" style="width: ${size_td}%;">
                    %if type(simplelist.model.fields[field]).__name__!='ForeignKeyField':
                    ${simplelist.model.fields[field].show_formatted(row[field])}
                    % else:
                    ${str(simplelist.model.fields[field].related_model.fields[simplelist.model.fields[field].named_field].show_formatted(row[field]))} 
                    % endif
                </div>
                % else:
                <div class="${simplelist.model.fields[field].name}_td fields_span_table_data" style="width: ${size_td}%;">
                    %if type(simplelist.model.fields[field]).__name__!='ForeignKeyField':
                    ${str(simplelist.model.fields[field].show_formatted(row[field]))|n}
                    % else:
                    ${str(simplelist.model.fields[field].related_model.fields[simplelist.model.fields[field].named_field].show_formatted(row[field]))|n}
                    % endif
                </div>
                % endif
            % endfor
            
            % for extra_field_func in simplelist.arr_extra_options:
                <div class="options_td fields_span_table_data" style="width: ${size_td}%;">${ simplelist.set_options(extra_field_func, row)|n }</div>
            % endfor 
        <%
        pos+=1
        %>
        </div>
        % endfor 
    </div>
    <br clear="all" />
</div>

% endif
<p>
% if pages!='':
${lang('common', 'pages', 'Pages')}: ${pages|n}
% endif
</p>
