customqrcode.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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: 'customqrcode/index',
  8. add_url: 'customqrcode/add',
  9. edit_url: 'customqrcode/edit',
  10. del_url: 'customqrcode/del',
  11. multi_url: 'customqrcode/multi',
  12. table: 'custom_qrcode',
  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: 'title', title: __('Title')},
  25. {field: 'url', title: __('Url'),operate: false, formatter: Table.api.formatter.url},
  26. {field: 'uv', title: __('UV'),operate: false},
  27. {field: 'type', title: __('type'),searchList: {"0":__('Type0'),"1":__('Type1'),"2":__('Type2')},formatter: Controller.api.formatter.type_text},
  28. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
  29. var that = $.extend({}, this);
  30. var table = $(that.table).clone(true);
  31. if (row.type == 2)
  32. $(table).data("operate-edit", null);
  33. that.table = table;
  34. return Table.api.formatter.operate.call(that, value, row, index);
  35. }}
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. },
  42. add: function () {
  43. Controller.api.bindevent();
  44. },
  45. edit: function () {
  46. Controller.api.bindevent();
  47. },
  48. api: {
  49. bindevent: function () {
  50. Form.api.bindevent($("form[role=form]"));
  51. var refreshkey = function (data) {
  52. $("input[name='row[eventkey]']").val(data.eventkey).trigger("change");
  53. Layer.closeAll();
  54. var keytitle = data.title;
  55. var cont = $(".clickbox .create-click:first");
  56. $(".keytitle", cont).remove();
  57. if (keytitle) {
  58. cont.append('<div class="keytitle">' + __('Event key') + ':' + keytitle + '</div>');
  59. }
  60. };
  61. $(document).on('click', "#select-resources", function () {
  62. var key = $("input[name='row[eventkey]']").val();
  63. parent.Backend.api.open($(this).attr("href") + "?key=" + key, __('Select'), {callback: refreshkey});
  64. return false;
  65. });
  66. $(document).on('click', "#add-resources", function () {
  67. parent.Backend.api.open($(this).attr("href") + "?key=", __('Add'), {callback: refreshkey});
  68. return false;
  69. });
  70. },
  71. formatter:{
  72. type_text: function(value,row,index){return row.type_text;},
  73. }
  74. }
  75. };
  76. return Controller;
  77. });