config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. $("form.edit-form").data("validator-options", {
  5. display: function (elem) {
  6. return $(elem).closest('tr').find("td:first").text();
  7. }
  8. });
  9. Form.api.bindevent($("form.edit-form"));
  10. //不可见的元素不验证
  11. $("form#add-form").data("validator-options", {
  12. ignore: ':hidden',
  13. rules: {
  14. content: function () {
  15. return ['radio', 'checkbox', 'select', 'selects'].indexOf($("#add-form select[name='row[type]']").val()) > -1;
  16. },
  17. extend: function () {
  18. return $("#add-form select[name='row[type]']").val() == 'custom';
  19. }
  20. }
  21. });
  22. Form.api.bindevent($("form#add-form"), function (ret) {
  23. setTimeout(function () {
  24. location.reload();
  25. }, 1500);
  26. });
  27. //切换显示隐藏变量字典列表
  28. $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
  29. $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
  30. });
  31. //选择规则
  32. $(document).on("click", ".rulelist > li > a", function () {
  33. var ruleArr = $("#rule").val() == '' ? [] : $("#rule").val().split(";");
  34. var rule = $(this).data("value");
  35. var index = ruleArr.indexOf(rule);
  36. if (index > -1) {
  37. ruleArr.splice(index, 1);
  38. } else {
  39. ruleArr.push(rule);
  40. }
  41. $("#rule").val(ruleArr.join(";"));
  42. $(this).parent().toggleClass("active");
  43. });
  44. //添加向发件人发送测试邮件按钮和方法
  45. $('input[name="row[mail_from]"]').parent().next().append('<a class="btn btn-info testmail">' + __('Send a test message') + '</a>');
  46. $(document).on("click", ".testmail", function () {
  47. var that = this;
  48. Layer.prompt({title: __('Please input your email'), formType: 0}, function (value, index) {
  49. Backend.api.ajax({
  50. url: "general/config/emailtest",
  51. data: $(that).closest("form").serialize() + "&receiver=" + value
  52. });
  53. });
  54. });
  55. //删除配置
  56. $(document).on("click", ".btn-delcfg", function () {
  57. var that = this;
  58. Layer.confirm(__('Are you sure you want to delete this item?'), {
  59. icon: 3,
  60. title: '提示'
  61. }, function (index) {
  62. Backend.api.ajax({
  63. url: "general/config/del",
  64. data: {name: $(that).data("name")}
  65. }, function () {
  66. $(that).closest("tr").remove();
  67. Layer.close(index);
  68. });
  69. });
  70. });
  71. },
  72. add: function () {
  73. Controller.api.bindevent();
  74. },
  75. edit: function () {
  76. Controller.api.bindevent();
  77. },
  78. api: {
  79. bindevent: function () {
  80. Form.api.bindevent($("form[role=form]"));
  81. }
  82. }
  83. };
  84. return Controller;
  85. });