_RoleEditPartial.cshtml 4.6 KB

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