userlevel.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'config/userlevel/index' + location.search,
  8. add_url: 'config/userlevel/add',
  9. edit_url: 'config/userlevel/edit',
  10. del_url: 'config/userlevel/del',
  11. multi_url: 'config/userlevel/multi',
  12. table: 'user_level',
  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. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'name', title: __('Name')},
  26. {field: 'icon', title: __('Icon'), formatter: Controller.api.formatter.icon},
  27. {field: 'status', title: __('Status'), formatter: Table.api.formatter.toggle},
  28. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  29. ]
  30. ]
  31. });
  32. // 为表格绑定事件
  33. Table.api.bindevent(table);
  34. },
  35. add: function () {
  36. Controller.api.bindevent();
  37. },
  38. edit: function () {
  39. Controller.api.bindevent();
  40. },
  41. api: {
  42. formatter: {
  43. title: function (value, row, index) {
  44. return !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value;
  45. },
  46. name: function (value, row, index) {
  47. return !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value;
  48. },
  49. icon: function (value, row, index) {
  50. return '<span class="' + (!row.ismenu || row.status == 'hidden' ? 'text-muted' : '') + '"><i class="' + value + '"></i></span>';
  51. },
  52. subnode: function (value, row, index) {
  53. return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="btn btn-xs '
  54. + (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
  55. }
  56. },
  57. bindevent: function () {
  58. var iconlist = [];
  59. var iconfunc = function () {
  60. Layer.open({
  61. type: 1,
  62. area: ['99%', '98%'], //宽高
  63. content: Template('chooseicontpl', {iconlist: iconlist})
  64. });
  65. };
  66. Form.api.bindevent($("form[role=form]"), function (data) {
  67. Fast.api.refreshmenu();
  68. });
  69. $(document).on('click', ".btn-search-icon", function () {
  70. if (iconlist.length == 0) {
  71. $.get(Config.site.cdnurl + "/assets/libs/font-awesome/less/variables.less", function (ret) {
  72. var exp = /fa-var-(.*):/ig;
  73. var result;
  74. while ((result = exp.exec(ret)) != null) {
  75. iconlist.push(result[1]);
  76. }
  77. iconfunc();
  78. });
  79. } else {
  80. iconfunc();
  81. }
  82. });
  83. $(document).on('click', '#chooseicon ul li', function () {
  84. $("input[name='row[icon]']").val('fa fa-' + $(this).data("font"));
  85. Layer.closeAll();
  86. });
  87. $(document).on('keyup', 'input.js-icon-search', function () {
  88. $("#chooseicon ul li").show();
  89. if ($(this).val() != '') {
  90. $("#chooseicon ul li:not([data-font*='" + $(this).val() + "'])").hide();
  91. }
  92. });
  93. }
  94. }
  95. };
  96. return Controller;
  97. });