installsmtp.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. $(function()
  2. {
  3. /**
  4. * Fresh submit btton by enable SMTP checkboc value and verified result of SMTP account.
  5. *
  6. * @access public
  7. * @return void
  8. */
  9. function freshSubmitBtn()
  10. {
  11. var enableSMTP = $('#smtpForm input[type=checkbox]:checked').length > 0;
  12. var accountRight = $('#verifyAccountBtn').attr('pass') == 'true';
  13. if(enableSMTP)
  14. {
  15. $('#smtpForm').find('table').show();
  16. $('#smtpForm').find('button[type=submit]').show();
  17. }
  18. else
  19. {
  20. $('#smtpForm').find('table').hide();
  21. $('#smtpForm').find('button[type=submit]').hide();
  22. }
  23. if(enableSMTP && accountRight)
  24. {
  25. $('#smtpForm button[type=submit]').attr('disabled', false);
  26. }
  27. else
  28. {
  29. $('#smtpForm button[type=submit]').attr('disabled', true);
  30. }
  31. }
  32. $('#smtpForm input[type=checkbox]').on('change', function(event)
  33. {
  34. freshSubmitBtn();
  35. });
  36. $('#smtpForm input[type=checkbox]').change();
  37. $('#smtpForm input[type=text]').on('change', function(event)
  38. {
  39. $('#verifyAccountBtn').attr('pass', 'false');
  40. $('#verifyResult').text('');
  41. freshSubmitBtn();
  42. });
  43. $('#verifyAccountBtn').on('click', function(event)
  44. {
  45. var settings = {};
  46. settings.host = $("input[name='host']").val();
  47. settings.port = $("input[name='port']").val();
  48. settings.user = $("input[name='user']").val();
  49. settings.pass = $("input[name='pass']").val();
  50. if(!settings.host || !settings.port || !settings.user || !settings.pass)
  51. {
  52. bootbox.alert(
  53. {
  54. title: notices.attention,
  55. message: notices.fillAllRequiredFields,
  56. });
  57. return;
  58. }
  59. $.post(createLink('system', 'ajaxVerifySMTPAccount'), settings).done(function(response)
  60. {
  61. try
  62. {
  63. var res = JSON.parse(response);
  64. }
  65. catch(error)
  66. {
  67. var res = {result: 'fail', message: errors.verifySMTPFailed,};
  68. }
  69. $('#verifyResult').html(res.message);
  70. if(res.result == 'success')
  71. {
  72. $('#verifyAccountBtn').attr('pass', 'true');
  73. $('#verifyResult').removeClass('text-red').addClass('text-success');
  74. freshSubmitBtn();
  75. }
  76. else
  77. {
  78. $('#verifyAccountBtn').attr('pass', 'false');
  79. $('#verifyResult').removeClass('text-success').addClass('text-red');
  80. freshSubmitBtn();
  81. }
  82. });
  83. });
  84. });