@model Disco.Web.Areas.Config.Models.DocumentTemplate.CreateModel
@{
    Authorization.RequireAll(Claims.Config.DocumentTemplate.Create, Claims.Config.DocumentTemplate.Configure);
    
    ViewBag.Title = Html.ToBreadcrumb("Configuration", MVC.Config.Config.Index(), "Document Templates", MVC.Config.DocumentTemplate.Index(null), "Create");
}
@using (Html.BeginForm(MVC.Config.DocumentTemplate.Create(), FormMethod.Post, new { enctype = "multipart/form-data" }))
{ 
    <div class="form" style="width: 650px">
        <table>
            <tr>
                <th>
                    Id:
                </th>
                <td>@Html.TextBoxFor(model => model.DocumentTemplate.Id)<br />@Html.ValidationMessageFor(model => model.DocumentTemplate.Id)
                </td>
            </tr>
            <tr>
                <th>
                    Description:
                </th>
                <td>@Html.TextBoxFor(model => model.DocumentTemplate.Description)<br />@Html.ValidationMessageFor(model => model.DocumentTemplate.Description)
                </td>
            </tr>
            <tr>
                <th>
                    Scope:
                </th>
                <td>
                    @Html.DropDownListFor(model => model.DocumentTemplate.Scope, Model.Scopes.ToSelectListItems(null))
                </td>
            </tr>
            <tr>
                <th>
                    Template PDF
                </th>
                <td>
                    <input type="file" name="Template" accept=".pdf" /><br />@Html.ValidationMessage("Template")
                </td>
            </tr>
            <tr id="trJobTypes">
                <th class="name">
                    Types:
                </th>
                <td class="value">
                    @CommonHelpers.CheckBoxList("Types", Model.JobTypes.ToSelectListItems(Model.Types), 2)
                </td>
            </tr>
            @foreach (var jt in Model.JobTypes)
            {
                <tr id="trJobSubType@(jt.Id)" class="jobSubTypes">
                    <th class="name">
                        @jt.Description<br />
                        Sub Types<br />
                    @CommonHelpers.CheckboxBulkSelect(string.Format("CheckboxBulkSelect_{0}", jt.Id))
                    </th>
                    <td class="value">
                        @CommonHelpers.CheckBoxList("SubTypes", Model.JobSubTypes.Where(jst => jst.JobTypeId == jt.Id).ToList().ToSelectListItems(Model.SubTypes), 2)
                    </td>
                </tr>   
            }
        </table>
        <p class="actions">
            <input type="submit" class="button" value="Create" />
        </p>
    </div>
    <script type="text/javascript">
        $(function () {
            $('#Name').focus().select();

            var $scope = $('#DocumentTemplate_Scope');
            var $trJobTypes = $('#trJobTypes');
            var $jobTypes = $trJobTypes.find('input[type="checkbox"]');
            $scope.change(scopeChange);
            $jobTypes.change(jobTypesChange);

            scopeChange();

            function scopeChange() {
                if ($scope.val() == 'Job') {
                    $trJobTypes.show();
                    jobTypesChange();
                } else {
                    $trJobTypes.hide();
                    $('.jobSubTypes').hide();
                }
            }

            function jobTypesChange() {
                $('.jobSubTypes').hide();
                $jobTypes.filter(':checked').each(function () {
                    $('#trJobSubType' + $(this).val()).show();    
                });
            }

        });
    </script>
}