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

%>

<%def name="headerIncludes()">
	<div id="subhead_container">
		<div id="subhead_menu">		
                        <a id="menu_link_refresh" href="manualpull">Refresh Pull-list</a>
                        <a id="menu_link_delete" href="pullrecreate">Recreate Pull-list</a>
                        <a id="menu_link_scan" class="button">Download</a>
                      <!--  <a id="menu_link_scan" onclick="doAjaxCall('MassWeeklyDownload?pulldate=${pulldate}, $(this)),'table'" href="#" data-success="Now Downloading Comics to : ${mylar.GRABBAG_DIR}">Download.</a> -->
		</div>
	</div>	
	<a href="home" class="back">&laquo; Back to overview</a>
</%def>

<%def name="body()">
        <div class="clearfix">
              %if wantedcount == 0:
                   <h1>Weekly Pull list for : ${pulldate}</h1>
              %else:
                   <h1>Weekly Pull list for : ${pulldate} (${wantedcount})</h1>
              %endif              
        </div>

        <div>
          <form action="MassWeeklyDownload" method="GET" id="MassDownload">
             <fieldset>
                  <div class="row">
                       <input type="checkbox" name="weekfolder" id="weekfolder" value="1" ${checked(mylar.WEEKFOLDER)} /><label>Store in Weekly Directory</label> 
                       <small>Create ${weekfold}</small>
                 </div>

               <input type="hidden" name="pulldate" value=${pulldate}>
               <input type="submit" style="display:none" />
             </fieldset>
          </form>
        </div>

        <div class="table_wrapper">

	<table class="display" id="pull_table">
		<thead>
			<tr>
                                <th id="publisher">Publisher</th>
                                <th id="comicname">Comic</th>
				<th id="comicnumber">Number</th>
				<th id="status">Status</th>
			</tr>
		</thead>
		<tbody>
		%for weekly in weeklyresults:
			<%
				if weekly['STATUS'] == 'Skipped':
					grade = 'Z'
				elif weekly['STATUS'] == 'Wanted':
					grade = 'X'
				elif weekly['STATUS'] == 'Snatched':
					grade = 'C'
                                elif weekly['STATUS'] == 'Downloaded':
                                        grade = 'D'
				else:
					grade = 'A'
                                if weekly['AUTOWANT'] == True:
                                        grade = 'H'

			%>
			<tr class="grade${grade}">
                                %if pullfilter is True:
                                        <td class="publisher">${weekly['PUBLISHER']}</td>
                                        <td class="comicname">
                                        %if weekly['COMICID'] == '' or weekly['COMICID'] is None:
                                             ${weekly['COMIC']}
                                        %else:
                                             <a href="comicDetails?ComicID=${weekly['COMICID']}">${weekly['COMIC']}</a>
                                        %endif
                                        </td>
                                        <td class="comicnumber">${weekly['ISSUE']}</td>
                                        %if weekly['AUTOWANT']:
             	                             <td class="status">Auto-Want
                                        %else:
              	                            <td class="status">${weekly['STATUS']}
                                            %if weekly['STATUS'] == 'Skipped':
                                                %if weekly['ISSUE'] == '1' or weekly['ISSUE'] == '0':
                                                      <a href="#" title="Watch for this series" onclick="doAjaxCall('add2futurewatchlist?ComicName=${weekly['COMIC'] |u}&Issue=${weekly['ISSUE']}&Publisher=${weekly['PUBLISHER']}&ShipDate=${pulldate}', $(this),'table')" data-success="${weekly['COMIC']} is now on auto-watch/add."><span class="ui-icon ui-icon-plus"></span>Watch</a>
                                                %endif
                                                <a href="searchit?name=${weekly['COMIC'] | u}&issue=${weekly['ISSUE']}&mode=pullseries"><span class="ui-icon ui-icon-plus"></span>add series</a>
                                                <a href="queueissue?ComicName=${weekly['COMIC'] | u}&ComicIssue=${weekly['ISSUE']}&mode=pullwant&Publisher=${weekly['PUBLISHER']}"><span class="ui-icon ui-icon-plus"></span>one off</a>
                                            %endif
                                        %endif
                                        </td>
                                %endif
			</tr>			
		%endfor
		</tbody>
	</table>
      </div>
</%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 type="text/javascript">
        $("#menu_link_scan").click(function() {
            $('#MassDownload').submit();
            return true;
        });
        </script>       	

	<script>

        function initThisPage() {

                initActions();
                $('#pull_table').dataTable (
                        {
                                "bDestroy": true,
                                //"aoColumnDefs": [
                                //       { 'bSortable': false, 'aTargets': [ 2,3 ] }
                                //],
                                "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, 'All' ]],
                                "oLanguage": {
                                       "sLengthMenu":"Show _MENU_ issues per page",
                                       "sEmptyTable": "No issue information available",
                                       "sInfo":"Showing _TOTAL_ issues",
                                       "sInfoEmpty":"Showing 0 to 0 of 0 issues",
                                       "sInfoFiltered":"(filtered from _MAX_ total issues)",
                                       "sSearch": ""},
                                "bStateSave": true,
                                "iDisplayLength": 25,
                                "sPaginationType": "full_numbers",
                                "aaSorting": [[0, 'desc'],[1, 'asc']]
                        });
                        resetFilters("weekly");
                        setTimeout(function(){
                            initFancybox();
                        },1500)
        }

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