menu_info.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * 菜单详情对话框
  3. */
  4. var MenuInfoDlg = {
  5. menuInfoData: {},
  6. ztreeInstance: null,
  7. validateFields: {
  8. name: {
  9. validators: {
  10. notEmpty: {
  11. message: '菜单名称不能为空'
  12. }
  13. }
  14. },
  15. code: {
  16. validators: {
  17. notEmpty: {
  18. message: '菜单编号不能为空'
  19. }
  20. }
  21. },
  22. pcodeName: {
  23. validators: {
  24. notEmpty: {
  25. message: '父菜单不能为空'
  26. }
  27. }
  28. },
  29. url: {
  30. validators: {
  31. notEmpty: {
  32. message: '请求地址不能为空'
  33. }
  34. }
  35. },
  36. num: {
  37. validators: {
  38. notEmpty: {
  39. message: '序号不能为空'
  40. }
  41. }
  42. }
  43. }
  44. };
  45. /**
  46. * 清除数据
  47. */
  48. MenuInfoDlg.clearData = function () {
  49. this.menuInfoData = {};
  50. }
  51. /**
  52. * 设置对话框中的数据
  53. *
  54. * @param key 数据的名称
  55. * @param val 数据的具体值
  56. */
  57. MenuInfoDlg.set = function (key, value) {
  58. this.menuInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
  59. return this;
  60. }
  61. /**
  62. * 设置对话框中的数据
  63. *
  64. * @param key 数据的名称
  65. * @param val 数据的具体值
  66. */
  67. MenuInfoDlg.get = function (key) {
  68. return $("#" + key).val();
  69. }
  70. /**
  71. * 关闭此对话框
  72. */
  73. MenuInfoDlg.close = function () {
  74. parent.layer.close(window.parent.Menu.layerIndex);
  75. }
  76. /**
  77. * 收集数据
  78. */
  79. MenuInfoDlg.collectData = function () {
  80. this.set('id').set('name').set('code').set('pcode').set('url').set('num').set('levels').set('icon').set("ismenu");
  81. }
  82. /**
  83. * 验证数据是否为空
  84. */
  85. MenuInfoDlg.validate = function () {
  86. $('#menuInfoForm').data("bootstrapValidator").resetForm();
  87. $('#menuInfoForm').bootstrapValidator('validate');
  88. return $("#menuInfoForm").data('bootstrapValidator').isValid();
  89. }
  90. /**
  91. * 提交添加用户
  92. */
  93. MenuInfoDlg.addSubmit = function () {
  94. this.clearData();
  95. this.collectData();
  96. if (!this.validate()) {
  97. return;
  98. }
  99. //提交信息
  100. var ajax = new $ax(Feng.ctxPath + "/menu/add", function (data) {
  101. Feng.success("添加成功!");
  102. window.parent.Menu.table.refresh();
  103. MenuInfoDlg.close();
  104. }, function (data) {
  105. Feng.error("添加失败!" + data.responseJSON.message + "!");
  106. });
  107. ajax.set(this.menuInfoData);
  108. ajax.start();
  109. }
  110. /**
  111. * 提交修改
  112. */
  113. MenuInfoDlg.editSubmit = function () {
  114. this.clearData();
  115. this.collectData();
  116. if (!this.validate()) {
  117. return;
  118. }
  119. //提交信息
  120. var ajax = new $ax(Feng.ctxPath + "/menu/edit", function (data) {
  121. Feng.success("修改成功!");
  122. window.parent.Menu.table.refresh();
  123. MenuInfoDlg.close();
  124. }, function (data) {
  125. Feng.error("修改失败!" + data.responseJSON.message + "!");
  126. });
  127. ajax.set(this.menuInfoData);
  128. ajax.start();
  129. }
  130. /**
  131. * 点击父级编号input框时
  132. */
  133. MenuInfoDlg.onClickDept = function (e, treeId, treeNode) {
  134. $("#pcodeName").attr("value", MenuInfoDlg.ztreeInstance.getSelectedVal());
  135. $("#pcode").attr("value", treeNode.id);
  136. };
  137. /**
  138. * 显示父级菜单选择的树
  139. */
  140. MenuInfoDlg.showMenuSelectTree = function () {
  141. Feng.showInputTree("pcodeName", "pcodeTreeDiv", 15, 34);
  142. };
  143. $(function () {
  144. Feng.initValidator("menuInfoForm", MenuInfoDlg.validateFields);
  145. var ztree = new $ZTree("pcodeTree", "/menu/selectMenuTreeList");
  146. ztree.bindOnClick(MenuInfoDlg.onClickDept);
  147. ztree.init();
  148. MenuInfoDlg.ztreeInstance = ztree;
  149. //初始化是否是菜单
  150. if($("#ismenuValue").val() == undefined){
  151. $("#ismenu").val(0);
  152. }else{
  153. $("#ismenu").val($("#ismenuValue").val());
  154. }
  155. });