editsmtp.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 && accountRight)
  14. {
  15. $('#smtpForm button[type=submit]').attr('disabled', false);
  16. }
  17. else
  18. {
  19. $('#smtpForm button[type=submit]').attr('disabled', true);
  20. }
  21. }
  22. $('#smtpForm input[type=checkbox]').on('change', function(event)
  23. {
  24. freshSubmitBtn();
  25. });
  26. $('#smtpForm input[type=checkbox]').change();
  27. $('#verifyAccountBtn').on('click', function(event)
  28. {
  29. var settings = {};
  30. settings.host = $("input[name='host']").val();
  31. settings.port = $("input[name='port']").val();
  32. settings.user = $("input[name='user']").val();
  33. settings.pass = $("input[name='pass']").val();
  34. if(!settings.host || !settings.port || !settings.user || !settings.pass)
  35. {
  36. bootbox.alert(
  37. {
  38. title: notices.attention,
  39. message: notices.fillAllRequiredFields,
  40. });
  41. return;
  42. }
  43. $.post(createLink('system', 'ajaxVerifySMTPAccount'), settings).done(function(response)
  44. {
  45. try
  46. {
  47. var res = JSON.parse(response);
  48. }
  49. catch(error)
  50. {
  51. var res = {result: 'fail', message: errors.verifySMTPFailed,};
  52. }
  53. $('#verifyResult').html(res.message);
  54. if(res.result == 'success')
  55. {
  56. $('#verifyAccountBtn').attr('pass', 'true');
  57. $('#verifyResult').removeClass('text-red').addClass('text-success');
  58. freshSubmitBtn();
  59. }
  60. else
  61. {
  62. $('#verifyAccountBtn').attr('pass', 'false');
  63. $('#verifyResult').removeClass('text-success').addClass('text-red');
  64. freshSubmitBtn();
  65. }
  66. });
  67. });
  68. });