@using NzbDrone.Web.Models;
@model List<SeasonEditModel>

@{
    Layout = null;
}

<script type="text/javascript">
    $(document).ready(function () {
        var options = {
            target: '#result',
            //beforeSubmit: showRequest,
            success: showResponse,
            type: 'post',
            resetForm: false
        };
        $('#form').ajaxForm(options);
        $('#save_button').attr('disabled', '');
    });

    function showRequest(formData, jqForm, options) {
        $("#result").empty().html('Saving...');
        $("#form :input").attr("disabled", true);
    }

    function showResponse(responseText, statusText, xhr, $form) {
        //$("#result").empty().html(responseText);
        $("#form :input").attr("disabled", false);
        closeSeasonEditor();
    }            
</script>

@using (Html.BeginForm("SaveSeasons", "Series", FormMethod.Post, new { id = "form" }))
{
    <div style="vertical-align: middle">
        @foreach (var season in Model)
        {
            Html.RenderAction("GetSingleSeasonView", "Series", season);
        }
    </div>
    
    <div id="buttons" style="padding-top: 20px; position: absolute; bottom: 5;">
        <button type="submit" class="t-button t-state-default">Save</button>
        <button type="button" class="t-button t-state-default" onclick="closeSeasonEditor()">Cancel</button>
    </div>
}
<div id="result"></div>

<script type="text/javascript">
    var lastChecked = null;

    $(document).ready(function () {
        $('.chkbox').click(function (event) {
            if (!lastChecked) {
                lastChecked = this;
                return;
            }

            if (event.shiftKey) {
                var start = $('.chkbox').index(this);
                var end = $('.chkbox').index(lastChecked);

                for (i = Math.min(start, end); i <= Math.max(start, end); i++) {
                    $('.chkbox')[i].checked = lastChecked.checked;
                }
            }

            lastChecked = this;
        });
    });
    </script>
