#import sickbeard
#import os.path
#import datetime
#import re
#from sickbeard import history
#from sickbeard import providers
#from sickbeard.providers import generic
#from sickbeard.common import *
#set global $title="History"

#set global $sbPath=".."

#set global $topmenu="history"#
#include $os.path.join($sickbeard.PROG_DIR, "data/interfaces/default/inc_top.tmpl")

<script type="text/javascript">
<!--
\$(document).ready(function() 
{ 
    \$("#historyTable:has(tbody tr)").tablesorter({
        widgets: ['zebra', 'stickyHeaders', 'filter'],
        sortList: [[0,1]],
        textExtraction: {
            4: function(node) { return \$(node).find("span").text().toLowerCase(); }
        }
    });
    \$('#limit').change(function(){
        url = '$sbRoot/history/?limit='+\$(this).val()
        window.location.href = url
    });
});
//-->
</script>

<div class="h2footer align-right"><b>Limit:</b> 
    <select name="limit" id="limit">
        <option value="100" #if $limit == "100" then "selected=\"selected\"" else ""#>100</option>
        <option value="250" #if $limit == "250" then "selected=\"selected\"" else ""#>250</option>
        <option value="500" #if $limit == "500" then "selected=\"selected\"" else ""#>500</option>
        <option value="0" #if $limit == "0" then "selected=\"selected\"" else ""#>All</option>
    </select>
</div><br/>

<table id="historyTable" class="tablesorter" cellspacing="1" border="0" cellpadding="0">
  <thead><tr><th class="nowrap">Time</th><th>Episode</th><th>Action</th><th>Provider</th><th>Quality</th></tr></thead>
  <tbody>
#for $hItem in $historyResults:
#set $curStatus, $curQuality = $Quality.splitCompositeStatus(int($hItem["action"]))
  <tr>
    <td class="nowrap">$datetime.datetime.strptime(str($hItem["date"]), $history.dateFormat)</td>
    <td><a href="$sbRoot/home/displayShow?show=$hItem["showid"]#season-$hItem["season"]">$hItem["show_name"] - <%=str(hItem["season"]) +"x"+ "%02i" % int(hItem["episode"]) %></a></td>
    <td align="center">$statusStrings[$curStatus]</td>
    <td align="center">
    #if $curStatus == DOWNLOADED and $str($hItem["provider"]) == '-1':
        #set $match = $re.search("\-(\w+)\.\w{3}\Z", $os.path.basename($hItem["resource"]))
        #if $match:
            #if $match.group(1).upper() in ("X264", "720P"):
                #set $match = $re.search("(\w+)\-.*\-"+$match.group(1)+"\.\w{3}\Z", $os.path.basename($hItem["resource"]), re.IGNORECASE)
                #if $match:
                    $match.group(1).upper()
                #end if
            #else:
                $match.group(1).upper()
            #end if
        #end if
    #elif $curStatus == DOWNLOADED:
        $hItem["provider"]
    #else
      #if $len($hItem["provider"]) > 0
        #set $provider = $providers.getProviderClass($generic.GenericProvider.makeID($hItem["provider"]))
        #if $provider != None: 
        <img src="$sbRoot/images/providers/<%=provider.imageName()%>" width="16" height="16" alt="$provider.name" title="$provider.name"/>
        #else:
        <img src="$sbRoot/images/providers/missing.png" width="16" height="16" alt="missing provider" title="missing provider"/>
        #end if
      #end if
    #end if
    </td>
    <td align="center"><span class="quality $Quality.qualityStrings[$curQuality].replace("720p","HD720p").replace("1080p","HD1080p").replace("RawHD TV", "RawHD").replace("HD TV", "HD720p")">$Quality.qualityStrings[$curQuality]</span></td>
  </tr>
#end for
  </tbody>
</table>

#include $os.path.join($sickbeard.PROG_DIR, "data/interfaces/default/inc_bottom.tmpl")
