postbackchannel.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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: 'postbackchannel/index?rule_id=' + Config.rule_id + '&action=' + Config.action,
  8. table: 'admin',
  9. },
  10. search: false,
  11. });
  12. var table = $("#table");
  13. // 初始化表格
  14. table.bootstrapTable({
  15. url: $.fn.bootstrapTable.defaults.extend.index_url,
  16. pk: 'id',
  17. sortName: 'id',
  18. columns:[
  19. Controller.api.showFilterColumns(table)
  20. ]
  21. });
  22. // 为表格绑定事件
  23. Table.api.bindevent(table);
  24. $(document).delegate('.batch_relation', 'click', function () {
  25. var ids = [];
  26. var action = $(this).data('action');
  27. if ($(this).data('channel_id')) {
  28. ids.push($(this).data('channel_id'));
  29. } else {
  30. ids = Table.api.selectedids(table);
  31. }
  32. Controller.api.batchrelation(ids, action, table)
  33. });
  34. },
  35. api: {
  36. showFilterColumns:function(table){
  37. cols = [
  38. {checkbox: true},
  39. {field: 'id', title: __('Id')},
  40. {field: 'username', title: __('Username'), operate:'LIKE'},
  41. {field: 'nickname', title: __('Nickname'), operate:'LIKE'},
  42. {field: 'operate', title: __('Operate'), operate:false,formatter: function (value, row, table) {
  43. if (Config.action == 'relation') {
  44. return "<a href='javascript:;' class='batch_relation' data-action='add' data-channel_id='"+row.id+"'>关联</a>";
  45. } else {
  46. return "<a href='javascript:;' class='batch_relation' data-action='delete' data-channel_id='"+row.id+"'>删除</a>";
  47. }
  48. }}
  49. ];
  50. if (Config.channels == '*') {
  51. cols.pop();
  52. }
  53. return cols;
  54. },
  55. bindevent: function () {
  56. Form.api.bindevent($("form[role=form]"));
  57. },
  58. batchrelation: function (ids, action, table) {
  59. if (ids.length) {
  60. var msg = '';
  61. if (ids[0] == '-1') {
  62. if (!$(table).find('.no-records-found').length) {
  63. if (action == 'add') {
  64. msg = '关联全部渠道?';
  65. } else {
  66. msg = '删除全部渠道及推广链接?';
  67. }
  68. } else {
  69. Layer.alert('渠道为空,操作取消');
  70. return;
  71. }
  72. } else {
  73. msg = __('已选中渠道个数:%s', ids.length);
  74. }
  75. Layer.confirm(
  76. msg,
  77. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  78. function (index) {
  79. var url = 'postbackchannel/batch_relation';
  80. var options = {url: url, data: { channel_ids: ids.join(","), rule_id: Config.rule_id, action: action}};
  81. Fast.api.ajax(options, function (data, ret) {
  82. Layer.msg('处理成功!');
  83. table.bootstrapTable('refresh');
  84. }, function (data, ret) {
  85. });
  86. Layer.close(index);
  87. }
  88. );
  89. }
  90. }
  91. }
  92. };
  93. return Controller;
  94. });