edit_mail_acc.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. generate_mail_credentials();
  85. }
  86. generate_mail_credentials = function() {
  87. var div = $('.mail-infoblock').clone();
  88. div.find('#mail_configuration').remove();
  89. var pass=div.find('#v_password').text();
  90. if (pass=="") div.find('#v_password').html(' ');
  91. var output = div.text();
  92. output=output.replace(/(?:\r\n|\r|\n|\t)/g, "|");
  93. output=output.replace(/ /g, "");
  94. output=output.replace(/\|\|/g, "|");
  95. output=output.replace(/\|\|/g, "|");
  96. output=output.replace(/\|\|/g, "|");
  97. output=output.replace(/^\|+/g, "");
  98. output=output.replace(/\|$/, "");
  99. output=output.replace(/ $/, "");
  100. output=output.replace(/:\|/g, ": ");
  101. output=output.replace(/\|/g, "\n");
  102. //console.log(output);
  103. $('#v_credentials').val(output);
  104. }
  105. $(document).ready(function() {
  106. $('#v_account').text($('input[name=v_account]').val());
  107. $('#v_password').text($('input[name=v_password]').val());
  108. generate_mail_credentials();
  109. $('input[name=v_account]').change(function(){
  110. $('#v_account').text($(this).val());
  111. generate_mail_credentials();
  112. });
  113. $('input[name=v_password]').change(function(){
  114. if($('input[name=v_password]').attr('type') == 'text')
  115. $('#v_password').text($(this).val());
  116. else
  117. $('#v_password').text(Array($(this).val().length+1).join('*'));
  118. generate_mail_credentials();
  119. });
  120. $('.toggle-psw-visibility-icon').click(function(){
  121. if($('input[name=v_password]').attr('type') == 'text')
  122. $('#v_password').text($('input[name=v_password]').val());
  123. else
  124. $('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*'));
  125. generate_mail_credentials();
  126. });
  127. $('#mail_configuration').change(function(evt){
  128. var opt = $(evt.target).find('option:selected');
  129. switch(opt.attr('v_type')){
  130. case 'hostname':
  131. $('#td_imap_hostname').html(opt.attr('domain'));
  132. $('#td_smtp_hostname').html(opt.attr('domain'));
  133. break;
  134. case 'starttls':
  135. $('#td_imap_port').html('143');
  136. $('#td_imap_encryption').html('STARTTLS');
  137. $('#td_smtp_port').html('587');
  138. $('#td_smtp_encryption').html('STARTTLS');
  139. break;
  140. case 'ssl':
  141. $('#td_imap_port').html('993');
  142. $('#td_imap_encryption').html('SSL / TLS');
  143. $('#td_smtp_port').html('465');
  144. $('#td_smtp_encryption').html('SSL / TLS');
  145. break;
  146. case 'no_encryption':
  147. $('#td_imap_hostname').html(opt.attr('domain'));
  148. $('#td_smtp_hostname').html(opt.attr('domain'));
  149. $('#td_imap_port').html('143');
  150. $('#td_imap_encryption').html(opt.attr('no_encryption'));
  151. $('#td_smtp_port').html('25');
  152. $('#td_smtp_encryption').html(opt.attr('no_encryption'));
  153. break;
  154. }
  155. generate_mail_credentials();
  156. });
  157. });