Edit.cshtml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. @using CD67.FicheCollege.MVC.Models
  2. @model TopModel
  3. @{
  4. ViewBag.Title = "Ajout";
  5. Layout = "~/Views/Shared/_Layout.cshtml";
  6. College college = (Model.Obj as College);
  7. }
  8. <h1>@college.Libelle</h1>
  9. @using (Html.BeginForm())
  10. {
  11. @Html.AntiForgeryToken()
  12. <fieldset>
  13. <legend>
  14. Informations générales - @Model.Acces.ToString()
  15. </legend>
  16. <div class="form-horizontal">
  17. <h4>Collège</h4>
  18. <hr />
  19. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  20. @if (Model.Acces == ModeAcces.Modification)
  21. {
  22. @Html.HiddenFor(model => college.Id)
  23. }
  24. <div class="form-group">
  25. @Html.LabelFor(model => college.CodeRne, htmlAttributes: new { @class = "control-label col-md-2" })
  26. <div class="col-md-10">
  27. @if (Model.Acces == ModeAcces.Modification)
  28. {
  29. @Html.EditorFor(model => college.CodeRne, new { htmlAttributes = new { @class = "form-control", @disabled = true } })
  30. }
  31. else
  32. {
  33. @Html.EditorFor(model => college.CodeRne, new { htmlAttributes = new { @class = "form-control" } })
  34. }
  35. @Html.ValidationMessageFor(model => college.CodeRne, "", new { @class = "text-danger" })
  36. </div>
  37. </div>
  38. <div class="form-group">
  39. @Html.LabelFor(model => college.Libelle, htmlAttributes: new { @class = "control-label col-md-2" })
  40. <div class="col-md-10">
  41. @Html.EditorFor(model => college.Libelle, new { htmlAttributes = new { @class = "form-control" } })
  42. @Html.ValidationMessageFor(model => college.Libelle, "", new { @class = "text-danger" })
  43. </div>
  44. </div>
  45. <div class="form-group">
  46. @Html.LabelFor(model => college.TypeCollege_Id, htmlAttributes: new { @class = "control-label col-md-2" })
  47. <div class="col-md-10">
  48. @Html.DropDownListFor(model => college.TypeCollege_Id, (Model.Bag["Select_TypeCollege"] as IEnumerable<SelectListItem>), htmlAttributes: new { @class = "form-control" })
  49. @Html.ValidationMessageFor(model => college.TypeCollege_Id, "", new { @class = "text-danger" })
  50. </div>
  51. </div>
  52. <div class="form-group">
  53. @Html.LabelFor(model => college.Adresse, htmlAttributes: new { @class = "control-label col-md-2" })
  54. <div class="col-md-10">
  55. @Html.EditorFor(model => college.Adresse, new { htmlAttributes = new { @class = "form-control" } })
  56. @Html.ValidationMessageFor(model => college.Adresse, "", new { @class = "text-danger" })
  57. </div>
  58. </div>
  59. @Html.HiddenFor(model => college.Commune_Insee, new { data_picker = "commune.insee" })
  60. @Html.HiddenFor(model => college.Commune, new { data_picker = "commune.nom" })
  61. @Html.HiddenFor(model => college.Canton, new { data_picker = "commune.canton" })
  62. @Html.HiddenFor(model => college.Territoire_Id, new { data_picker = "commune.code_tad" })
  63. @Html.HiddenFor(model => college.TAD, new { data_picker = "commune.tad" })
  64. @Html.HiddenFor(model => college.CDC, new { data_picker = "commune.cdc" })
  65. <div class="form-group">
  66. @Html.LabelFor(model => college.Commune, htmlAttributes: new { @class = "control-label col-md-2 required" })
  67. <div class="col-md-4">
  68. <a class='modal-window-events' href="http://referentiel.bas-rhin.fr/picker/cd67/com67/" title="Selection commune (nouvelle fenetre)">Sélectionner une commune</a>
  69. <br />
  70. <div class="panel panel-default" id="Commune_Panel" name="Commune_Panel" style="@if (college.Commune_Insee == null) { <text>display: none;</text> }">
  71. <div class="panel-heading clearfix">
  72. <h4 class="panel-title pull-left" style="padding-top: 7.5px;">
  73. <i class="fa fa-map-marker color1" aria-hidden="true"></i>
  74. Localisation (commune)
  75. </h4>
  76. <div class="pull-right">
  77. <span class="glyphicon glyphicon-trash removeItem btn btn-danger btn-sm" aria-hidden="true" data-type="commune"></span>
  78. </div>
  79. </div>
  80. <div class="panel-body" style="text-align: center;">
  81. <span>
  82. <b><span data-picker="commune.nom">@college.Commune</span ></b >
  83. <br />Canton : <span data-picker="commune.canton">@college.Canton</span >
  84. <br />TAD : <span data-picker="commune.tad">@college.TAD</span >
  85. <br />CDC : <span data-picker="commune.cdc">@college.CDC</span >
  86. </span>
  87. </div>
  88. </div>
  89. @Html.ValidationMessageFor(model => college.Commune, "", new { @class = "text-danger" })
  90. </div>
  91. </div>
  92. <div class="form-group">
  93. @Html.LabelFor(model => college.Code_Postal, htmlAttributes: new { @class = "control-label col-md-2" })
  94. <div class="col-md-10">
  95. Code(s) postal(aux) associé(s) à la commune <span id="CP-warning" class="text-danger" style="@if ((Model.Bag["Select_CodePostaux"] as IEnumerable<SelectListItem>).Count() == 1) { <text>display: none;</text> }">(attention, plusieurs choix possibles)</span> : <input id="code_postaux" data-picker="commune.code_postal" value="@String.Join(",", (Model.Bag["Select_CodePostaux"] as IEnumerable<SelectListItem>).Select(i => i.Text))" class="disabled-input-as-label" />
  96. <br />
  97. @Html.DropDownListFor(model => college.Code_Postal, (Model.Bag["Select_CodePostaux"] as IEnumerable<SelectListItem>), htmlAttributes: new { @class = "form-control" })
  98. @Html.ValidationMessageFor(model => college.Code_Postal, "", new { @class = "text-danger" })
  99. </div>
  100. </div>
  101. <div class="form-group">
  102. @Html.LabelFor(model => college.Tel, htmlAttributes: new { @class = "control-label col-md-2" })
  103. <div class="col-md-10">
  104. @Html.EditorFor(model => college.Tel, new { htmlAttributes = new { @class = "form-control" } })
  105. @Html.ValidationMessageFor(model => college.Tel, "", new { @class = "text-danger" })
  106. </div>
  107. </div>
  108. <div class="form-group">
  109. @Html.LabelFor(model => college.Fax, htmlAttributes: new { @class = "control-label col-md-2" })
  110. <div class="col-md-10">
  111. @Html.EditorFor(model => college.Fax, new { htmlAttributes = new { @class = "form-control" } })
  112. @Html.ValidationMessageFor(model => college.Fax, "", new { @class = "text-danger" })
  113. </div>
  114. </div>
  115. <div class="form-group">
  116. @Html.LabelFor(model => college.Email, htmlAttributes: new { @class = "control-label col-md-2" })
  117. <div class="col-md-10">
  118. @Html.EditorFor(model => college.Email, new { htmlAttributes = new { @class = "form-control" } })
  119. @Html.ValidationMessageFor(model => college.Email, "", new { @class = "text-danger" })
  120. </div>
  121. </div>
  122. <div class="form-group">
  123. <div class="col-md-offset-2 col-md-10">
  124. <input type="submit" value="@Model.Acces.EnumDisplayNameFor(MvcHtmlHelpers.DisplayValue.Prompt)" class="btn btn-default" /> |
  125. @if (Model.Acces == ModeAcces.Creation)
  126. { @Html.ActionLink("Annuler", "Index") }
  127. else
  128. { @Html.ActionLink("Annuler", "Details", new { Id = college.Id }) }
  129. </div>
  130. </div>
  131. </div>
  132. </fieldset>
  133. }
  134. @section Scripts {
  135. <script type="text/javascript">
  136. $(".removeItem").click(function () {
  137. switch ($(this).data("type")) {
  138. case 'commune':
  139. $('#Code_Postal').val(null);
  140. $('#Commune_Insee').val(null);
  141. $('#Commune').val(null);
  142. $('#Canton').val(null);
  143. $('#Territoire_Id').val(null);
  144. $('#TAD').val(null);
  145. $('#CDC').val(null);
  146. $('#Commune_Panel').hide();
  147. //suppression du champ en dessous
  148. $('#code_postaux').val(null);
  149. $('#contenu_Code_Postal').empty();
  150. $('#CP-warning').hide();
  151. break;
  152. default:
  153. return false;
  154. }
  155. });
  156. // Function à implémenter pour éviter une erreur
  157. function onModalOpen()
  158. {
  159. $('#CP-warning').hide();
  160. }
  161. function onModalClose()
  162. {
  163. var code_postaux = $('#code_postaux').val();
  164. if (code_postaux != '') {
  165. //On vide la liste actuelle
  166. $('#contenu_Code_Postal').empty();
  167. var liste = code_postaux.split(',');
  168. liste.forEach(function (element) {
  169. //On ajoute les choix
  170. $('#contenu_Code_Postal').append($('<option>', {
  171. value: element,
  172. text: element
  173. }));
  174. });
  175. if (liste.length > 1) $('#CP-warning').show();
  176. }
  177. }
  178. </script>
  179. @Scripts.Render("~/bundles/jqueryval")
  180. }