@using NzbDrone.Web.Helpers
@model NzbDrone.Web.Models.SystemSettingsModel

@{
    Layout = "_SettingsLayout.cshtml";
}

<div class="infoBox">
    You must manually restart NzbDrone for these changes to take effect. (Automatic restart coming soon!)
</div>

<div id="stylized">
    @using (Html.BeginForm("SaveSystem", "Settings", FormMethod.Post, new { id = "SystemForm", name = "SystemForm", @class = "settingsForm" }))
    {
        @Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.")
        <label class="labelClass">@Html.LabelFor(m => m.LaunchBrowser)
            <span class="small">@Html.DescriptionFor(m => m.LaunchBrowser)</span>
        </label>
        @Html.CheckBoxFor(m => m.LaunchBrowser, new { @class = "inputClass checkClass" })
        
        <label class="labelClass">@Html.LabelFor(m => m.Port)
            <span class="small">@Html.DescriptionFor(m => m.Port)</span>
            <span class="small">@Html.ValidationMessageFor(m => m.Port)</span>
        </label>
        @Html.TextBoxFor(m => m.Port, new { @class = "inputClass" })

        <label class="labelClass">@Html.LabelFor(m => m.AuthenticationType)
            <span class="small">@Html.DescriptionFor(m => m.AuthenticationType)</span>
        </label>
        @Html.DropDownListFor(m => m.AuthenticationType, Model.AuthTypeSelectList, new { @class = "inputClass" })

        <label class="labelClass">@Html.LabelFor(m => m.RecycleBin)
            <span class="small">@Html.DescriptionFor(m => m.RecycleBin)</span>
            <span class="small">@Html.ValidationMessageFor(m => m.RecycleBin)</span>
        </label>
        @Html.TextBoxFor(m => m.RecycleBin, new { @class = "inputClass folderLookup" })

        <label class="labelClass"> Backup Configuration
            <span class="small">Backup your Configuration file and Database</span>
        </label>
        <input type="button" value="Backup Now" onclick="window.location='../System/Backup'; return false;" class="inputClass" />
        
        <button type="submit" class="save_button" disabled="disabled">
            Save</button>
    }
</div>

@section Scripts
{
    <script type="text/javascript">
        $(document).ready(function() {
            //Allow unobstrusive validation of the AJAX loaded form
            $.validator.unobtrusive.parse('#SystemForm');

            //Validator Settings
            var settings = $.data($('#SystemForm')[0], 'validator').settings;
            settings.ignore = [];
            settings.focusInvalid = false;
            settings.onfocusout = function(element) { $(element).valid(); };

            var oldHighlight = settings.highlight;
            var oldUnhighlight = settings.unhighlight;

            settings.highlight = function(element, errorClass, validClass) {
                oldHighlight(element, errorClass, validClass);
                $(element).parents('div.ui-accordion-content').prev('h3.ui-accordion-header').addClass('validation-error');
            };
            settings.unhighlight = function(element, errorClass, validClass) {
                oldUnhighlight(element, errorClass, validClass);

                var container = $(element).parents('div.ui-accordion-content');
                if ($(container).children('.' + errorClass).length == 0)
                    $(container).prev('h3.ui-accordion-header').removeClass('validation-error');
            };
        });
    </script>
}