@model CD67.FicheCollege.Entity.Territoire

@{
    ViewBag.Title = "Modification";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Modification</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Territoire</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.Ordre)

        <div class="form-group">
            @Html.LabelFor(model => model.Libelle, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Libelle, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Libelle, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.Label("Référent", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-4" data-picker-type="referent">
                @Html.HiddenFor(model => model.Referent_SID, new { data_picker = "agent.id" })
                @Html.HiddenFor(model => model.Referent_Nom, new { data_picker = "agent.nom" })
                @Html.HiddenFor(model => model.Referent_Prenom, new { data_picker = "agent.prenom" })
                @Html.HiddenFor(model => model.Referent_Structure, new { data_picker = "agent.chemin" })
                @Html.HiddenFor(model => model.Referent_Login, new { data_picker = "agent.login" })
                <a class='modal-window' href="http://referentiel.bas-rhin.fr/picker/cd67/ad67/?type=referent" title="Selection d'un référent (nouvelle fenetre)">Sélectionner un référent</a>
                <br />
                <div class="panel panel-default" id="Referent_Panel" name="Referent_Panel" style="@if (Model.Referent_SID == null) { <text>display: none;</text> }">
                    <div class="panel-heading clearfix">
                        <h4 class="panel-title pull-left" style="padding-top: 7.5px;">
                            <i class="fa fa-user color1" aria-hidden="true"></i>
                            Agent
                        </h4>
                        <div class="btn-group pull-right">
                            <a class="btn btn-danger btn-sm" href="#">
                                <span class="glyphicon glyphicon-trash removeItem" aria-hidden="true" data-type="referent"></span>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body" style="text-align: center;">
                        <b><span data-picker="agent.prenom">@Model.Referent_Prenom</span> <span data-picker="agent.nom">@Model.Referent_Nom</span></b>
                        <br /><span data-picker="agent.chemin">@Model.Referent_Structure</span>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Enregistrer" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Retour à la liste", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

    <script type="text/javascript">
        $(".removeItem").click(function () {
            switch ($(this).data("type")) {
                case 'referent':
                    $('#Referent_SID').val(null);
                    $('#Referent_Prenom').val(null);
                    $('#Referent_Nom').val(null);
                    $('#Referent_Structure').val(null);
                    $('#Referent_Login').val(null);
                    $('#Referent_Panel').hide();
                    break;
                default:
                    return false;
            }
        });
    </script>
}
