View.cshtml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. @using GreenTree.Nachtragsmanagement.Web.Models.Global;
  2. @{
  3. Layout = "~/Views/Shared/_FunctionLayout.cshtml";
  4. }
  5. @model IEnumerable<GreenTree.Nachtragsmanagement.Web.Models.Admin.User.RoleDataModel>
  6. <script>
  7. var deleteId;
  8. var deleteReplaceId = -1;
  9. function editRole(id) {
  10. if (!id) return;
  11. $.ajax({
  12. url: '@Url.Action("EditRole", "Admin")',
  13. data: { id: id },
  14. success: function (response) {
  15. setTimeout(function () {
  16. $(".roleEditContainer").remove();
  17. $("body").append(response);
  18. }, 200);
  19. },
  20. error: function () {
  21. alert("error occured");
  22. }
  23. });
  24. }
  25. function confirmDelete(id) {
  26. if (!id) return;
  27. deleteId = id;
  28. $.ajax({
  29. type: "GET",
  30. url: '@Url.Action("GetRole", "Admin")',
  31. data: { id: deleteId },
  32. success: function (response) {
  33. if (response == "notFound") return;
  34. var role = JSON.parse(response);
  35. $(".deleteValidation").hide();
  36. var comboBox = MVCxClientComboBox.Cast(devComboBoxRoleDeleteReplaceRole);
  37. comboBox.PerformCallback();
  38. var popupControl = MVCxClientPopupControl.Cast(devPopupControlDeleteRole);
  39. popupControl.SetHeaderText(popupControl.GetHeaderText().replace("{role}", role.Description));
  40. $(".dialogText").text($(".dialogText").text().replace("{role}", role.Description));
  41. popupControl.Show();
  42. }
  43. });
  44. }
  45. function deleteRole() {
  46. if (devRadioButtonDeleteReplaceRole.GetChecked()) {
  47. deleteReplaceId = devComboBoxRoleDeleteReplaceRole.GetValue();
  48. } else {
  49. deleteReplaceId = -1;
  50. }
  51. if (deleteReplaceId == 0) {
  52. $(".deleteValidation").text("Es muss ein Ersatz ausgewählt werden.");
  53. $(".deleteValidation").show();
  54. return;
  55. }
  56. if (deleteId == deleteReplaceId) {
  57. $(".deleteValidation").text("Der Ersatz darf nicht gleich dem zu löschenden Element sein.");
  58. $(".deleteValidation").show();
  59. return;
  60. }
  61. $.ajax({
  62. type: "POST",
  63. url: '@Url.Action("DeleteRole", "Admin")',
  64. data: { id: deleteId, replaceId: deleteReplaceId },
  65. success: function (response) {
  66. var popupControl = MVCxClientPopupControl.Cast(devPopupControlDeleteRole);
  67. popupControl.Hide();
  68. setTimeout(function () {
  69. devGridViewRole.PerformCallback();
  70. }, 200);
  71. },
  72. error: function () {
  73. alert("error occured");
  74. }
  75. });
  76. }
  77. </script>
  78. @Html.DevExpress().PopupControl(s =>
  79. {
  80. s.Name = "devPopupControlDeleteRole";
  81. s.HeaderText = "\"{role}\" löschen";
  82. s.Modal = false;
  83. s.Width = new Unit(350, UnitType.Pixel);
  84. s.CloseAction = CloseAction.CloseButton;
  85. s.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
  86. s.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
  87. s.AllowDragging = false;
  88. s.AllowResize = false;
  89. s.ShowFooter = false;
  90. s.SetContent(() =>
  91. {
  92. ViewContext.Writer.Write("<div class='dialogText' style='padding: 12px'>");
  93. ViewContext.Writer.Write("Falls Sie \"{role}\" löschen möchten, was soll mit den Benutzern geschehen, die sich bereits in dieser Rolle befinden?");
  94. ViewContext.Writer.Write("</div>");
  95. ViewContext.Writer.Write("<div style='padding: 0 12px 12px 12px'>");
  96. Html.DevExpress().RadioButton(rb =>
  97. {
  98. rb.Name = "devRadioButtonDeleteReplaceRole";
  99. rb.Text = "Eine neue Rolle zuweisen";
  100. rb.GroupName = "roleDelete";
  101. rb.Properties.ClientSideEvents.CheckedChanged =
  102. "function (s, e) { " +
  103. "devComboBoxRoleDeleteReplaceRole.SetEnabled(s.GetChecked()); " +
  104. "}";
  105. }).Render();
  106. Session.Add("RolesDeleteComboBoxSettings", new Action<ComboBoxSettings>(a =>
  107. {
  108. a.Name = "devComboBoxRoleDeleteReplaceRole";
  109. a.Width = new Unit(100, UnitType.Percentage);
  110. a.Properties.ValueType = typeof(int);
  111. a.Properties.ValueField = "Id";
  112. a.Properties.TextField = "Description";
  113. a.Properties.ClientSideEvents.BeginCallback = "function (s, e) { e.customArgs['excludedIds'] = [ deleteId ]; }";
  114. a.Properties.ClientSideEvents.EndCallback = "function (s, e) { s.SetSelectedIndex(0); }";
  115. a.SelectedIndex = 0;
  116. a.ClientEnabled = false;
  117. a.CallbackRouteValues = new
  118. {
  119. Controller = "DataCallback",
  120. Action = "RolesComboBoxExcluded",
  121. SettingsKey = "RolesDeleteComboBoxSettings"
  122. };
  123. }));
  124. ViewData.Add("RolesComboBoxSettings", "RolesDeleteComboBoxSettings");
  125. Html.RenderPartial("~/Views/Shared/DataEditorTemplates/_RolesComboBox.cshtml", EmptyIRequireDataModel.Instance, ViewData);
  126. Html.DevExpress().RadioButton(rb =>
  127. {
  128. rb.Name = "devRadioButtonDeleteRemoveRole";
  129. rb.Text = "Benutzer aus der Rolle entfernen";
  130. rb.GroupName = "roleDelete";
  131. rb.Checked = true;
  132. rb.Properties.ClientSideEvents.CheckedChanged =
  133. "function (s, e) { " +
  134. "devComboBoxRoleDeleteReplaceRole.SetEnabled(!s.GetChecked()); " +
  135. "}";
  136. }).Render();
  137. ViewContext.Writer.Write("<div class=\"deleteValidation\" style=\"display: none\"></div>");
  138. ViewContext.Writer.Write("</div>");
  139. Html.RenderPartial(
  140. "~/Views/Shared/_PopupButtonPanelYesNo.cshtml",
  141. new YesNoDialogModel
  142. {
  143. PopupName = "devPopupControlDeleteRole",
  144. YesFunction = "function (s, e) { deleteRole(); }"
  145. }
  146. );
  147. });
  148. s.Styles.Content.Paddings.Padding = new Unit(0, UnitType.Pixel);
  149. }).GetHtml()
  150. @Html.Partial("~/Views/Admin/Roles/_RoleGridPartial.cshtml", Model)