media.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: 'booklistch/media/index',
  17. add_url: 'booklistch/media/add/from/'+Config.from_window,
  18. edit_url: 'booklistch/media/edit',
  19. del_url: 'booklistch/media/del',
  20. multi_url: 'booklistch/media/multi',
  21. table: 'book_list_media_ch',
  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. onPostBody: function () {
  47. //隐藏禁用操作按钮
  48. $.each(table.bootstrapTable("getData"), function (index, row) {
  49. if (row.self == "0") {
  50. //隐藏操作按钮
  51. $("a.btn-editone").eq(index).hide();
  52. $("a.btn-delone").eq(index).hide();
  53. }
  54. });
  55. }
  56. });
  57. // 为表格绑定事件
  58. Table.api.bindevent(table);
  59. },
  60. add: function () {
  61. Controller.api.bindevent();
  62. },
  63. edit: function () {
  64. if(Config.bnotin.indexOf(parseInt($('#c-book_id').val())) != -1){
  65. $('#c-book_id').val('');
  66. $('#c-book_name').val('');
  67. }
  68. Controller.api.bindevent();
  69. },
  70. select: function () {
  71. // 初始化表格参数配置
  72. Table.api.init({
  73. extend: {
  74. index_url: 'booklistch/media/select'
  75. },
  76. showColumns: false,
  77. showToggle: false,
  78. showExport: false,
  79. searchFormVisible: false,
  80. search: false
  81. });
  82. var table = $("#table");
  83. // 初始化表格
  84. table.bootstrapTable({
  85. url: $.fn.bootstrapTable.defaults.extend.index_url,
  86. pk: 'id',
  87. sortName: 'id desc',
  88. sortOrder: '',
  89. columns: [
  90. [
  91. {checkbox: true},
  92. {field: 'id', title: __('Id'), operate:false},
  93. {field: 'image', title: __('Image'), visible: false, operate:false},
  94. {field: 'book_id', title: __('Bookid'), visible: false, operate:false},
  95. {field: 'book_name', title: __('Bookname'),visible: false, operate:false},
  96. {field: 'description', title: __('Description'),visible: false, operate:false},
  97. {field: 'title', title: __('Title'), operate: 'LIKE %...%'},
  98. {
  99. field: 'operate', title: __('Operate'), events: {
  100. 'click .btn-chooseone': function (e, value, row, index) {
  101. Fast.api.close([row]);
  102. },
  103. }, formatter: function () {
  104. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  105. }
  106. }
  107. ]
  108. ]
  109. });
  110. // 为表格绑定事件
  111. Table.api.bindevent(table);
  112. //获取选中数据
  113. $(document).on('click', "#btn-chooseone", function () {
  114. Fast.api.close(table.bootstrapTable('getSelections'));
  115. });
  116. },
  117. api: {
  118. bindevent: function () {
  119. if (Config.from_window != 'list') {
  120. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  121. Fast.api.close(data);
  122. return false;
  123. });
  124. } else {
  125. Form.api.bindevent($("form[role=form]"));
  126. }
  127. var refreshkey = function (data) {
  128. Layer.closeAll();
  129. $('#c-book_id').val(data[0].id);
  130. $('#c-book_name').val(data[0].name);
  131. $('#c-book_name').trigger('change');
  132. $('#c-description').val(excludeSpecial(data[0].description));
  133. };
  134. $(document).on('click', "#select-resources", function () {
  135. var block_id = Config.block_id;
  136. parent.Backend.api.open($(this).data("url") + "?action=blockresoure&block_id=" + block_id, __('Select'), {callback: refreshkey});
  137. return false;
  138. });
  139. }
  140. }
  141. };
  142. return Controller;
  143. });