create.jsp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <%@ page contentType="text/html; charset=utf-8"%>
  2. <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
  5. <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
  6. <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
  7. <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
  8. <c:set var="basePath" value="${pageContext.request.contextPath}"/>
  9. <div id="createDialog" class="crudDialog">
  10. <form id="createForm" method="post">
  11. <div class="radio">
  12. <div class="radio radio-inline radio-success">
  13. <input id="type_1" type="radio" name="type" value="1" checked>
  14. <label for="type_1">目录 </label>
  15. </div>
  16. <div class="radio radio-inline radio-info">
  17. <input id="type_2" type="radio" name="type" value="2">
  18. <label for="type_2">菜单 </label>
  19. </div>
  20. <div class="radio radio-inline radio-warning">
  21. <input id="type_3" type="radio" name="type" value="3">
  22. <label for="type_3">按钮 </label>
  23. </div>
  24. </div>
  25. <div class="form-group">
  26. <span class="type1 type2 type3">
  27. <select id="systemId" name="systemId">
  28. <option value="0">请选择系统</option>
  29. <c:forEach var="upmsSystem" items="${upmsSystems}">
  30. <option value="${upmsSystem.systemId}">${upmsSystem.title}</option>
  31. </c:forEach>
  32. </select>
  33. </span>
  34. <span class="type2 type3" hidden>
  35. <select id="pid" name="pid">
  36. <option value="0">请选择上级</option>
  37. </select>
  38. </span>
  39. </div>
  40. <div class="form-group">
  41. <label for="name">名称</label>
  42. <input id="name" type="text" class="form-control" name="name" maxlength="20">
  43. </div>
  44. <div class="form-group type2 type3" hidden>
  45. <label for="permissionValue">权限值</label>
  46. <input id="permissionValue" type="text" class="form-control" name="permissionValue" maxlength="50">
  47. </div>
  48. <div class="form-group type2 type3" hidden>
  49. <label for="uri">路径</label>
  50. <input id="uri" type="text" class="form-control" name="uri" maxlength="100">
  51. </div>
  52. <div class="form-group type1 type3">
  53. <label for="icon">图标</label>
  54. <input id="icon" type="text" class="form-control" name="icon" maxlength="50" value="zmdi zmdi-widgets">
  55. </div>
  56. <div class="radio">
  57. <div class="radio radio-inline radio-success">
  58. <input id="status_1" type="radio" name="status" value="1" checked>
  59. <label for="status_1">正常 </label>
  60. </div>
  61. <div class="radio radio-inline">
  62. <input id="status_0" type="radio" name="status" value="0">
  63. <label for="status_0">锁定 </label>
  64. </div>
  65. </div>
  66. <div class="form-group text-right dialog-buttons">
  67. <a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
  68. <a class="waves-effect waves-button" href="javascript:;" onclick="createDialog.close();">取消</a>
  69. </div>
  70. </form>
  71. </div>
  72. <script>
  73. var pidType = 0;
  74. var systemId = 0;
  75. var type = 1;
  76. $(function() {
  77. // 选择分类
  78. $('input:radio[name="type"]').change(function() {
  79. type = $(this).val();
  80. initType();
  81. });
  82. // 选择系统
  83. $('#systemId').change(function() {
  84. systemId = $(this).val();
  85. initPid();
  86. });
  87. });
  88. function initType() {
  89. // 显示对应必填项
  90. $('.type1,.type2,.type3').hide(0, function () {
  91. $('.type' + type).show();
  92. });
  93. // 级联菜单
  94. if (type == 2) {
  95. pidType = 1;
  96. initPid();
  97. }
  98. if (type == 3) {
  99. pidType = 2
  100. initPid();
  101. }
  102. }
  103. function initPid() {
  104. if (systemId != 0) {
  105. $.getJSON('${basePath}/manage/permission/list', {systemId: systemId, type: pidType, limit: 10000}, function(json) {
  106. var datas = [{id: 0, text: '请选择上级'}];
  107. for (var i = 0; i < json.rows.length; i ++) {
  108. var data = {};
  109. data.id = json.rows[i].permissionId;
  110. data.text = json.rows[i].name;
  111. datas.push(data);
  112. }
  113. $('#pid').empty();
  114. $('#pid').select2({
  115. data : datas
  116. });
  117. });
  118. } else {
  119. $('#pid').empty();
  120. $('#pid').select2({
  121. data : [{id: 0, text: '请选择上级'}]
  122. });
  123. }
  124. }
  125. function createSubmit() {
  126. $.ajax({
  127. type: 'post',
  128. url: '${basePath}/manage/permission/create',
  129. data: $('#createForm').serialize(),
  130. beforeSend: function() {
  131. if ($('#systemId').val() == 0) {
  132. $.confirm({
  133. title: false,
  134. content: '请选择系统!',
  135. autoClose: 'cancel|3000',
  136. backgroundDismiss: true,
  137. buttons: {
  138. cancel: {
  139. text: '取消',
  140. btnClass: 'waves-effect waves-button'
  141. }
  142. }
  143. });
  144. return false;
  145. }
  146. if (type == 1) {
  147. if ($('#name').val() == '') {
  148. $('#name').focus();
  149. return false;
  150. }
  151. }
  152. if (type == 2 || type == 3) {
  153. if ($('#pid').val() == 0) {
  154. $.confirm({
  155. title: false,
  156. content: '请选择上级!',
  157. autoClose: 'cancel|3000',
  158. backgroundDismiss: true,
  159. buttons: {
  160. cancel: {
  161. text: '取消',
  162. btnClass: 'waves-effect waves-button'
  163. }
  164. }
  165. });
  166. return false;
  167. }
  168. if ($('#name').val() == '') {
  169. $('#name').focus();
  170. return false;
  171. }
  172. if ($('#permissionValue').val() == '') {
  173. $('#permissionValue').focus();
  174. return false;
  175. }
  176. if ($('#uri').val() == '') {
  177. $('#uri').focus();
  178. return false;
  179. }
  180. }
  181. },
  182. success: function(result) {
  183. if (result.code != 1) {
  184. if (result.data instanceof Array) {
  185. $.each(result.data, function(index, value) {
  186. $.confirm({
  187. theme: 'dark',
  188. animation: 'rotateX',
  189. closeAnimation: 'rotateX',
  190. title: false,
  191. content: value.errorMsg,
  192. buttons: {
  193. confirm: {
  194. text: '确认',
  195. btnClass: 'waves-effect waves-button waves-light'
  196. }
  197. }
  198. });
  199. });
  200. } else {
  201. $.confirm({
  202. theme: 'dark',
  203. animation: 'rotateX',
  204. closeAnimation: 'rotateX',
  205. title: false,
  206. content: result.data.errorMsg,
  207. buttons: {
  208. confirm: {
  209. text: '确认',
  210. btnClass: 'waves-effect waves-button waves-light'
  211. }
  212. }
  213. });
  214. }
  215. } else {
  216. createDialog.close();
  217. $table.bootstrapTable('refresh');
  218. }
  219. },
  220. error: function(XMLHttpRequest, textStatus, errorThrown) {
  221. $.confirm({
  222. theme: 'dark',
  223. animation: 'rotateX',
  224. closeAnimation: 'rotateX',
  225. title: false,
  226. content: textStatus,
  227. buttons: {
  228. confirm: {
  229. text: '确认',
  230. btnClass: 'waves-effect waves-button waves-light'
  231. }
  232. }
  233. });
  234. }
  235. });
  236. }
  237. </script>