edit_mail_acc.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. }
  81. $(document).ready(function() {
  82. $('#v_account').text($('input[name=v_account]').val());
  83. $('#v_password').text($('input[name=v_password]').val());
  84. $('input[name=v_account]').change(function(){
  85. $('#v_account').text($(this).val());
  86. });
  87. $('input[name=v_password]').change(function(){
  88. if($('input[name=v_password]').attr('type') == 'text')
  89. $('#v_password').text($(this).val());
  90. else
  91. $('#v_password').text(Array($(this).val().length+1).join('*'));
  92. });
  93. $('.toggle-psw-visibility-icon').click(function(){
  94. if($('input[name=v_password]').attr('type') == 'text')
  95. $('#v_password').text($('input[name=v_password]').val());
  96. else
  97. $('#v_password').text(Array($('input[name=v_password]').val().length+1).join('*'));
  98. });
  99. });