preferences.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. function showErrorSections() {
  2. if($("#soundcloud-settings .errors").length > 0) {
  3. $("#soundcloud-settings").show();
  4. $(window).scrollTop($("#soundcloud-settings .errors").position().top);
  5. }
  6. if($("#email-server-settings .errors").length > 0) {
  7. $("#email-server-settings").show();
  8. $(window).scrollTop($("#email-server-settings .errors").position().top);
  9. }
  10. if($("#livestream-settings .errors").length > 0) {
  11. $("#livestream-settings").show();
  12. $(window).scrollTop($("#livestream-settings .errors").position().top);
  13. }
  14. }
  15. function setConfigureMailServerListener() {
  16. var configMailServer = $("#configureMailServer");
  17. configMailServer.click(function(event){
  18. setMailServerInputReadonly();
  19. });
  20. var msRequiresAuth = $("#msRequiresAuth");
  21. msRequiresAuth.click(function(event){
  22. setMsAuthenticationFieldsReadonly($(this));
  23. });
  24. }
  25. function setEnableSystemEmailsListener() {
  26. var enableSystemEmails = $("#enableSystemEmail");
  27. enableSystemEmails.click(function(event){
  28. setSystemFromEmailReadonly();
  29. });
  30. }
  31. function setSystemFromEmailReadonly() {
  32. var enableSystemEmails = $("#enableSystemEmail");
  33. var systemFromEmail = $("#systemEmail");
  34. if ($(enableSystemEmails).is(':checked')) {
  35. systemFromEmail.removeAttr("readonly");
  36. } else {
  37. systemFromEmail.attr("readonly", "readonly");
  38. }
  39. }
  40. function setMailServerInputReadonly() {
  41. var configMailServer = $("#configureMailServer");
  42. var mailServer = $("#mailServer");
  43. var port = $("#port");
  44. var requiresAuthCB = $("#msRequiresAuth");
  45. if (configMailServer.is(':checked')) {
  46. mailServer.removeAttr("readonly");
  47. port.removeAttr("readonly");
  48. requiresAuthCB.parent().show();
  49. } else {
  50. mailServer.attr("readonly", "readonly");
  51. port.attr("readonly", "readonly");
  52. requiresAuthCB.parent().hide();
  53. }
  54. setMsAuthenticationFieldsReadonly(requiresAuthCB);
  55. }
  56. /*
  57. * Enable/disable mail server authentication fields
  58. */
  59. function setMsAuthenticationFieldsReadonly(ele) {
  60. var email = $("#email");
  61. var password = $("#ms_password");
  62. var configureMailServer = $("#configureMailServer");
  63. if (ele.is(':checked') && configureMailServer.is(':checked')) {
  64. email.removeAttr("readonly");
  65. password.removeAttr("readonly");
  66. } else if (ele.not(':checked') || configureMailServer.not(':checked')) {
  67. email.attr("readonly", "readonly");
  68. password.attr("readonly", "readonly");
  69. }
  70. }
  71. function setSoundCloudCheckBoxListener() {
  72. var subCheckBox= $("#UseSoundCloud,#SoundCloudDownloadbleOption");
  73. var mainCheckBox= $("#UploadToSoundcloudOption");
  74. subCheckBox.change(function(e){
  75. if (subCheckBox.is(':checked')) {
  76. mainCheckBox.attr("checked", true);
  77. }
  78. });
  79. mainCheckBox.change(function(e){
  80. if (!mainCheckBox.is(':checked')) {
  81. $("#UseSoundCloud,#SoundCloudDownloadbleOption").attr("checked", false);
  82. }
  83. });
  84. }
  85. function removeLogo() {
  86. $.post(baseUrl+'Preference/remove-logo', function(json){});
  87. location.reload();
  88. }
  89. $(document).ready(function() {
  90. $('.collapsible-header').live('click',function() {
  91. $(this).next().toggle('fast');
  92. $(this).toggleClass("closed");
  93. return false;
  94. }).next().hide();
  95. /* No longer using AJAX for this form. Zend + our code makes it needlessly hard to deal with. -- Albert
  96. $('#pref_save').live('click', function() {
  97. var data = $('#pref_form').serialize();
  98. var url = baseUrl+'Preference/index';
  99. $.post(url, {format: "json", data: data}, function(json){
  100. $('#content').empty().append(json.html);
  101. setTimeout(removeSuccessMsg, 5000);
  102. showErrorSections();
  103. setMailServerInputReadonly();
  104. setConfigureMailServerListener();
  105. setEnableSystemEmailsListener();
  106. });
  107. });*/
  108. showErrorSections();
  109. setSoundCloudCheckBoxListener();
  110. setMailServerInputReadonly();
  111. setSystemFromEmailReadonly();
  112. setConfigureMailServerListener();
  113. setEnableSystemEmailsListener();
  114. });