f8f12761f18d8b5e17b75948cf3eaa57c66d9f08.svn-base 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /**
  2. * @class 系统菜单管理类
  3. * 功能:管理系统菜单,该菜单内容只有“系统管理员”才有访问权限
  4. *
  5. * @author 徐杨
  6. * @since v1.0 2014-07-18
  7. *
  8. */
  9. com.sinosoft.lz.system.right.SysMenu = function(){
  10. var _this = this;
  11. _this.listTreeGrid = null;
  12. /** 菜单表名 **/
  13. var tableName = 'SYS_MENU';
  14. /** 根节点 **/
  15. var root = 10;
  16. var classid = 893;
  17. function filterHandler(childData){
  18. //alert(JSON.stringify(childData));
  19. var newData=[];
  20. $.each(childData["rows"],function(idx,item){
  21. newData.push(item);
  22. });
  23. return newData;
  24. }
  25. /******新增Form信息***********/
  26. _this.addForm = function(){
  27. /*
  28. * 思路:
  29. * 当点击一条记录的时候获得该记录id的值, 并作为新增记录的id值
  30. * 如果没有点击记录,则默认值是根节点id
  31. * 并将id值和父id值给表单初始化
  32. */
  33. var rows = _this.listTreeGrid.getSelectedRows();
  34. var initrow = {};
  35. initrow['classid'] = classid;
  36. if(rows.length == 1){
  37. initrow['PARENTCODE_893'] = rows[0]['code'];
  38. }else{
  39. initrow['PARENTCODE_893'] = root;
  40. }
  41. $.ajax({
  42. type: "POST",
  43. url:$.pathname() + '/ws/indexMag/SysMenuService/newMenu',
  44. data: initrow['PARENTCODE_893'],
  45. success: function(data){
  46. // alert(data);
  47. if(data != '2'){
  48. top.Dialog.alert("此处不允许添加新菜单!");
  49. return ;
  50. }else {
  51. //自动生成id
  52. createId(initrow['PARENTCODE_893'], function(id){
  53. var diag = new top.Dialog();
  54. diag.Title = '新增';
  55. diag.URL = $.pathname() + '/page/system/right/addMenu.jsp?fd_id=&code='+id+"&pcode="+initrow['PARENTCODE_893'];
  56. //alert(diag.URL);
  57. diag.OkButtonText = '提交';
  58. diag.OKEvent = function(){
  59. _this.add(diag);
  60. };
  61. diag.Width = 750; //宽度
  62. diag.Height = 320; //高度
  63. diag.ButtonAlign = 'center';
  64. diag.show();
  65. });
  66. }
  67. },
  68. error:function(data){
  69. }
  70. });
  71. };
  72. /**
  73. * 功能:保存方法
  74. */
  75. _this.add = function(diag) {
  76. $form = diag.innerFrame.contentWindow.$('#sysmenu_form');
  77. var valid = $form.validationEngine({returnIsValid: true});
  78. if(valid){
  79. var formValue = $form.serialize();
  80. $.ajax({
  81. url : url = $.pathname() + '/ws/crud/CRUDService/create',
  82. type : 'post',
  83. timeout : 15000,
  84. data : formValue,
  85. dataType : 'json',
  86. success : function(data){
  87. top.Dialog.close();
  88. top.Dialog.alert("提交成功", null, null, null, 1);
  89. window.location.href='/nwyj/page/system/right/SysMenu.jsp';
  90. },
  91. error : function(e){
  92. $.messager.alert('系统提示信息', '访问服务失败!', 'error');
  93. }
  94. });
  95. }
  96. };
  97. /**
  98. * 功能:根据父id自动创建id
  99. * @param parentId 父id
  100. * @param fn 成功时调用的函数
  101. */
  102. var createId = function(parentId, fn){
  103. var url = $.pathname() + '/ws/indexMag/SysMenuService/createDetail';
  104. var param = {node : parentId, name : tableName};
  105. $.ajax({
  106. url : url,
  107. type : 'post',
  108. data : param,
  109. dataType : 'text',
  110. success : function(data){
  111. if (data) fn(data);
  112. },
  113. error : function(){
  114. $.messager.alert('系统提示信息', '访问服务失败!', 'error');
  115. }
  116. });
  117. };
  118. /******修改Form信息***********/
  119. _this.editForm = function(){
  120. var rows = _this.listTreeGrid.getSelectedRows();
  121. var rowsLength = rows.length;
  122. if (rowsLength == 0) {
  123. Dialog.alert('请选中要修改的记录!');
  124. return;
  125. } else if (rowsLength > 1) {
  126. Dialog.alert('请选中一条要修改的记录!');
  127. return;
  128. } else {
  129. var fd_id = _this.listTreeGrid.getSelectedRow().fd_objectid; //
  130. var diag = new Dialog();
  131. diag.Title = '修改';
  132. diag.URL = $.pathname() +'/page/system/right/addMenu.jsp?fd_id='+fd_id;
  133. diag.OkButtonText = '提交';
  134. diag.OKEvent = function(){
  135. _this.edit(diag);
  136. };
  137. diag.Width = 750; //宽度
  138. diag.Height = 320; //高度
  139. diag.ButtonAlign = 'center';
  140. diag.show();
  141. }
  142. };
  143. _this.edit = function(diag){
  144. $form = diag.innerFrame.contentWindow.$('#sysmenu_form');
  145. var valid = $form.validationEngine({returnIsValid: true});
  146. if(valid){
  147. var formValue = $form.serialize();
  148. $.ajax({
  149. url : $.pathname() + '/ws/crud/CRUDService/update',
  150. type : 'post',
  151. timeout : 15000,
  152. data : formValue,
  153. dataType : 'json',
  154. success : function(data){
  155. Dialog.close();
  156. Dialog.alert("修改成功", null, null, null, 1);
  157. _this.listTreeGrid.loadData(); //刷新表格数据
  158. window.location.href='/nwyj/page/system/right/SysMenu.jsp';
  159. },
  160. error : function(e){
  161. $.messager.alert('系统提示信息', '访问服务失败!', 'error');
  162. }
  163. });
  164. }
  165. };
  166. /****删除****/
  167. _this.del = function(){
  168. var rows = _this.listTreeGrid.getSelectedRows();
  169. var rowsLength = rows.length;
  170. if (rowsLength == 0) {
  171. top.Dialog.alert('请选中要删除的记录!');
  172. return;
  173. }
  174. var ids = '';
  175. for ( var i = 0; i < rowsLength; i++) {
  176. ids += rows[i].fd_objectid + ',';
  177. }
  178. top.Dialog.confirm('确定要删除吗?', function() {
  179. $.post($.pathname() +'/ws/crud/CRUDService/delete/', {
  180. objectIDs : ids,
  181. classid : '893'
  182. },
  183. function(result) {
  184. if (result.Msg.sucsess == true) {
  185. top.Dialog.alert('删除成功!', null, null, null, 1);
  186. window.location.href='/nwyj/page/system/right/SysMenu.jsp';
  187. _this.listTreeGrid.loadData();
  188. }else{
  189. top.Dialog.alert('删除失败!');
  190. }
  191. }, 'json');
  192. });
  193. };
  194. $('#searchButton').click(function() {
  195. var name = $('#searchInput').val();
  196. $.ajax({
  197. url : $.pathname() + '/ws/crud/CRUDService/query',
  198. type : 'post',
  199. timeout : 15000,
  200. data : {'RIGHTNAME_893':name,'listId':'893'},
  201. dataType : 'json',
  202. success : function(data){
  203. _this.listTreeGrid.loadData(); //刷新表格数据
  204. },
  205. error : function(e){
  206. $.messager.alert('系统提示信息', '访问服务失败!', 'error');
  207. }
  208. });
  209. });
  210. _this.InitGrid = function (){
  211. var gridData={"rows":[{"rightName":"菜单管理","isParent":true,"open":false}]};
  212. _this.listTreeGrid = $("#system_right_sysmenu").quiGrid({
  213. columns: [
  214. { name: 'fd_objectid', align: 'left',hide:true },
  215. { display: '菜单名称', name: 'rightName', id:'code', align: 'left', width:'20%' },
  216. { display: '节点', name: 'code', align: 'left',hide:true, width:'20%' },
  217. { display: '父节点', name: 'parentcode', align: 'left',hide:true, width:'20%' } ,
  218. { display: '排序号', name: 'sort', align: 'left', width:'20%' },
  219. { display: '按钮图片', name: 'img', align: 'left', width:'20%' },
  220. { display: '菜单功能', name: 'functionlink', align: 'left', width:'20%' }
  221. ],
  222. toolbar:{
  223. items:[
  224. {text: '新增',click:_this.addForm, iconClass: 'icon_add'},
  225. { line : true },
  226. {text: '删除', click: _this.del, iconClass: 'icon_delete'},
  227. { line : true },
  228. {text: '修改', click:_this.editForm, iconClass: 'icon_edit'},
  229. { line : true }
  230. // ,
  231. // {text: '查看详细信息', /*click: exportPageData,*/ iconClass: 'icon_view'}
  232. ]
  233. } ,
  234. height: '100%',
  235. width:'100%',
  236. percentWidthMode:true,
  237. checkbox:true,
  238. usePager: false,
  239. data:gridData,
  240. autoCheckChildren:true,
  241. tree: { columnId: 'code' },
  242. treeChildDataPath: $.pathname() +"/ws/indexMag/SysMenuService/getMenutTree/",
  243. autoCheckChildren:false,
  244. treeAjax:true,
  245. treeAutoParam:"code",
  246. treeDataFilter:filterHandler
  247. });
  248. };
  249. return {
  250. init : function(){
  251. _this.InitGrid();
  252. },
  253. searchHandler :function(){
  254. var name = $('#searchInput').val();
  255. $.ajax({
  256. url : $.pathname() + '/ws/crud/CRUDService/queryQuiTree',
  257. type : 'post',
  258. timeout : 15000,
  259. data : {'RIGHTNAME_893':name,'listId':'893'},
  260. dataType : 'json',
  261. success : function(data){
  262. alert($treegrid.loadData());
  263. $treegrid.loadData(); //刷新表格数据
  264. },
  265. error : function(e){
  266. $.messager.alert('系统提示信息', '访问服务失败!', 'error');
  267. }
  268. });
  269. }
  270. };
  271. }();
  272. $(function(){
  273. com.sinosoft.lz.system.right.SysMenu.init();
  274. });
  275. $.menu = com.sinosoft.lz.system.right.SysMenu;