add_mail_acc.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. App.Actions.MAIL_ACC.enable_unlimited = function(elm, source_elm) {
  2. $(elm).data('checked', true);
  3. $(elm).data('prev_value', $(elm).val()); // save prev value in order to restore if needed
  4. $(elm).val(App.Constants.UNLIM_TRANSLATED_VALUE);
  5. $(elm).attr('disabled', true);
  6. $(source_elm).css('opacity', '1');
  7. }
  8. App.Actions.MAIL_ACC.disable_unlimited = function(elm, source_elm) {
  9. $(elm).data('checked', false);
  10. if ($(elm).data('prev_value') && $(elm).data('prev_value').trim() != '') {
  11. var prev_value = $(elm).data('prev_value').trim();
  12. $(elm).val(prev_value);
  13. if (App.Helpers.isUnlimitedValue(prev_value)) {
  14. $(elm).val('0');
  15. }
  16. }
  17. else {
  18. if (App.Helpers.isUnlimitedValue($(elm).val())) {
  19. $(elm).val('0');
  20. }
  21. }
  22. $(elm).attr('disabled', false);
  23. $(source_elm).css('opacity', '0.5');
  24. }
  25. App.Actions.MAIL_ACC.toggle_unlimited_feature = function(evt) {
  26. var elm = $(evt.target);
  27. var ref = elm.prev('.vst-input');
  28. if (!$(ref).data('checked')) {
  29. App.Actions.MAIL_ACC.enable_unlimited(ref, elm);
  30. }
  31. else {
  32. App.Actions.MAIL_ACC.disable_unlimited(ref, elm);
  33. }
  34. }
  35. App.Listeners.MAIL_ACC.checkbox_unlimited_feature = function() {
  36. $('.unlim-trigger').on('click', App.Actions.MAIL_ACC.toggle_unlimited_feature);
  37. }
  38. App.Listeners.MAIL_ACC.init = function() {
  39. $('.unlim-trigger').each(function(i, elm) {
  40. var ref = $(elm).prev('.vst-input');
  41. if (App.Helpers.isUnlimitedValue($(ref).val())) {
  42. App.Actions.MAIL_ACC.enable_unlimited(ref, elm);
  43. }
  44. else {
  45. $(ref).data('prev_value', $(ref).val());
  46. App.Actions.MAIL_ACC.disable_unlimited(ref, elm);
  47. }
  48. });
  49. }
  50. App.Helpers.isUnlimitedValue = function(value) {
  51. var value = value.trim();
  52. if (value == App.Constants.UNLIM_VALUE || value == App.Constants.UNLIM_TRANSLATED_VALUE) {
  53. return true;
  54. }
  55. return false;
  56. }
  57. //
  58. // Page entry point
  59. // Trigger listeners
  60. App.Listeners.MAIL_ACC.init();
  61. App.Listeners.MAIL_ACC.checkbox_unlimited_feature();
  62. $('form[name="v_quota"]').bind('submit', function(evt) {
  63. $('input:disabled').each(function(i, elm) {
  64. $(elm).attr('disabled', false);
  65. if (App.Helpers.isUnlimitedValue($(elm).val())) {
  66. $(elm).val(App.Constants.UNLIM_VALUE);
  67. }
  68. });
  69. });
  70. randomString = function() {
  71. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  72. var string_length = 10;
  73. var randomstring = '';
  74. for (var i = 0; i < string_length; i++) {
  75. var rnum = Math.floor(Math.random() * chars.length);
  76. randomstring += chars.substr(rnum, 1);
  77. }
  78. document.v_add_mail_acc.v_password.value = randomstring;
  79. if($('input[name=v_password]').attr('type') == 'text')
  80. $('#v_password').text(randomstring);
  81. else
  82. $('#v_password').text(Array(randomstring.length+1).join('*'));
  83. }
  84. $(document).ready(function() {
  85. $('#v_account').text($('input[name=v_account]').val());
  86. $('#v_password').text($('input[name=v_password]').val());
  87. $('input[name=v_account]').change(function(){
  88. $('#v_account').text($(this).val());
  89. });
  90. $('input[name=v_password]').change(function(){
  91. if($('input[name=v_password]').attr('type') == 'text')
  92. $('#v_password').text($(this).val());
  93. else
  94. $('#v_password').text(Array($(this).val().length+1).join('*'));
  95. });
  96. $('.toggle-psw-visibility-icon').click(function(){
  97. if($('input[name=v_password]').attr('type') == 'text')
  98. $('#v_password').text($('input[name=v_password]').val());
  99. else
  100. $('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*'));
  101. });
  102. $('#mail_configuration').change(function(evt){
  103. var opt = $(evt.target).find('option:selected');
  104. switch(opt.attr('v_type')){
  105. case 'hostname':
  106. $('#td_imap_hostname').html(opt.attr('domain'));
  107. $('#td_smtp_hostname').html(opt.attr('domain'));
  108. break;
  109. case 'starttls':
  110. $('#td_imap_port').html('143');
  111. $('#td_imap_encryption').html('STARTTLS');
  112. $('#td_smtp_port').html('587');
  113. $('#td_smtp_encryption').html('STARTTLS');
  114. break;
  115. case 'ssl':
  116. $('#td_imap_port').html('993');
  117. $('#td_imap_encryption').html('SSL');
  118. $('#td_smtp_port').html('465');
  119. $('#td_smtp_encryption').html('SSL');
  120. break;
  121. case 'no_encryption':
  122. $('#td_imap_hostname').html(opt.attr('domain'));
  123. $('#td_smtp_hostname').html(opt.attr('domain'));
  124. $('#td_imap_port').html('143');
  125. $('#td_imap_encryption').html(opt.attr('no_encryption'));
  126. $('#td_smtp_port').html('25');
  127. $('#td_smtp_encryption').html(opt.attr('no_encryption'));
  128. break;
  129. }
  130. });
  131. });