edit_mail_acc.js 5.0 KB

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