View.cshtml 5.0 KB

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