<TMPL_IF .allow.scan_series_events>

	<link href="css/jquery-ui-timepicker.css" type="text/css" rel="stylesheet" /> 
	<script src="js/jquery-ui-timepicker.js" type="text/javascript"></script>
    <script src="js/jquery.autosize.min.js" type="text/javascript"></script>

	<link href="css/theme.default.css" rel="stylesheet">
	<script src="js/jquery.tablesorter.min.js"></script>
	
    <script src="js/image.js" type="text/javascript"></script>
    <script>
        var event_id='<TMPL_VAR event_id>';
        <TMPL_IF .getBack>
            $(document).ready(
                function(){
                    getBack()
                }
            );
        </TMPL_IF>

        $(document).ready(
            function(){
                $('table#assignment_table').tablesorter({
                    widgets: ["filter"],
          	        usNumberFormat : false
                });
            }
        );

        var event_ids=[];

        function assign_series_events(project_id,studio_id,series_id){
            if (project_id=='')return false;
            if (studio_id=='')return false;
            if (series_id=='')return false;

            $('#assignments_form input[name="series_id"]').val(series_id);

            event_ids=[];
            $('input[type=checkbox]:checked').each(
                function(){
                    event_ids.push($(this).val())
                }
            );
            var event_id=event_ids.join(',');
            $('#assignments_form input[name="event_ids"]').val(event_id);

            var url="assignments.cgi?project_id="+project_id+'&studio_id='+studio_id+'&series_id='+series_id+'&event_ids='+event_id+'&action=assign_events';
            console.log(url);
            $('#assignments_form').submit();
            return false;
        }

        function clear_selection(){
            $('#tabs-assignments input[type=checkbox]:checked').prop('checked', false);
        }

        selected=0;
        function select_all(){
            clear_selection();
            selected=0;
            $('#tabs-assignments input[type=checkbox]').each(
                function(){
                    if ( $(this).parent().parent().css('display')=='none') return;
                    $(this).prop('checked', true);
                    selected++;
                }
            );
            console.log(selected+" selected")            
        }

    </script>

<style>
    body #content {
        max-width:1920px;
    }
    #content div.show_schedule{
        height:100%;
        overflow:none;
    }

    #content div.show_schedule table{
        width:100%;
    }

	#editor div p a img {
		float:right;
	}
</style>

found <TMPL_VAR sum_events> unassigned events for project <b><TMPL_VAR project_name></b> and studio <b><TMPL_VAR studio_name></b>

<!-- view series -->
<div id="view_<TMPL_VAR .series_id>" class="view" style="clear:both">
	<div class="buttons">
        <button target="_blank"
            onclick="select_all()"
            style="float:left"
        >select all</button>

        <button target="_blank"
            onclick="clear_selection()"
            style="float:left"
        >clear</button>

        <div style="float:left">Series</div>
        <select style="float:left;max-width:600px;" id="series_id">
            <option value="">--select--</option>
            <TMPL_LOOP series>
                <option value="<TMPL_VAR series_id>"><b><TMPL_VAR series_name> - <TMPL_VAR title></b> [<TMPL_VAR project_name> - <TMPL_VAR studio_name>]
            </TMPL_LOOP>
        </select>
        <form action="assignments.cgi?project_id=<TMPL_VAR .project_id>&studio_id=<TMPL_VAR .studio_id>" method="post" id="assignments_form">
            <input type="hidden" name="project_id" value="<TMPL_VAR .project_id>">
            <input type="hidden" name="studio_id" value="<TMPL_VAR .studio_id>">
            <input type="hidden" name="series_id" value="<TMPL_VAR .series_id>">	
            <input type="hidden" name="event_ids" value="<TMPL_VAR .event_id>">	
            <input type="hidden" name="action" value="assign_events">
            <button target="_blank"
                onclick="assign_series_events('<TMPL_VAR .project_id>', '<TMPL_VAR .studio_id>', $('#series_id').val());return false;"
                style="float:left"
            >assign</button>
        </form>
    </div>
</div>

<div id="tabs" style="clear:both">

    <!-- schedule -->
    <div id="tabs-assignments">

        <!-- show schedule -->
        <div id="show_schedule_<TMPL_VAR series_id>" class="show_schedule">
	        <table id="assignment_table">
                <thead>
	                <tr>
                        <th>assign</th>
                        <!--<th>id</th>-->
		                <th>program</th>
		                <th>project</th>
		                <th>location</th>
		                <th>weekday</th>
		                <th>start</th>
		                <th>series_name</th>
		                <th>title</th>
		                <th>episode</th>
		                <th>rerun</th>
		                <th>preview</th>
	                </tr>
                </thead>
                <tbody>
	        <TMPL_LOOP unassigned_events>
		            <tr>
		                <td><input class="event_id" type="checkbox" value="<TMPL_VAR id>" title="<TMPL_VAR id>"></td>
		                <!--<td><TMPL_VAR id></td>-->
		                <td><TMPL_VAR program></td>
		                <td><TMPL_VAR project></td>
		                <td><TMPL_VAR location></td>
		                <td><TMPL_VAR weekday></td>
		                <td><TMPL_VAR start></td>
		                <td><TMPL_VAR series_name></td>
		                <td><TMPL_VAR title></td>
		                <td><TMPL_VAR episode></td>
		                <td><TMPL_VAR rerun></td>
                        <td><a href="/programm/sendung/<TMPL_VAR id>.html" target="_blank"> <button >preview</button></a>
	                </tr>
	        </TMPL_LOOP>
                </tbody>
	        </table>
	    </div>
    </div>

</main>	    
</body>
</html>

</TMPL_IF>
