role.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'jstree'], function ($, undefined, Backend, Form, Table) {
  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 : 'qingdong/department/role/index',
  24. add_url : 'qingdong/department/role/add',
  25. edit_url : 'qingdong/department/role/edit',
  26. del_url : 'qingdong/department/role/del',
  27. table : 'role'
  28. }
  29. });
  30. var table = $("#table");
  31. // 初始化表格
  32. table.bootstrapTable({
  33. url : $.fn.bootstrapTable.defaults.extend.index_url,
  34. sortName : 'id',
  35. columns : [
  36. [
  37. {checkbox: true},
  38. {field : 'name', title : __('角色名称'),formatter:function (value, row, index) {
  39. return value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
  40. }
  41. },
  42. {field: 'createtime', title: __('创建时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  43. {
  44. field : 'operate',
  45. title : __('Operate'),
  46. table : table,
  47. events : Table.api.events.operate,
  48. formatter : Table.api.formatter.operate,
  49. buttons:[
  50. {
  51. name: '权限配置',
  52. text: __('权限配置'),
  53. classname: 'btn-xs btn-dialog',
  54. url: 'qingdong/department/role/rule',
  55. },
  56. ]
  57. }
  58. ]
  59. ],
  60. search:false,
  61. //启用普通表单搜索
  62. commonSearch : false,
  63. searchFormVisible : false,
  64. onLoadSuccess:function(){
  65. // 这里就是数据渲染结束后的回调函数
  66. $('.btn-delone').html('删除').removeClass('btn-danger').removeClass('btn');
  67. $('.btn-editone').html('编辑').removeClass('btn-success')
  68. .removeClass('btn').data("area",["300px","200px"]);
  69. }
  70. });
  71. // 为表格绑定事件
  72. Table.api.bindevent(table);
  73. },
  74. add : function () {
  75. Controller.api.bindevent();
  76. },
  77. edit : function () {
  78. Controller.api.bindevent();
  79. },
  80. rule:function(){
  81. //渲染权限节点树
  82. var ids=$('#ids').val()
  83. console.log(ids)
  84. Controller.api.set_roletree(ids);
  85. },
  86. api : {
  87. bindevent : function () {
  88. Form.api.bindevent($("form[role=form]"));
  89. },
  90. formatter: {
  91. title: function (value, row, index) {
  92. value = value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
  93. return value;
  94. },
  95. },
  96. rendertree: function (content) {
  97. $("#treeview")
  98. .on('redraw.jstree', function (e) {
  99. $(".layer-footer").attr("domrefresh", Math.random());
  100. })
  101. .jstree({
  102. "themes": {"stripes": true},
  103. "checkbox": {
  104. "keep_selected_style": false,
  105. },
  106. "types": {
  107. "root": {
  108. "icon": false,
  109. },
  110. "menu": {
  111. "icon": false,
  112. },
  113. "file": {
  114. "icon": false,
  115. }
  116. },
  117. "plugins": ["checkbox", "types"],
  118. "core": {
  119. 'check_callback': true,
  120. 'dblclick_toggle': false,
  121. "data": content
  122. }
  123. });
  124. },
  125. set_roletree:function(ids){
  126. $.post("qingdong/department/role/roletree", {ids:ids},function (ret){
  127. if (ret.hasOwnProperty("code")) {
  128. var data = ret.hasOwnProperty("data") && ret.data != "" ? ret.data : "";
  129. if (ret.code === 1) {
  130. var roletree=data;
  131. //销毁已有的节点树
  132. $("#treeview").jstree("destroy");
  133. Controller.api.rendertree(roletree);
  134. } else {
  135. Backend.api.toastr.error(ret.msg);
  136. }
  137. }
  138. },'json');
  139. Form.api.bindevent($("form[role=form]"), null, null, function () {
  140. var array=new Array();
  141. if ($("#treeview").length > 0) {
  142. var r = $("#treeview").jstree("get_selected");
  143. if(r.length != 0){
  144. array.push(r.join(','));
  145. }
  146. }
  147. $("input[name='row[rules]']").val(array.join(','));
  148. return true;
  149. });
  150. },
  151. }
  152. };
  153. return Controller;
  154. });