View.cshtml 5.5 KB

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