config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. {
  30. field: 'operate',
  31. title: __('Operate'),
  32. table: table,
  33. events: Table.api.events.operate,
  34. formatter: Table.api.formatter.operate
  35. }
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. $("form.edit-form").data("validator-options", {
  42. display: function (elem) {
  43. return $(elem).closest('tr').find("td:first").text();
  44. }
  45. });
  46. Form.api.bindevent($("form.edit-form"));
  47. //不可见的元素不验证
  48. $("form#add-form").data("validator-options", {ignore: ':hidden'});
  49. Form.api.bindevent($("form#add-form"), null, function (ret) {
  50. location.reload();
  51. });
  52. //切换显示隐藏变量字典列表
  53. $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
  54. $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
  55. });
  56. //添加向发件人发送测试邮件按钮和方法
  57. $('input[name="row[mail_from]"]').parent().next().append('<a class="btn btn-info testmail">' + __('Send a test message') + '</a>');
  58. $(document).on("click", ".testmail", function () {
  59. var that = this;
  60. Layer.prompt({title: __('Please input your email'), formType: 0}, function (value, index) {
  61. Backend.api.ajax({
  62. url: "general/config/emailtest?receiver=" + value,
  63. data: $(that).closest("form").serialize()
  64. });
  65. });
  66. });
  67. },
  68. add: function () {
  69. Controller.api.bindevent();
  70. },
  71. edit: function () {
  72. Controller.api.bindevent();
  73. },
  74. api: {
  75. bindevent: function () {
  76. Form.api.bindevent($("form[role=form]"));
  77. }
  78. }
  79. };
  80. return Controller;
  81. });