traincate.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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: 'traincate/index' + location.search,
  8. add_url: 'traincate/add',
  9. edit_url: 'traincate/edit',
  10. del_url: 'traincate/del',
  11. multi_url: 'traincate/multi',
  12. import_url: 'traincate/import',
  13. table: 'train_cate',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  27. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  28. ]
  29. ]
  30. });
  31. // 为表格绑定事件
  32. Table.api.bindevent(table);
  33. },
  34. recyclebin: function () {
  35. // 初始化表格参数配置
  36. Table.api.init({
  37. extend: {
  38. 'dragsort_url': ''
  39. }
  40. });
  41. var table = $("#table");
  42. // 初始化表格
  43. table.bootstrapTable({
  44. url: 'traincate/recyclebin' + location.search,
  45. pk: 'id',
  46. sortName: 'id',
  47. columns: [
  48. [
  49. {checkbox: true},
  50. {field: 'id', title: __('Id')},
  51. {field: 'name', title: __('Name'), align: 'left'},
  52. {
  53. field: 'deletetime',
  54. title: __('Deletetime'),
  55. operate: 'RANGE',
  56. addclass: 'datetimerange',
  57. formatter: Table.api.formatter.datetime
  58. },
  59. {
  60. field: 'operate',
  61. width: '140px',
  62. title: __('Operate'),
  63. table: table,
  64. events: Table.api.events.operate,
  65. buttons: [
  66. {
  67. name: 'Restore',
  68. text: __('Restore'),
  69. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  70. icon: 'fa fa-rotate-left',
  71. url: 'traincate/restore',
  72. refresh: true
  73. },
  74. {
  75. name: 'Destroy',
  76. text: __('Destroy'),
  77. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  78. icon: 'fa fa-times',
  79. url: 'traincate/destroy',
  80. refresh: true
  81. }
  82. ],
  83. formatter: Table.api.formatter.operate
  84. }
  85. ]
  86. ]
  87. });
  88. // 为表格绑定事件
  89. Table.api.bindevent(table);
  90. },
  91. add: function () {
  92. Controller.api.bindevent();
  93. },
  94. edit: function () {
  95. Controller.api.bindevent();
  96. },
  97. api: {
  98. bindevent: function () {
  99. Form.api.bindevent($("form[role=form]"));
  100. }
  101. }
  102. };
  103. return Controller;
  104. });