<%inherit file="base.html"/>
<%!
	from mylar import helpers
%>

<%def name="headerIncludes()">
	<div id="subhead_container">
		<div id="subhead_menu">
			<a id="menu_link_delete" href="#" onclick="doAjaxCall('clearhistory?type=all',$(this),'table')" data-success="All History cleared">Clear All History</a>
			<a id="menu_link_delete" href="#" onclick="doAjaxCall('clearhistory?type=Processed',$(this),'table')" data-success="All Processed cleared">Clear Processed</a>
			<a id="menu_link_delete" href="#" onclick="doAjaxCall('clearhistory?type=Unprocessed',$(this),'table')" data-success="All Unprocessed cleared">Clear Unprocessed</a>
			<a id="menu_link_delete" href="#" onclick="doAjaxCall('clearhistory?type=Snatched',$(this),'table')" data-success="All Snatched cleared">Clear Snatched</a>
		</div>
	</div>	
</%def>

<%def name="body()">
	<div id="paddingheader">
		<h1 class="clearfix"><img src="interfaces/default/images/icon_history.png" alt="History"/>History</h1>
	</div>
	<table class="display" id="history_table">
		<thead>
			<tr>
				<th id="dateadded">Date Added</th>
				<th id="filename">Comic Name</th>
                                <th id="issue">Issue</th>
				<th id="status">Status</th>
				<th id="action"></th>
			</tr>
		</thead>
		<tbody>
		%for item in history:
			<%
				if item['Status'] == 'Processed':
					grade = 'A'
				elif item['Status'] == 'Snatched':
					grade = 'C'
				elif item['Status'] == 'Unprocessed':
					grade = 'X'
				else:
					grade = 'U'
					
			%>
			<tr class="grade${grade}">
				<td id="dateadded">${item['DateAdded']}</td>
				<td id="filename">${item['ComicName']}</td>
                                <td id="issue">${item['Issue_Number']}</td>
				<td id="status">${item['Status']}</td>
				<td id="action">[<a href="#" onclick="doAjaxCall('queueissue?IssueID=${item['IssueID']}&ComicName=${item['ComicName']}&ComicID=${item['ComicID']}&ComicIssue=${item['Issue_Number']}&mode=want&redirect=history', $(this),'table')"  data-success="Retrying download of '${item['ComicName']}' '${item['Issue_Number']}'">retry</a>]</td>
			</tr>
		%endfor
		</tbody>
	</table>
</%def>

<%def name="headIncludes()">
	<link rel="stylesheet" href="interfaces/default/css/data_table.css">
</%def>

<%def name="javascriptIncludes()">
	<script src="js/libs/jquery.dataTables.min.js"></script>
	<script>
	function initThisPage() {
		$('#history_table').dataTable({
			"bDestroy": true,
			"oLanguage": {
				"sLengthMenu":"Show _MENU_ items per page",
				"sEmptyTable": "<em>No History to Display</em>",
				"sInfo":"Showing _START_ to _END_ of _TOTAL_ items",
				"sInfoEmpty":"Showing 0 to 0 of 0 items",
				"sInfoFiltered":"(filtered from _MAX_ total items)"},
			"iDisplayLength": 25,
			"sPaginationType": "full_numbers",
			"aaSorting": []

		});
		resetFilters("history");
	}
	$(document).ready(function() {
		initThisPage();
		initActions();
	});
	</script>
</%def>