GroupRole.cshtml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. @using WeApp
  2. @using WeApp.Configuration
  3. @using WeApp.Authorization
  4. @using WeApp.Views.Shared.Modals
  5. @using WeApp.Views.Shared.SearchForm
  6. @using WeApp.Views.Shared.Table
  7. @{
  8. ViewBag.Title = "演练角色组预案信息维护";
  9. string activeMenu = PermissionNames.PagesBasicMgGroupRoleMg; //The menu item will be active for this page.
  10. ViewBag.ActiveMenu = activeMenu;
  11. var searchForm = new SearchFormViewModel(new List<SearchItem>()
  12. {
  13. new SearchItem("roleGroupName","预案名称"),
  14. },"search-form",false);
  15. var table = new TableViewModel(IwbConsts.ApiAppUrl + "TrainingRoleGroup/GetAll", activeMenu, searchForm)
  16. .SetFields(new List<FieldItem>()
  17. {
  18. new FieldItem("roleGroupName", "预案名称"),
  19. new FieldItem("roleNames", "角色"),
  20. });
  21. }
  22. @section css{
  23. }
  24. @Html.Partial("Table/_Table", table)
  25. @section modal{
  26. <!--Main Modal-->
  27. @{
  28. var modal = new ModalViewModel("角色组", new ModalBodyViewModel(new List<Input>()
  29. {
  30. new InputHide("id"),
  31. new Input("roleGroupName", "预案名称"),
  32. new InputTextarea("description", "预案描述").SetNotRequired(),
  33. }));
  34. }
  35. @Html.Partial("Modals/_Modal", modal)
  36. }
  37. @section scripts
  38. {
  39. <script type="text/javascript">
  40. var $table;
  41. $(function () {
  42. $table = LoadTable();
  43. var funs = window.iwbfuns || { none: function () { console.log("No type"); } };
  44. funs["btnCreate"] = function() {
  45. BtnCreate({
  46. data: { id: "" },
  47. dataFun: GetSaveData,
  48. shownAfter: function() {
  49. GetRoleInfo();
  50. }
  51. });
  52. }
  53. funs["btnUpdate"] = function () {
  54. var row = $table.bootstrapTable('getSelections')[0];
  55. if (row) {
  56. BtnUpdate({
  57. disabled: "",
  58. dataFun: GetSaveData,
  59. shownAfter: function() {
  60. GetRoleInfo(row.roles);
  61. }
  62. },
  63. row);
  64. } else {
  65. abp.message.warn(abp.localization.iwbZero('SelectRecordOperation'));
  66. }
  67. BtnUpdate({ disabled: "" });
  68. };
  69. });
  70. function GetSaveData() {
  71. var data = $.formSerialize($('#modal form'));
  72. var roleNos = [];
  73. $('#modal #role-box input[name="role"]:checked').each(function () {
  74. if ($(this).is(':checked')) {
  75. roleNos.push($(this).data('role-no'));
  76. }
  77. });
  78. data.roleNos = roleNos;
  79. return data;
  80. }
  81. </script>
  82. <script>
  83. function GetRoleInfo(roleNos) {
  84. $('#modal #role-box').remove();
  85. $.iwbAjax4({
  86. url: abp.appUrl + "TrainingRoleGroup/GetAllRoles",
  87. block: true,
  88. success: function(res) {
  89. FormatterRoleBody(res, roleNos);
  90. }
  91. });
  92. }
  93. function FormatterRoleBody(data, roleNos) {
  94. var $Div = $('<div>', { 'css': { 'padding': '0 10px 10px' }, 'id': 'role-box' });
  95. var temp =
  96. '<label class="iwb-checkbox iwb-{3}"><input type="checkbox" id="role-{0}" data-role-no="{0}" name="role" value="{0}" {2}><span></span>{1}</label>';
  97. var $roleBox = $('<div>', { 'class': 'dynamic-box row', 'css': { 'margin': '10px', 'paddingBottom': '0' } });
  98. var roleArr = roleNos ? roleNos.split(',') : undefined;
  99. if (data) {
  100. data.forEach(function(v) {
  101. var checkedStr = "";
  102. if (roleArr && roleArr.indexOf(v.id) > -1) {
  103. checkedStr = "checked";
  104. }
  105. var $role = $('<div>', { 'class': 'col-sm-3' })
  106. .append(temp.format(v.id, v.roleName, checkedStr, 'green'));
  107. $roleBox.append($role);
  108. });
  109. }
  110. var $info = $('<div>', { 'class': 'iwb-info-box iwb-sm', 'css': { 'padding': '0 10px' } });
  111. $info.append('<div class="box-header">演练角色</div>');
  112. $info.append($roleBox);
  113. $Div.append($info);
  114. $('#modal form').append($Div);
  115. }
  116. </script>
  117. <!--格式化-->
  118. <script id="formatter-script" type="text/javascript">
  119. function TypeFormatter(v) {
  120. var name = $('#hid-type option[value="' + v + '"]').text();
  121. switch (v) {
  122. case 0:
  123. return '<span class="label label-danger">' + name +'</span>';
  124. default:
  125. return '<span class="label label-info">' + name +'</span>';
  126. }
  127. }
  128. </script>
  129. }
  130. <section style="display: none">
  131. <select id="hid-type">
  132. <option value=""></option>
  133. </select>
  134. @*@Html.DropDownList("hid-type", type)*@
  135. </section>