configvalue.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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: 'general/configvalue/index',
  8. add_url: 'general/configvalue/add',
  9. edit_url: 'general/configvalue/edit',
  10. del_url: 'general/configvalue/del',
  11. multi_url: 'general/configvalue/multi',
  12. table: 'configvalue',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. sortName: 'weigh',
  20. columns: [
  21. [
  22. {field: 'state', checkbox: true, },
  23. {field: 'id', title: 'ID'},
  24. {field: 'name', title: __('Name')},
  25. {field: 'weigh', title: __('Weigh')},
  26. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  27. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  28. ]
  29. ]
  30. });
  31. // 为表格绑定事件
  32. Table.api.bindevent(table);
  33. // 清除缓存
  34. $(document).on("click", ".btn-clear-cache", function (e) {
  35. Backend.api.layer.confirm(__("Are you sure you want to clear cache?"), function () {
  36. Backend.api.ajax({
  37. url: 'ajax/clearcache'
  38. }, function (ret) {
  39. Layer.closeAll();
  40. Toastr.success(__('Operation completed'));
  41. });
  42. });
  43. });
  44. },
  45. add: function () {
  46. Form.api.bindevent($("form[role=form]"));
  47. Controller.api.bindevent();
  48. },
  49. edit: function () {
  50. Form.api.bindevent($("form[role=form]"));
  51. Controller.api.bindevent();
  52. },
  53. api: {
  54. bindevent: function () {
  55. $(document).on("click", ".fieldlist .append", function () {
  56. var rel = parseInt($(this).closest("dl").attr("rel")) + 1;
  57. $(this).closest("dl").attr("rel", rel);
  58. $('<dd class="form-inline"><input type="text" name="field[' + rel + ']" class="form-control" id="field-' + rel + '" value="" size="10" /> <input type="text" name="value[' + rel + ']" class="form-control" id="value-' + rel + '" value="" size="40" /> <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span> <span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span></dd>').insertBefore($(this).parent());
  59. });
  60. $(document).on("click", ".fieldlist dd .btn-remove", function () {
  61. $(this).parent().remove();
  62. });
  63. //拖拽排序
  64. require(['dragsort'], function () {
  65. //绑定拖动排序
  66. $("dl.fieldlist").dragsort({
  67. itemSelector: 'dd',
  68. dragSelector: ".btn-dragsort",
  69. dragEnd: function () {
  70. },
  71. placeHolderTemplate: "<dd></dd>"
  72. });
  73. });
  74. }
  75. }
  76. };
  77. return Controller;
  78. });