Edit.cshtml 9.6 KB

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