casescategory.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'wwh/casescategory/index',
  8. add_url: 'wwh/casescategory/add',
  9. edit_url: 'wwh/casescategory/edit',
  10. del_url: 'wwh/casescategory/del',
  11. multi_url: 'wwh/casescategory/multi',
  12. table: 'wwh_casescategory',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. escape: false,
  22. columns: [
  23. [
  24. { checkbox: true },
  25. {
  26. field: 'id',
  27. title: __('Id'),
  28. },
  29. { field: 'name', title: __('Name'), align: 'left' },
  30. {
  31. field: 'id',
  32. title: '<a href="javascript:;" class="btn btn-success btn-xs btn-toggle"><i class="fa fa-chevron-up"></i></a>',
  33. operate: false,
  34. formatter: Controller.api.formatter.subnode
  35. },
  36. { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
  37. ]
  38. ],
  39. pagination: false,
  40. search: false,
  41. commonSearch: false,
  42. });
  43. //当内容渲染完成后
  44. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  45. //默认隐藏所有子节点
  46. //$("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").hide();
  47. //$(".btn-node-sub.disabled[data-pid!=0]").closest("tr").hide();
  48. //显示隐藏子节点
  49. $(".btn-node-sub").off("click").on("click", function (e) {
  50. var status = $(this).data("shown") || $("a.btn[data-pid='" + $(this).data("id") + "']:visible").size() > 0 ? true : false;
  51. $("a.btn[data-pid='" + $(this).data("id") + "']").each(function () {
  52. $(this).closest("tr").toggle(!status);
  53. if (!$(this).hasClass("disabled")) {
  54. $(this).trigger("click");
  55. }
  56. });
  57. $(this).data("shown", !status);
  58. return false;
  59. });
  60. });
  61. //展开隐藏一级
  62. $(document.body).on("click", ".btn-toggle", function (e) {
  63. $("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
  64. var that = this;
  65. var show = $("i", that).hasClass("fa-chevron-down");
  66. $("i", that).toggleClass("fa-chevron-down", !show);
  67. $("i", that).toggleClass("fa-chevron-up", show);
  68. $("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").toggle(show);
  69. $(".btn-node-sub[data-pid=0]").data("shown", show);
  70. });
  71. //展开隐藏全部
  72. $(document.body).on("click", ".btn-toggle-all", function (e) {
  73. var that = this;
  74. var show = $("i", that).hasClass("fa-plus");
  75. $("i", that).toggleClass("fa-plus", !show);
  76. $("i", that).toggleClass("fa-minus", show);
  77. $(".btn-node-sub.disabled[data-pid!=0]").closest("tr").toggle(show);
  78. $(".btn-node-sub[data-pid!=0]").data("shown", show);
  79. });
  80. // 为表格绑定事件
  81. Table.api.bindevent(table);
  82. },
  83. add: function () {
  84. Controller.api.bindevent();
  85. },
  86. edit: function () {
  87. Controller.api.bindevent();
  88. },
  89. api: {
  90. formatter: {
  91. subnode: function (value, row, index) {
  92. return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="btn btn-xs '
  93. + (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
  94. }
  95. },
  96. bindevent: function () {
  97. Form.api.bindevent($("form[role=form]"));
  98. },
  99. }
  100. };
  101. return Controller;
  102. });