add_mail_acc.js 5.9 KB

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