teaching.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. var pid = $("#page_pid").val()||0;
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'teaching/index' + location.search,
  9. add_url: 'teaching/add',
  10. edit_url: 'teaching/edit',
  11. del_url: 'teaching/del',
  12. multi_url: 'teaching/multi',
  13. import_url: '',
  14. table: 'teaching',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'type',
  23. sortOrder: 'desc',
  24. columns: [
  25. [
  26. {checkbox: true},
  27. // {field: 'id', title: __('Id')},
  28. {field: 'pid', title: __('Pid'),visible:false},
  29. {field: 'name', title: __('Name'), operate: 'LIKE',formatter: Controller.api.formatter.url,align:'left'},
  30. {field: 'url', title: __('Url'), operate: 'LIKE', formatter: Table.api.formatter.url,visible:false},
  31. {field: 'type', title: __('Type'), operate: 'LIKE',visible:false},
  32. {field: 'size', title: __('Size'), operate: 'LIKE'},
  33. {field: 'admin_name', title: __('上传人')},
  34. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible:false},
  35. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  36. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter:
  37. function(value, row, index) {
  38. var that = $.extend({}, this);
  39. var table = $(that.table).clone(true);
  40. // operate-edit编辑 perate-del删除
  41. //判断什么时候显示什么时候不显示
  42. if (row.is_me != 1) {
  43. $(table).data("operate-del", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
  44. $(table).data("operate-edit", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
  45. }
  46. that.table = table;
  47. return Table.api.formatter.operate.call(that, value, row, index);
  48. }
  49. }
  50. ]
  51. ]
  52. });
  53. $('#myModal').on('click','#J_new_folder', function () {
  54. var folder_name = $('#folder_name').val();
  55. if (folder_name){
  56. $.get('teaching/make_folder',{pid:pid,name:folder_name},function(res){
  57. if (res.code == 1){
  58. $('#myModal').modal('hide')
  59. var container = $("#table").data("bootstrap.table").$container;
  60. var options = $("#table").bootstrapTable('getOptions');
  61. $("form.form-commonsearch", container).trigger('submit');
  62. Toastr.success(res.msg);
  63. }else{
  64. Toastr.error(res.msg);
  65. }
  66. });
  67. }else{
  68. alert('请输入文件夹名称')
  69. }
  70. })
  71. var toolbar = ".toolbar";
  72. // 导入按钮事件
  73. if ($('.btn-updata', toolbar).size() > 0) {
  74. require(['upload'], function (Upload) {
  75. Upload.api.upload($('.btn-updata', toolbar), function (data, ret) {
  76. table.trigger("uncheckbox");
  77. table.bootstrapTable('refresh');
  78. if(data == 1){
  79. Toastr.success('操作成功');
  80. }else{
  81. Toastr.error('操作失败');
  82. }
  83. });
  84. });
  85. }
  86. // 为表格绑定事件
  87. Table.api.bindevent(table);
  88. table.on('post-body.bs.table',function(){
  89. $(".btn-editone").data("area",["480px","360px"]);
  90. })
  91. table.on('post-common-search.bs.table',function(){
  92. console.log('search')
  93. });
  94. },
  95. recyclebin: function () {
  96. // 初始化表格参数配置
  97. Table.api.init({
  98. extend: {
  99. 'dragsort_url': ''
  100. }
  101. });
  102. var table = $("#table");
  103. // 初始化表格
  104. table.bootstrapTable({
  105. url: 'teaching/recyclebin' + location.search,
  106. pk: 'id',
  107. sortName: 'id',
  108. columns: [
  109. [
  110. {checkbox: true},
  111. {field: 'id', title: __('Id')},
  112. {field: 'name', title: __('Name'), align: 'left'},
  113. {
  114. field: 'deletetime',
  115. title: __('Deletetime'),
  116. operate: 'RANGE',
  117. addclass: 'datetimerange',
  118. formatter: Table.api.formatter.datetime
  119. },
  120. {
  121. field: 'operate',
  122. width: '130px',
  123. title: __('Operate'),
  124. table: table,
  125. events: Table.api.events.operate,
  126. buttons: [
  127. {
  128. name: 'Restore',
  129. text: __('Restore'),
  130. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  131. icon: 'fa fa-rotate-left',
  132. url: 'teaching/restore',
  133. refresh: true
  134. },
  135. {
  136. name: 'Destroy',
  137. text: __('Destroy'),
  138. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  139. icon: 'fa fa-times',
  140. url: 'teaching/destroy',
  141. refresh: true
  142. }
  143. ],
  144. formatter: Table.api.formatter.operate
  145. }
  146. ]
  147. ]
  148. });
  149. // 为表格绑定事件
  150. Table.api.bindevent(table);
  151. },
  152. add: function () {
  153. Controller.api.bindevent();
  154. },
  155. edit: function () {
  156. Controller.api.bindevent();
  157. },
  158. api: {
  159. bindevent: function () {
  160. Form.api.bindevent($("form[role=form]"));
  161. },
  162. formatter: {//渲染的方法
  163. url: function (value, row, index) {
  164. if(row.type!='folder')return '<a href="'+ (row.url||'') +'" class="btn-ip" target="_blank" download="'+row.name+'"><i class="fa fa-file text-danger"></i> '+value + '</a>';
  165. return '<a href="?pid='+row.id+'" class=" btn-ip" data-toggle="tooltip" title="" data-field="pid" data-value="'+row.id+'" data-original-title="'+value+'" '+index+'><i style="color: #E1BF4C" class="fa fa-folder"></i> '+value+'</a>';
  166. },
  167. operate:function (value, row, index) {
  168. return '<a href="/teaching/edit/ids/'+row.id+'" class="btn btn-xs btn-success btn-editone" data-toggle="tooltip" title="" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="1" data-original-title="编辑"><i class="fa fa-pencil"></i></a> <a href="javascript:;" class="btn btn-xs btn-danger btn-delone" data-toggle="tooltip" title="删除" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="2"><i class="fa fa-trash"></i></a>'
  169. },
  170. },
  171. events: {
  172. url: {
  173. //格式为:方法名+空格+DOM元素
  174. // 'click .btn-ip': function (e, value, row, index) {
  175. // e.stopPropagation();
  176. // var container = $("#table").data("bootstrap.table").$container;
  177. // var options = $("#table").bootstrapTable('getOptions');
  178. // //这里我们手动将数据填充到表单然后提交
  179. // $("form.form-commonsearch [name='pid']", container).val(row.pid);
  180. // $("form.form-commonsearch", container).trigger('submit');
  181. // }
  182. },
  183. }
  184. }
  185. };
  186. return Controller;
  187. });