LocalGovIMS_localgov-ims/src/Admin/Views/SystemMessage/Edit.cshtml
@model Admin.Models.SystemMessage.EditViewModel
@{
    ViewBag.Title = "Edit system message";
}

@section Header { Edit system message }

@section Subheader { System message details }

@using (Html.BeginForm("Edit", "SystemMessage", FormMethod.Post))
{
        @Html.HiddenFor(m => m.Id)

<div>

    <div class="row mb-3">
        <div class="col-12 col-sm-9 col-md-7 col-lg-6">
            @Html.LabelFor(m => m.Message, new { @class = "form-label" })
            @Html.TextAreaFor(m => m.Message, new { @class = "form-control" })
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.Message)
            </div>
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-12 col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.Severity, new { @class = "form-label" })
            <select id="Severity" name="Severity">
                @foreach (var item in Model.SeverityList.Items)
                {
                    <option class="item" value="@item.Value" @(Model.Severity.Equals(item.Value) ? "selected" : String.Empty)>@item.Text</option>
                }
            </select>
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.Severity)
            </div>
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-12 col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.StartDate, new { @class = "form-label" })
            @Html.TextBoxFor(m => m.StartDate, "{0:yyyy-MM-ddTHH:mm:ss}", new { @class = "form-control", type = "datetime-local" })
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.StartDate)
            </div>
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-12 col-sm-6 col-md-5 col-lg-4">
            @Html.LabelFor(m => m.EndDate, new { @class = "form-label" })
            @Html.TextBoxFor(m => m.EndDate, "{0:yyyy-MM-ddTHH:mm:ss}", new { @class = "form-control", type = "datetime-local" })
            <div class="form__element--error">
                @Html.ValidationMessageFor(m => m.EndDate)
            </div>
        </div>
    </div>

    <input type="submit" value="Save" class="btn btn-primary" />
    @Html.ActionLink("Back", "Back", "SystemMessage", null, new { @class = "btn btn-secondary" })

</div>
}

@section Scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            accessibleAutocomplete.enhanceSelectElement({
                displayMenu: 'overlay',
                autoSelect: false,
                confirmOnBlur: false,
                showAllValues: true,
                defaultValue: '',
                preserveNullOptions: true,
                placeholder: 'Select severity',
                dropdownArrow: () => paymentsAdmin.controls.autocomplete.downarrow,
                selectElement: document.querySelector('#Severity')
            });

        });

        $(document).ready(function () {
            $.culture = Globalize.culture("en-GB");
            $.validator.methods.date = function (value, element) {
                //This is not ideal but Chrome passes dates through in ISO1901 format regardless of locale
                //and despite displaying in the specified format.

                return this.optional(element)
                    || Globalize.parseDate(value, "dd/mm/yyyy", "en-GB")
                    || Globalize.parseDate(value, "yyyy-mm-dd");
            }
        });
    </script>
}
