group.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function ($, undefined, Backend, Table, Form, undefined) {
  2. //读取选中的条目
  3. $.jstree.core.prototype.get_all_checked = function (full) {
  4. var obj = this.get_selected(), i, j;
  5. for (i = 0, j = obj.length; i < j; i++) {
  6. obj = obj.concat(this.get_node(obj[i]).parents);
  7. }
  8. obj = $.grep(obj, function (v, i, a) {
  9. return v != '#';
  10. });
  11. obj = obj.filter(function (itm, i, a) {
  12. return i == a.indexOf(itm);
  13. });
  14. return full ? $.map(obj, $.proxy(function (i) {
  15. return this.get_node(i);
  16. }, this)) : obj;
  17. };
  18. var Controller = {
  19. index: function () {
  20. // 初始化表格参数配置
  21. Table.api.init({
  22. extend: {
  23. index_url: 'user/group/index',
  24. add_url: 'user/group/add',
  25. edit_url: 'user/group/edit',
  26. del_url: 'user/group/del',
  27. multi_url: 'user/group/multi',
  28. table: 'user_group',
  29. }
  30. });
  31. var table = $("#table");
  32. // 初始化表格
  33. table.bootstrapTable({
  34. url: $.fn.bootstrapTable.defaults.extend.index_url,
  35. pk: 'id',
  36. sortName: 'id',
  37. columns: [
  38. [
  39. {checkbox: true},
  40. {field: 'id', title: __('Id')},
  41. {field: 'name', title: __('Name')},
  42. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  43. {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  44. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  45. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  46. ]
  47. ]
  48. });
  49. // 为表格绑定事件
  50. Table.api.bindevent(table);
  51. },
  52. add: function () {
  53. Controller.api.bindevent();
  54. },
  55. edit: function () {
  56. Controller.api.bindevent();
  57. },
  58. api: {
  59. bindevent: function () {
  60. Form.api.bindevent($("form[role=form]"), null, null, function () {
  61. if ($("#treeview").length > 0) {
  62. var r = $("#treeview").jstree("get_all_checked");
  63. $("input[name='row[rules]']").val(r.join(','));
  64. }
  65. return true;
  66. });
  67. //渲染权限节点树
  68. //销毁已有的节点树
  69. $("#treeview").jstree("destroy");
  70. Controller.api.rendertree(nodeData);
  71. //全选和展开
  72. $(document).on("click", "#checkall", function () {
  73. $("#treeview").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  74. });
  75. $(document).on("click", "#expandall", function () {
  76. $("#treeview").jstree($(this).prop("checked") ? "open_all" : "close_all");
  77. });
  78. $("select[name='row[pid]']").trigger("change");
  79. },
  80. rendertree: function (content) {
  81. $("#treeview")
  82. .on('redraw.jstree', function (e) {
  83. $(".layer-footer").attr("domrefresh", Math.random());
  84. })
  85. .jstree({
  86. "themes": {"stripes": true},
  87. "checkbox": {
  88. "keep_selected_style": false,
  89. },
  90. "types": {
  91. "root": {
  92. "icon": "fa fa-folder-open",
  93. },
  94. "menu": {
  95. "icon": "fa fa-folder-open",
  96. },
  97. "file": {
  98. "icon": "fa fa-file-o",
  99. }
  100. },
  101. "plugins": ["checkbox", "types"],
  102. "core": {
  103. 'check_callback': true,
  104. "data": content
  105. }
  106. });
  107. }
  108. }
  109. };
  110. return Controller;
  111. });