gridPage.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <%var cssParam = {%>
  2. <%};%>
  3. <%var jsParam = {%>
  4. <script type="text/javascript">
  5. jQuery(function($) {
  6. var grid_selector = "#grid-table";
  7. var pager_selector = "#grid-pager";
  8. var auths="";
  9. $.ajax({
  10. url: $path_base+'/auths/getalldatetotext',
  11. async: false,
  12. cache: false,
  13. dataType: "text",
  14. success: function(data) {
  15. if (data != null) {
  16. auths=data;
  17. }
  18. }
  19. });
  20. jQuery(grid_selector).jqGrid({
  21. //direction: "rtl",
  22. url: $path_base+"/roles/getdatetojson",
  23. mtype: 'post',
  24. datatype: "json",
  25. height: "auto",
  26. colNames:[' ','名称','ID'],
  27. colModel:[
  28. {name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false,
  29. formatter:'actions',
  30. formatoptions:{
  31. keys:true,
  32. //editformbutton:true, editOptions:{recreateForm: true, beforeShowForm:beforeEditCallback},
  33. delOptions:{recreateForm: true, beforeShowForm:beforeDeleteCallback}
  34. }
  35. },
  36. {name:'name',index:'name', width:60, editable: true, sortable:false, sorttype:"string",editrules:{required:true}},
  37. {name:'id',index:'id', hidden:true, editable: true, sortable:false, key:true}
  38. ],
  39. viewrecords : true,
  40. rowNum:10,
  41. rowList:[10,15,20],
  42. pager : pager_selector,
  43. altRows: true,
  44. //toppager: true,
  45. // multiselect: true,
  46. //multikey: "ctrlKey",
  47. multiboxonly: true,
  48. loadComplete : function() {
  49. var table = this;
  50. setTimeout(function(){
  51. styleCheckbox(table);
  52. updateActionIcons(table);
  53. updatePagerIcons(table);
  54. enableTooltips(table);
  55. }, 0);
  56. },
  57. editurl: $path_base+"/roles/editfromgrid",//nothing is saved
  58. // caption: "角色信息",
  59. jsonReader:{root:"list",
  60. page:"page",
  61. total:"totalPage",
  62. records:"totalRecords",
  63. repeatitems : false
  64. },
  65. autowidth: true,
  66. subGrid: true,
  67. subGridOptions:{plusicon: "icon-plus blue",
  68. minusicon: "icon-minus blue",
  69. openicon: "icon-chevron-right center orange",
  70. },
  71. subGridRowExpanded: function(subgrid_id, row_id) {
  72. var subgrid_table_id, pager_id;
  73. subgrid_table_id = subgrid_id+"_t";
  74. pager_id = "p_"+subgrid_table_id;
  75. $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
  76. jQuery("#"+subgrid_table_id).jqGrid({
  77. url: $path_base+"/roleAuths/getdatetojson?rowid="+row_id,
  78. mtype: 'post',
  79. datatype: "json",
  80. editurl: $path_base+"/roleAuths/editfromgrid?roleId="+row_id,
  81. colNames: [' ','权限','ID'],
  82. colModel: [
  83. {name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false,
  84. formatter:'actions',
  85. formatoptions:{
  86. keys:true,
  87. editbutton:false, editformbutton:false, editOptions:{recreateForm: false, beforeShowForm:beforeEditCallback},
  88. delbutton:true, delOptions:{recreateForm: true, beforeShowForm:beforeDeleteCallback}
  89. }
  90. },
  91. {name:"authid",index:"authid",width:180, sortable:false,
  92. editable: true, edittype: 'select', formatter: 'select',editrules:{required:true},
  93. editoptions: {
  94. value: auths
  95. }
  96. },
  97. {name:'id',index:'id', hidden:true, editable: true, sortable:false, key:true}
  98. ],
  99. loadComplete : function() {
  100. var table = this;
  101. setTimeout(function(){
  102. styleCheckbox(table);
  103. updateActionIcons(table);
  104. updatePagerIcons(table);
  105. enableTooltips(table);
  106. }, 0);
  107. },
  108. jsonReader:{root:"list",
  109. page:"page",
  110. total:"totalPage",
  111. records:"totalRecords",
  112. repeatitems : false
  113. },
  114. rowNum:20,
  115. pager: pager_id,
  116. autowidth: true,
  117. height: "auto"
  118. });
  119. jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,
  120. { //navbar options
  121. edit: false,
  122. editicon : 'icon-pencil blue',
  123. add: true,
  124. addicon : 'icon-plus-sign purple',
  125. del: false,
  126. delicon : 'icon-trash red',
  127. search: false,
  128. searchicon : 'icon-search orange',
  129. refresh: true,
  130. refreshicon : 'icon-refresh green',
  131. view: false,
  132. viewicon : 'icon-zoom-in grey',
  133. },
  134. {
  135. //edit record form
  136. closeAfterEdit: true,
  137. recreateForm: true,
  138. beforeShowForm : function(e) {
  139. var form = $(e[0]);
  140. form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  141. style_edit_form(form);
  142. }
  143. },
  144. {
  145. //new record form
  146. closeAfterAdd: true,
  147. recreateForm: true,
  148. viewPagerButtons: false,
  149. beforeShowForm : function(e) {
  150. var form = $(e[0]);
  151. form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  152. style_edit_form(form);
  153. var roles = $.ajax({ type: "POST",
  154. url: $path_base+'/auths/getselectdatetotext',
  155. async: false,
  156. cache: false,
  157. dataType: "text",
  158. data:{
  159. rowid:row_id // 传入值,到后台获取json
  160. },
  161. success: function(data) {
  162. }
  163. }).responseText;
  164. var rolename = $("select#authid");// 获取下面下拉框unit对象
  165. rolename.html(roles);// 然后绑定下拉框
  166. }
  167. },
  168. {
  169. //delete record form
  170. recreateForm: true,
  171. beforeShowForm : function(e) {
  172. var form = $(e[0]);
  173. if(form.data('styled')) return false;
  174. form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  175. style_delete_form(form);
  176. form.data('styled', true);
  177. },
  178. onClick : function(e) {
  179. alert(1);
  180. }
  181. },
  182. {
  183. //search form
  184. recreateForm: true,
  185. afterShowSearch: function(e){
  186. var form = $(e[0]);
  187. form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
  188. style_search_form(form);
  189. },
  190. afterRedraw: function(){
  191. style_search_filters($(this));
  192. }
  193. ,
  194. multipleSearch: true,
  195. /**
  196. multipleGroup:true,
  197. showQuery: true
  198. */
  199. },
  200. {
  201. //view record form
  202. recreateForm: true,
  203. beforeShowForm: function(e){
  204. var form = $(e[0]);
  205. form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
  206. }
  207. }
  208. )
  209. }
  210. });
  211. //enable search/filter toolbar
  212. //jQuery(grid_selector).jqGrid('filterToolbar',{defaultSearch:true,stringResult:true})
  213. //switch element when editing inline
  214. function aceSwitch( cellvalue, options, cell ) {
  215. setTimeout(function(){
  216. $(cell) .find('input[type=checkbox]')
  217. .wrap('<label class="inline" />')
  218. .addClass('ace ace-switch ace-switch-5')
  219. .after('<span class="lbl"></span>');
  220. }, 0);
  221. }
  222. //enable datepicker
  223. function pickDate( cellvalue, options, cell ) {
  224. setTimeout(function(){
  225. $(cell) .find('input[type=text]')
  226. .datepicker({format:'yyyy-mm-dd' , autoclose:true});
  227. }, 0);
  228. }
  229. //navButtons
  230. jQuery(grid_selector).jqGrid('navGrid',pager_selector,
  231. { //navbar options
  232. edit: false,
  233. editicon : 'icon-pencil blue',
  234. add: true,
  235. addicon : 'icon-plus-sign purple',
  236. del: false,
  237. delicon : 'icon-trash red',
  238. search: false,
  239. searchicon : 'icon-search orange',
  240. refresh: true,
  241. refreshicon : 'icon-refresh green',
  242. view: false,
  243. viewicon : 'icon-zoom-in grey'
  244. },
  245. {
  246. //edit record form
  247. closeAfterEdit: true,
  248. recreateForm: true,
  249. beforeShowForm : function(e) {
  250. var form = $(e[0]);
  251. form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  252. style_edit_form(form);
  253. }
  254. },
  255. {
  256. //new record form
  257. closeAfterAdd: true,
  258. recreateForm: true,
  259. viewPagerButtons: false,
  260. beforeShowForm : function(e) {
  261. var form = $(e[0]);
  262. form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  263. style_edit_form(form);
  264. }
  265. },
  266. {
  267. //delete record form
  268. recreateForm: true,
  269. beforeShowForm : function(e) {
  270. var form = $(e[0]);
  271. if(form.data('styled')) return false;
  272. form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  273. style_delete_form(form);
  274. form.data('styled', true);
  275. },
  276. onClick : function(e) {
  277. alert(1);
  278. }
  279. },
  280. {
  281. //search form
  282. recreateForm: true,
  283. afterShowSearch: function(e){
  284. var form = $(e[0]);
  285. form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
  286. style_search_form(form);
  287. },
  288. afterRedraw: function(){
  289. style_search_filters($(this));
  290. }
  291. ,
  292. multipleSearch: true,
  293. /**
  294. multipleGroup:true,
  295. showQuery: true
  296. */
  297. },
  298. {
  299. //view record form
  300. recreateForm: true,
  301. beforeShowForm: function(e){
  302. var form = $(e[0]);
  303. form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
  304. }
  305. }
  306. )
  307. function style_edit_form(form) {
  308. //enable datepicker on "sdate" field and switches for "stock" field
  309. form.find('input[name=sdate]').datepicker({format:'yyyy-mm-dd' , autoclose:true})
  310. .end().find('input[name=stock]')
  311. .addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');
  312. //update buttons classes
  313. var buttons = form.next().find('.EditButton .fm-button');
  314. buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
  315. buttons.eq(0).addClass('btn-primary').prepend('<i class="icon-ok"></i>');
  316. buttons.eq(1).prepend('<i class="icon-remove"></i>')
  317. buttons = form.next().find('.navButton a');
  318. buttons.find('.ui-icon').remove();
  319. buttons.eq(0).append('<i class="icon-chevron-left"></i>');
  320. buttons.eq(1).append('<i class="icon-chevron-right"></i>');
  321. }
  322. function style_delete_form(form) {
  323. var buttons = form.next().find('.EditButton .fm-button');
  324. buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
  325. buttons.eq(0).addClass('btn-danger').prepend('<i class="icon-trash"></i>');
  326. buttons.eq(1).prepend('<i class="icon-remove"></i>')
  327. }
  328. function style_search_filters(form) {
  329. form.find('.delete-rule').val('X');
  330. form.find('.add-rule').addClass('btn btn-xs btn-primary');
  331. form.find('.add-group').addClass('btn btn-xs btn-success');
  332. form.find('.delete-group').addClass('btn btn-xs btn-danger');
  333. }
  334. function style_search_form(form) {
  335. var dialog = form.closest('.ui-jqdialog');
  336. var buttons = dialog.find('.EditTable')
  337. buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'icon-retweet');
  338. buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'icon-comment-alt');
  339. buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'icon-search');
  340. }
  341. function beforeDeleteCallback(e) {
  342. var form = $(e[0]);
  343. if(form.data('styled')) return false;
  344. form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  345. style_delete_form(form);
  346. form.data('styled', true);
  347. }
  348. function beforeEditCallback(e) {
  349. var form = $(e[0]);
  350. form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
  351. style_edit_form(form);
  352. }
  353. //it causes some flicker when reloading or navigating grid
  354. //it may be possible to have some custom formatter to do this as the grid is being created to prevent this
  355. //or go back to default browser checkbox styles for the grid
  356. function styleCheckbox(table) {
  357. /**
  358. $(table).find('input:checkbox').addClass('ace')
  359. .wrap('<label />')
  360. .after('<span class="lbl align-top" />')
  361. $('.ui-jqgrid-labels th[id*="_cb"]:first-child')
  362. .find('input.cbox[type=checkbox]').addClass('ace')
  363. .wrap('<label />').after('<span class="lbl align-top" />');
  364. */
  365. }
  366. //unlike navButtons icons, action icons in rows seem to be hard-coded
  367. //you can change them like this in here if you want
  368. function updateActionIcons(table) {
  369. /**
  370. var replacement =
  371. {
  372. 'ui-icon-pencil' : 'icon-pencil blue',
  373. 'ui-icon-trash' : 'icon-trash red',
  374. 'ui-icon-disk' : 'icon-ok green',
  375. 'ui-icon-cancel' : 'icon-remove red'
  376. };
  377. $(table).find('.ui-pg-div span.ui-icon').each(function(){
  378. var icon = $(this);
  379. var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
  380. if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
  381. })
  382. */
  383. }
  384. //replace icons with FontAwesome icons like above
  385. function updatePagerIcons(table) {
  386. var replacement =
  387. {
  388. 'ui-icon-seek-first' : 'icon-double-angle-left bigger-140',
  389. 'ui-icon-seek-prev' : 'icon-angle-left bigger-140',
  390. 'ui-icon-seek-next' : 'icon-angle-right bigger-140',
  391. 'ui-icon-seek-end' : 'icon-double-angle-right bigger-140'
  392. };
  393. $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function(){
  394. var icon = $(this);
  395. var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
  396. if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
  397. })
  398. }
  399. function enableTooltips(table) {
  400. $('.navtable .ui-pg-button').tooltip({container:'body'});
  401. $(table).find('.ui-pg-div').tooltip({container:'body'});
  402. }
  403. //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');
  404. });
  405. </script>
  406. <%};%>
  407. <%layout("/ace/commonPage/_layout.html", {nav: "角色管理",meunsel:"roles",jsParam:jsParam,cssParam:cssParam}) {%>
  408. <!-- PAGE CONTENT BEGINS -->
  409. <table id="grid-table" class="table table-striped table-bordered table-hover"></table>
  410. <div id="grid-pager"></div>
  411. <script type="text/javascript">
  412. var $path_base = "${contextPath}";//this will be used in gritter alerts containing images
  413. </script>
  414. <!-- PAGE CONTENT ENDS -->
  415. <%}%>