category.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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: 'blog/category/index',
  8. add_url: 'blog/category/add',
  9. edit_url: 'blog/category/edit',
  10. del_url: 'blog/category/del',
  11. multi_url: 'blog/category/multi',
  12. table: 'blog_category',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'weigh',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'pid', title: __('Pid'), formatter: Table.api.formatter.search, visible: false},
  26. {field: 'name', title: __('Name')},
  27. {field: 'nickname', title: __('Nickname')},
  28. {
  29. field: 'link', title: __('Url'), formatter: function (value, row, index) {
  30. return '<div class=""><a href="' + row.url + '" class="btn btn-xs btn-default" target="_blank"><i class="fa fa-link"></i></a></div>';
  31. }
  32. },
  33. {field: 'flag', title: __('Flag'), formatter: Table.api.formatter.flag},
  34. {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
  35. {field: 'keywords', title: __('Keywords')},
  36. {field: 'description', title: __('Description')},
  37. {field: 'diyname', title: __('Diyname')},
  38. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange'},
  39. {field: 'updatetime', title: __('Updatetime'), visible: false, formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange'},
  40. {field: 'weigh', title: __('Weigh')},
  41. {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
  42. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  43. ]
  44. ]
  45. });
  46. // 为表格绑定事件
  47. Table.api.bindevent(table);
  48. },
  49. add: function () {
  50. Controller.api.bindevent();
  51. },
  52. edit: function () {
  53. Controller.api.bindevent();
  54. },
  55. api: {
  56. bindevent: function () {
  57. $.validator.config({
  58. rules: {
  59. diyname: function (element) {
  60. if (element.value.toString().match(/^\d+$/)) {
  61. return __('Can not be digital');
  62. }
  63. return $.ajax({
  64. url: 'blog/category/check_element_available',
  65. type: 'POST',
  66. data: {id: $("#category-id").val(), name: element.name, value: element.value},
  67. dataType: 'json'
  68. });
  69. }
  70. }
  71. });
  72. //获取栏目拼音
  73. var si;
  74. $(document).on("keyup", "#c-name", function () {
  75. var value = $(this).val();
  76. if (value != '' && !value.match(/\n/)) {
  77. clearTimeout(si);
  78. si = setTimeout(function () {
  79. Fast.api.ajax({
  80. loading: false,
  81. url: "blog/ajax/get_title_pinyin",
  82. data: {title: value}
  83. }, function (data, ret) {
  84. $("#c-diyname").val(data.pinyin);
  85. return false;
  86. }, function (data, ret) {
  87. return false;
  88. });
  89. }, 200);
  90. }
  91. });
  92. Form.api.bindevent($("form[role=form]"));
  93. }
  94. }
  95. };
  96. return Controller;
  97. });