config.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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'), table: table, 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. //切换显示隐藏变量字典列表
  47. $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
  48. $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
  49. });
  50. //添加向发件人发送测试邮件按钮和方法
  51. $('input[name="row[mail_from]"]').parent().next().append('<a class="btn btn-info testmail">' + __('Send a test message') + '</a>');
  52. $(document).on("click", ".testmail", function () {
  53. Backend.api.ajax({url: "general/config/emailtest", data: {receiver: $('input[name="row[mail_from]"]').val()}});
  54. });
  55. },
  56. add: function () {
  57. Controller.api.bindevent();
  58. },
  59. edit: function () {
  60. Controller.api.bindevent();
  61. },
  62. api: {
  63. bindevent: function () {
  64. Form.api.bindevent($("form[role=form]"));
  65. }
  66. }
  67. };
  68. return Controller;
  69. });