You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

134 lines
5.1 KiB

  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", {
  49. ignore: ':hidden',
  50. rules: {
  51. content: function () {
  52. return ['radio', 'checkbox', 'select', 'selects'].indexOf($("#add-form select[name='row[type]']").val()) > -1;
  53. },
  54. extend: function () {
  55. return $("#add-form select[name='row[type]']").val() == 'custom';
  56. }
  57. }
  58. });
  59. Form.api.bindevent($("form#add-form"), function (ret) {
  60. setTimeout(function () {
  61. location.reload();
  62. }, 1500);
  63. });
  64. //切换显示隐藏变量字典列表
  65. $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
  66. $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
  67. });
  68. //选择规则
  69. $(document).on("click", ".rulelist > li > a", function () {
  70. var ruleArr = $("#rule").val() == '' ? [] : $("#rule").val().split(";");
  71. var rule = $(this).data("value");
  72. var index = ruleArr.indexOf(rule);
  73. if (index > -1) {
  74. ruleArr.splice(index, 1);
  75. } else {
  76. ruleArr.push(rule);
  77. }
  78. $("#rule").val(ruleArr.join(";"));
  79. $(this).parent().toggleClass("active");
  80. });
  81. //添加向发件人发送测试邮件按钮和方法
  82. $('input[name="row[mail_from]"]').parent().next().append('<a class="btn btn-info testmail">' + __('Send a test message') + '</a>');
  83. $(document).on("click", ".testmail", function () {
  84. var that = this;
  85. Layer.prompt({title: __('Please input your email'), formType: 0}, function (value, index) {
  86. Backend.api.ajax({
  87. url: "general/config/emailtest",
  88. data: $(that).closest("form").serialize() + "&receiver=" + value
  89. });
  90. });
  91. });
  92. //删除配置
  93. $(document).on("click", ".btn-delcfg", function () {
  94. var that = this;
  95. Layer.confirm(__('Are you sure you want to delete this item?'), {
  96. icon: 3,
  97. title: '提示'
  98. }, function (index) {
  99. Backend.api.ajax({
  100. url: "general/config/del",
  101. data: {name: $(that).data("name")}
  102. }, function () {
  103. $(that).closest("tr").remove();
  104. Layer.close(index);
  105. });
  106. });
  107. });
  108. },
  109. add: function () {
  110. Controller.api.bindevent();
  111. },
  112. edit: function () {
  113. Controller.api.bindevent();
  114. },
  115. api: {
  116. bindevent: function () {
  117. Form.api.bindevent($("form[role=form]"));
  118. }
  119. }
  120. };
  121. return Controller;
  122. });