column.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. //设置弹窗宽高
  3. Fast.config.openArea = ['80%', '80%'];
  4. var Controller = {
  5. index: function () {
  6. // 初始化表格参数配置
  7. Table.api.init({
  8. extend: {
  9. index_url: 'wwh/column/index',
  10. add_url: 'wwh/column/add',
  11. edit_url: 'wwh/column/edit',
  12. del_url: 'wwh/column/del',
  13. multi_url: 'wwh/column/multi',
  14. dragsort_url: '',
  15. table: 'wwh_column',
  16. }
  17. });
  18. var table = $("#table");
  19. // 获取是否启用英文配置,显示隐藏英文字段
  20. if(Config.switch_lang == 1) {
  21. var stvisible = true;
  22. } else {
  23. var stvisible = false;
  24. }
  25. // 初始化表格
  26. table.bootstrapTable({
  27. url: $.fn.bootstrapTable.defaults.extend.index_url,
  28. pk: 'id',
  29. sortName: 'weigh',
  30. pagination: false,
  31. escape: false,
  32. fixedColumns: true,
  33. fixedRightNumber: 1,
  34. columns: [
  35. [
  36. {checkbox: true},
  37. {field: 'id', title: __('Id')},
  38. {
  39. field: 'id',
  40. title: '<a href="javascript:;" class="btn btn-success btn-xs btn-toggle"><i class="fa fa-chevron-up"></i></a>',
  41. operate: false,
  42. formatter: Controller.api.formatter.subnode
  43. },
  44. {field: 'classify', title: __('Classify'), operate: false, searchList: Config.classifyList,formatter: Table.api.formatter.flag},
  45. {field: 'name', title: __('Name'), align: 'left'},
  46. {field: 'e_name', title: __('E_name'), align: 'left',visible: stvisible},
  47. {
  48. field: 'url', title: __('Url'), formatter: function (value, row, index) {
  49. return '<a href="' + value + '" target="_blank" class="btn btn-default btn-xs"><i class="fa fa-link"></i></a>';
  50. }
  51. },
  52. {field: 'listtpl', title: __('Listtpl'), operate: 'LIKE'},
  53. {field: 'showtpl', title: __('Showtpl'), operate: 'LIKE'},
  54. {
  55. field: 'weigh',
  56. title: __('Weigh'),
  57. formatter: function (value, row, index) {
  58. return '<input type="text" class="form-control text-center text-weigh" data-id="' + row.id + '" value="' + value + '" style="width:50px;margin:0 auto;" />';
  59. },
  60. events: {
  61. "dblclick .text-weigh": function (e) {
  62. e.preventDefault();
  63. e.stopPropagation();
  64. return false;
  65. }
  66. }
  67. },
  68. {field: 'isnav', title: __('Isnav'), searchList: {"1": __('Yes'), "0": __('No')}, formatter: Table.api.formatter.toggle},
  69. {field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status},
  70. {
  71. field: 'operate',
  72. title: __('Operate'),
  73. clickToSelect: false,
  74. table: table,
  75. width: 170,
  76. events: Table.api.events.operate,
  77. formatter: Table.api.formatter.operate,
  78. buttons: [
  79. {
  80. name: 'addsub',
  81. text: '添加子栏目',
  82. classname: 'btn btn-primary btn-xs btn-dialog',
  83. icon: 'fa fa-plus',
  84. url: 'wwh/column/add/parent_id/{ids}'
  85. }
  86. ]
  87. }
  88. ]
  89. ],
  90. search: false,
  91. commonSearch: false
  92. });
  93. $(document).on("change", ".text-weigh", function () {
  94. $(this).data("params", {weigh: $(this).val()});
  95. Table.api.multi('', [$(this).data("id")], table, this);
  96. return false;
  97. });
  98. // 当内容渲染完成后
  99. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  100. // 默认隐藏所有子节点
  101. //$("a.btn[data-id][data-parent_id][data-parent_id!=0]").closest("tr").hide();
  102. //$(".btn-node-sub.disabled[data-parent_id!=0]").closest("tr").hide();
  103. // 显示隐藏子节点
  104. $(".btn-node-sub").off("click").on("click", function (e) {
  105. var status = $(this).data("shown") || $("a.btn[data-parent_id='" + $(this).data("id") + "']:visible").size() > 0 ? true : false;
  106. $("a.btn[data-parent_id='" + $(this).data("id") + "']").each(function () {
  107. $(this).closest("tr").toggle(!status);
  108. if (!$(this).hasClass("disabled")) {
  109. $(this).trigger("click");
  110. }
  111. });
  112. $(this).data("shown", !status);
  113. return false;
  114. });
  115. });
  116. // 展开隐藏一级
  117. $(document.body).on("click", ".btn-toggle", function (e) {
  118. $("a.btn[data-id][data-parent_id][data-parent_id!=0].disabled").closest("tr").hide();
  119. var that = this;
  120. var show = $("i", that).hasClass("fa-chevron-down");
  121. $("i", that).toggleClass("fa-chevron-down", !show);
  122. $("i", that).toggleClass("fa-chevron-up", show);
  123. $("a.btn[data-id][data-parent_id][data-parent_id!=0]").closest("tr").toggle(show);
  124. $(".btn-node-sub[data-parent_id=0]").data("shown", show);
  125. });
  126. // 展开隐藏全部
  127. $(document.body).on("click", ".btn-toggle-all", function (e) {
  128. var that = this;
  129. var show = $("i", that).hasClass("fa-plus");
  130. $("i", that).toggleClass("fa-plus", !show);
  131. $("i", that).toggleClass("fa-minus", show);
  132. $(".btn-node-sub.disabled[data-parent_id!=0]").closest("tr").toggle(show);
  133. $(".btn-node-sub[data-parent_id!=0]").data("shown", show);
  134. });
  135. // 为表格绑定事件
  136. Table.api.bindevent(table);
  137. // 弹窗窗口大小
  138. table.on('post-body.bs.table',function(e, settings, json, xhr){
  139. $(".btn-add").data("area", ['80%','80%']);
  140. $(".btn-editone").data("area", ['80%','80%']);
  141. });
  142. },
  143. add: function () {
  144. Controller.api.bindevent();
  145. $("input[name='row[type]'][value=list]").trigger("click");
  146. $("select[name='row[template_id]']").trigger("change");
  147. },
  148. edit: function () {
  149. Controller.api.bindevent();
  150. $("input[name='row[type]']:checked").trigger("fa.event.typeupdated", "edit");
  151. },
  152. api: {
  153. events: {
  154. operate: {
  155. 'click .btn-addson': function (e, value, row, index) {
  156. e.stopPropagation();
  157. e.preventDefault();
  158. var table = $(this).closest('table');
  159. var options = table.bootstrapTable('getOptions');
  160. var ids = row[options.pk];
  161. row = $.extend({}, row ? row : {}, {ids: ids});
  162. var url = $(this).attr('href');
  163. Fast.api.open(Table.api.replaceurl(url, row, table), $(this).data("original-title") || $(this).attr("title") || __('Edit'), $(this).data() || {});
  164. },
  165. }
  166. },
  167. formatter: {
  168. subnode: function (value, row, index) {
  169. return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-parent_id="' + row.parent_id + '" class="btn btn-xs '
  170. + (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-' + (row.haschild == 1 || row.ismenu == 1 ? 'sitemap' : 'list') + '"></i></a>';
  171. }
  172. },
  173. bindevent: function () {
  174. // 根据类型显示隐藏对应字段
  175. $(document).on("click fa.event.typeupdated", "input[name='row[type]']", function (e, ref) {
  176. $(".tf").addClass("hidden");
  177. $(".tf.tf-" + $(this).val()).removeClass("hidden");
  178. });
  179. $(document).on("change", "#c-select-tpl", function () {
  180. $("#c-tpl").val($(this).val());
  181. });
  182. // 不验证隐藏元素
  183. $('form[role=form]').data("validator-options", {
  184. ignore: ':hidden'
  185. });
  186. Form.api.bindevent($("form[role=form]"));
  187. $(document).on("change", "select[name='row[template_id]']", function () {
  188. var data = $("option:selected", this).data();
  189. var type = $("input[name='row[type]']:checked").val();
  190. $("input[name='row[listtpl]']").val(data.listtpl).prev().val(data.listtpl);
  191. $("input[name='row[showtpl]']").val(data.showtpl).prev().val(data.showtpl);
  192. });
  193. }
  194. }
  195. };
  196. return Controller;
  197. });