_RoleEditPartial.cshtml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. @using GreenTree.Nachtragsmanagement.Core.Domain.User;
  2. @using GreenTree.Nachtragsmanagement.Web.Extensions
  3. @using GreenTree.Nachtragsmanagement.Web.Framework.Extension.DevExpress;
  4. @model GreenTree.Nachtragsmanagement.Web.Models.Admin.User.RoleDataModel
  5. <div class="roleEditContainer">
  6. <script>
  7. var textSeparator = ", ";
  8. var checkedNodesText = "";
  9. var checkedNodesCounter = 0;
  10. function saveRole() {
  11. var form = $("#roleEditForm");
  12. $(form).submit(function (e) {
  13. $.ajax({
  14. type: "POST",
  15. url: '@Url.Action("EditRole", "Admin")',
  16. data: form.serialize(),
  17. success: function (response) {
  18. setTimeout(function () {
  19. $(".roleEditContainer").remove();
  20. if (response == "success") {
  21. devGridViewRole.PerformCallback();
  22. } else {
  23. $("body").append(response);
  24. }
  25. }, 200);
  26. }
  27. });
  28. e.preventDefault();
  29. });
  30. form.submit();
  31. }
  32. function synchronizeTreeViewValues(s, e) {
  33. var treeView = MVCxClientTreeView.Cast(s);
  34. var node = treeView.GetNodeByName(e.node.name);
  35. if (node.GetChecked()) {
  36. while (node) {
  37. node.SetChecked(true);
  38. if (node.parent) {
  39. node = treeView.GetNodeByName(node.parent.name);
  40. } else {
  41. node = null;
  42. }
  43. }
  44. }
  45. checkedNodesText = "";
  46. checkedNodesCounter = 0;
  47. $("#roleEditForm").children(".hiddenRoleVal").remove();
  48. getCheckedNodesText(treeView.GetRootNode());
  49. devDropDownListFunctionValues.SetText(checkedNodesText.substr(0, checkedNodesText.length - textSeparator.length));
  50. }
  51. function getCheckedNodesText(parent) {
  52. for (var i = 0; i < parent.GetNodeCount(); i++) {
  53. if (parent.GetNode(i).GetChecked()) {
  54. checkedNodesText = checkedNodesText + parent.GetNode(i).GetText() + textSeparator;
  55. $("#roleEditForm").append('<input class="hiddenRoleVal" type="hidden" name="FunctionValues[' + checkedNodesCounter + ']" value="' + parent.GetNode(i).name + '" />');
  56. checkedNodesCounter++;
  57. }
  58. if (parent.GetNode(i).GetNodeCount() != 0) {
  59. getCheckedNodesText(parent.GetNode(i));
  60. }
  61. }
  62. }
  63. </script>
  64. @Html.DevExpress().PopupControl(s =>
  65. {
  66. s.Name = "devPopupControlEditRole";
  67. if (Model.Id == -1)
  68. s.HeaderText = "Neue Rolle erstellen";
  69. else
  70. s.HeaderText = "\"" + Model.Description + "\" bearbeiten";
  71. s.Modal = true;
  72. s.Width = new Unit(400, UnitType.Pixel);
  73. s.CloseAction = CloseAction.CloseButton;
  74. s.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
  75. s.PopupVerticalAlign = PopupVerticalAlign.TopSides;
  76. s.PopupVerticalOffset = 10;
  77. s.AllowDragging = false;
  78. s.AllowResize = false;
  79. s.ShowFooter = false;
  80. s.ShowOnPageLoad = true;
  81. s.SetContent(() =>
  82. {
  83. using (Html.BeginForm("EditRole", "Admin", FormMethod.Post, new { id = "roleEditForm" }))
  84. {
  85. ViewContext.Writer.Write("<div class='editFormWrapper'>");
  86. ViewContext.Writer.Write("<input type=\"hidden\" value=\"" + Model.Id + "\" id=\"Id\" name=\"Id\" />");
  87. ViewContext.Writer.Write(Html.CustomLabelFor(m => m.FunctionValues, "Funktionen:"));
  88. ViewContext.Writer.Write(Html.ValidationMessageFor(m => m.FunctionValues).ToHtmlString());
  89. Html.DevExpress().DropDownEdit(t =>
  90. {
  91. t.Name = "devDropDownListFunctionValues";
  92. t.Width = new Unit(100, UnitType.Percentage);
  93. if (Model.FunctionDescriptions != null && Model.FunctionDescriptions.Any())
  94. t.Text = String.Join(", ", Model.FunctionDescriptions);
  95. t.SetDropDownWindowTemplateContent(l =>
  96. {
  97. ViewContext.Writer.Write("<div style='width: auto; overflow: auto; max-height: 200px'>");
  98. Html.DevExpress().TreeView(tv =>
  99. {
  100. var allFunctions = ViewData["AllFunctions"] as IList<Function>;
  101. tv.Name = "devTreeViewFunctionValues";
  102. tv.AllowCheckNodes = true;
  103. tv.CreateGroupedFunctionList(allFunctions);
  104. foreach (var checkedFunction in Model.FunctionValues)
  105. {
  106. tv.Nodes.FindRecursive(n => n.Name == checkedFunction.ToString()).Checked = true;
  107. }
  108. tv.ClientSideEvents.CheckedChanged = "function (s, e) { synchronizeTreeViewValues(s, e); }";
  109. }).Render();
  110. ViewContext.Writer.Write("</div>");
  111. });
  112. }).Render();
  113. ViewContext.Writer.Write(Html.CustomLabelFor(m => m.Description, "Beschreibung:"));
  114. ViewContext.Writer.Write(Html.ValidationMessageFor(m => m.Description).ToHtmlString());
  115. Html.DevExpress().TextBoxFor(m => m.Description, t =>
  116. {
  117. t.Width = new Unit(100, UnitType.Percentage);
  118. }).Render();
  119. ViewContext.Writer.Write(Html.CustomLabelFor(m => m.Level, "Stufe:"));
  120. ViewContext.Writer.Write(Html.ValidationMessageFor(m => m.Level).ToHtmlString());
  121. Html.DevExpress().SpinEditFor(m => m.Level, t =>
  122. {
  123. t.Width = new Unit(60, UnitType.Percentage);
  124. t.Properties.NumberType = SpinEditNumberType.Integer;
  125. t.Properties.MinValue = 0;
  126. }).Render();
  127. ViewContext.Writer.Write("</div>");
  128. Html.RenderPartial(
  129. "~/Views/Shared/_PopupButtonPanel.cshtml",
  130. new GreenTree.Nachtragsmanagement.Web.Models.Global.PopupModel
  131. {
  132. PopupName = "devPopupControlEditRole",
  133. AcceptFunction = "function (s, e) { saveRole(); }"
  134. }
  135. );
  136. }
  137. });
  138. s.Styles.Content.Paddings.Padding = new Unit(0);
  139. s.Styles.ModalBackground.Opacity = 0;
  140. }).GetHtml()
  141. </div>