config.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/config/index',
  8. add_url: 'general/config/add',
  9. edit_url: 'general/config/edit',
  10. del_url: 'general/config/del',
  11. multi_url: 'general/config/multi',
  12. table: 'config',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {field: 'state', checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'name', title: __('Name')},
  26. {field: 'intro', title: __('Intro')},
  27. {field: 'group', title: __('Group')},
  28. {field: 'type', title: __('Type')},
  29. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  30. ]
  31. ]
  32. });
  33. // 为表格绑定事件
  34. Table.api.bindevent(table);
  35. $("form.edit-form").data("validator-options", {
  36. display: function (elem) {
  37. return $(elem).closest('tr').find("td:first").text();
  38. }
  39. });
  40. Form.api.bindevent($("form.edit-form"));
  41. //不可见的元素不验证
  42. $("form#add-form").data("validator-options", {ignore: ':hidden'});
  43. Form.api.bindevent($("form#add-form"), null, function (ret) {
  44. location.reload();
  45. });
  46. $(document).on("click", ".fieldlist .append", function () {
  47. var rel = parseInt($(this).closest("dl").attr("rel")) + 1;
  48. var name = $(this).closest("dl").data("name");
  49. $(this).closest("dl").attr("rel", rel);
  50. $('<dd class="form-inline"><input type="text" name="' + name + '[field][' + rel + ']" class="form-control" value="" size="10" /> <input type="text" name="' + name + '[value][' + rel + ']" class="form-control" 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());
  51. });
  52. $(document).on("click", ".fieldlist dd .btn-remove", function () {
  53. $(this).parent().remove();
  54. });
  55. //拖拽排序
  56. require(['dragsort'], function () {
  57. //绑定拖动排序
  58. $("dl.fieldlist").dragsort({
  59. itemSelector: 'dd',
  60. dragSelector: ".btn-dragsort",
  61. dragEnd: function () {
  62. },
  63. placeHolderTemplate: "<dd></dd>"
  64. });
  65. });
  66. //切换显示隐藏变量字典列表
  67. $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
  68. $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
  69. });
  70. //添加向发件人发送测试邮件按钮和方法
  71. $('input[name="row[mail_from]"]').parent().next().append('<a class="btn btn-info testmail">' + __('Send a test message') + '</a>');
  72. $(document).on("click", ".testmail", function () {
  73. Backend.api.ajax({url: "general/config/emailtest", data: {receiver: $('input[name="row[mail_from]"]').val()}});
  74. });
  75. },
  76. add: function () {
  77. Controller.api.bindevent();
  78. },
  79. edit: function () {
  80. Controller.api.bindevent();
  81. },
  82. api: {
  83. bindevent: function () {
  84. Form.api.bindevent($("form[role=form]"));
  85. }
  86. }
  87. };
  88. return Controller;
  89. });