media.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. //去掉特殊字符和转义字符
  3. function excludeSpecial(s) {
  4. s = s.replace(/[\\\/\b\f\n\r\t\'\[\]\@\#\$\%\^\&\*\{\}\:\"\L\<\>\?]/g,'');
  5. return s;
  6. };
  7. $(document).on('keyup','#c-description',function () {
  8. var descrp = $('#c-description').val();
  9. $('#c-description').val(excludeSpecial(descrp));
  10. });
  11. var Controller = {
  12. index: function () {
  13. // 初始化表格参数配置
  14. Table.api.init({
  15. extend: {
  16. index_url: 'booklist/media/index',
  17. add_url: 'booklist/media/add/from/'+Config.from_window,
  18. edit_url: 'booklist/media/edit',
  19. del_url: 'booklist/media/del',
  20. multi_url: 'booklist/media/multi',
  21. table: 'book_list_media',
  22. }
  23. });
  24. var table = $("#table");
  25. // 初始化表格
  26. table.bootstrapTable({
  27. url: $.fn.bootstrapTable.defaults.extend.index_url,
  28. pk: 'id',
  29. sortName: 'id',
  30. search:false,
  31. commonSearch: false,
  32. searchFormVisible: false,
  33. columns: [
  34. [
  35. {checkbox: true},
  36. {field: 'id', title: __('Id')},
  37. {field: 'title', title: __('Title')},
  38. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image,},
  39. {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden'),"deleted":__('status deleted')}},
  40. {field: 'status_text', title: __('Status'), operate:false},
  41. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  42. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  43. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  44. ]
  45. ]
  46. });
  47. // 为表格绑定事件
  48. Table.api.bindevent(table);
  49. },
  50. add: function () {
  51. Controller.api.bindevent();
  52. },
  53. edit: function () {
  54. Controller.api.bindevent();
  55. },
  56. select: function () {
  57. // 初始化表格参数配置
  58. Table.api.init({
  59. extend: {
  60. index_url: 'booklist/media/select'
  61. },
  62. showColumns: false,
  63. showToggle: false,
  64. showExport: false,
  65. searchFormVisible: false,
  66. search: false
  67. });
  68. var table = $("#table");
  69. // 初始化表格
  70. table.bootstrapTable({
  71. url: $.fn.bootstrapTable.defaults.extend.index_url,
  72. pk: 'id',
  73. sortName: 'id desc',
  74. sortOrder: '',
  75. columns: [
  76. [
  77. {checkbox: true},
  78. {field: 'id', title: __('Id'), operate:false},
  79. {field: 'image', title: __('Image'), visible: false, operate:false},
  80. {field: 'book_id', title: __('Bookid'), visible: false, operate:false},
  81. {field: 'book_name', title: __('Bookname'),visible: false, operate:false},
  82. {field: 'description', title: __('Description'),visible: false, operate:false},
  83. {field: 'title', title: __('Title'), operate: 'LIKE %...%'},
  84. {
  85. field: 'operate', title: __('Operate'), events: {
  86. 'click .btn-chooseone': function (e, value, row, index) {
  87. Fast.api.close([row]);
  88. },
  89. }, formatter: function () {
  90. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  91. }
  92. }
  93. ]
  94. ]
  95. });
  96. // 为表格绑定事件
  97. Table.api.bindevent(table);
  98. //获取选中数据
  99. $(document).on('click', "#btn-chooseone", function () {
  100. Fast.api.close(table.bootstrapTable('getSelections'));
  101. });
  102. },
  103. api: {
  104. bindevent: function () {
  105. if (Config.from_window != 'list') {
  106. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  107. Fast.api.close(data);
  108. return false;
  109. });
  110. } else {
  111. Form.api.bindevent($("form[role=form]"));
  112. }
  113. var refreshkey = function (data) {
  114. Layer.closeAll();
  115. $('#c-book_id').val(data[0].id);
  116. $('#c-book_name').val(data[0].name);
  117. $('#c-book_name').trigger('change');
  118. $('#c-description').val(excludeSpecial(data[0].description));
  119. };
  120. $(document).on('click', "#select-resources", function () {
  121. var block_id = Config.block_id;
  122. parent.Backend.api.open($(this).attr("href") + "?action=blockresoure&block_id=" + block_id, __('Select'), {callback: refreshkey});
  123. return false;
  124. });
  125. }
  126. }
  127. };
  128. return Controller;
  129. });