admin.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. $(document).ready(function(){
  2. var params = OC.Util.History.parseUrlQuery();
  3. // Hack to add a trusted domain
  4. if (params.trustDomain) {
  5. OC.dialogs.confirm(t('settings', 'Are you really sure you want add "{domain}" as trusted domain?',
  6. {domain: params.trustDomain}),
  7. t('settings', 'Add trusted domain'), function(answer) {
  8. if(answer) {
  9. $.ajax({
  10. type: 'POST',
  11. url: OC.generateUrl('settings/admin/security/trustedDomains'),
  12. data: { newTrustedDomain: params.trustDomain }
  13. }).done(function() {
  14. window.location.replace(OC.generateUrl('settings/admin'));
  15. });
  16. }
  17. });
  18. }
  19. $('#excludedGroups').each(function (index, element) {
  20. OC.Settings.setupGroupsSelect($(element));
  21. $(element).change(function(ev) {
  22. var groups = ev.val || [];
  23. if (groups.length > 0) {
  24. groups = ev.val.join(','); // FIXME: make this JSON
  25. } else {
  26. groups = '';
  27. }
  28. OC.AppConfig.setValue('core', $(this).attr('name'), groups);
  29. });
  30. });
  31. $('#loglevel').change(function(){
  32. $.post(OC.generateUrl('/settings/admin/log/level'), {level: $(this).val()},function(){
  33. OC.Log.reload();
  34. } );
  35. });
  36. $('#backgroundjobs span.crondate').tipsy({gravity: 's', live: true});
  37. $('#backgroundjobs input').change(function(){
  38. if($(this).attr('checked')){
  39. var mode = $(this).val();
  40. if (mode === 'ajax' || mode === 'webcron' || mode === 'cron') {
  41. OC.AppConfig.setValue('core', 'backgroundjobs_mode', mode);
  42. }
  43. }
  44. });
  45. $('#shareAPIEnabled').change(function() {
  46. $('#shareAPI p:not(#enable)').toggleClass('hidden', !this.checked);
  47. });
  48. $('#enableEncryption').change(function() {
  49. $('#encryptionAPI div#EncryptionWarning').toggleClass('hidden');
  50. });
  51. $('#reallyEnableEncryption').click(function() {
  52. $('#encryptionAPI div#EncryptionWarning').toggleClass('hidden');
  53. $('#encryptionAPI div#EncryptionSettingsArea').toggleClass('hidden');
  54. OC.AppConfig.setValue('core', 'encryption_enabled', 'yes');
  55. $('#enableEncryption').attr('disabled', 'disabled');
  56. });
  57. $('#startmigration').click(function(event){
  58. $(window).on('beforeunload.encryption', function(e) {
  59. return t('settings', 'Migration in progress. Please wait until the migration is finished');
  60. });
  61. event.preventDefault();
  62. $('#startmigration').prop('disabled', true);
  63. OC.msg.startAction('#startmigration_msg', t('settings', 'Migration started …'));
  64. $.post(OC.generateUrl('/settings/admin/startmigration'), '', function(data){
  65. OC.msg.finishedAction('#startmigration_msg', data);
  66. if (data['status'] === 'success') {
  67. $('#encryptionAPI div#selectEncryptionModules').toggleClass('hidden');
  68. $('#encryptionAPI div#migrationWarning').toggleClass('hidden');
  69. } else {
  70. $('#startmigration').prop('disabled', false);
  71. }
  72. $(window).off('beforeunload.encryption');
  73. });
  74. });
  75. $('#shareAPI input:not(#excludedGroups)').change(function() {
  76. var value = $(this).val();
  77. if ($(this).attr('type') === 'checkbox') {
  78. if (this.checked) {
  79. value = 'yes';
  80. } else {
  81. value = 'no';
  82. }
  83. }
  84. OC.AppConfig.setValue('core', $(this).attr('name'), value);
  85. });
  86. $('#shareapiDefaultExpireDate').change(function() {
  87. $("#setDefaultExpireDate").toggleClass('hidden', !this.checked);
  88. });
  89. $('#allowLinks').change(function() {
  90. $("#publicLinkSettings").toggleClass('hidden', !this.checked);
  91. $('#setDefaultExpireDate').toggleClass('hidden', !(this.checked && $('#shareapiDefaultExpireDate')[0].checked));
  92. });
  93. $('#mail_smtpauth').change(function() {
  94. if (!this.checked) {
  95. $('#mail_credentials').addClass('hidden');
  96. } else {
  97. $('#mail_credentials').removeClass('hidden');
  98. }
  99. });
  100. $('#mail_smtpmode').change(function() {
  101. if ($(this).val() !== 'smtp') {
  102. $('#setting_smtpauth').addClass('hidden');
  103. $('#setting_smtphost').addClass('hidden');
  104. $('#mail_smtpsecure_label').addClass('hidden');
  105. $('#mail_smtpsecure').addClass('hidden');
  106. $('#mail_credentials').addClass('hidden');
  107. } else {
  108. $('#setting_smtpauth').removeClass('hidden');
  109. $('#setting_smtphost').removeClass('hidden');
  110. $('#mail_smtpsecure_label').removeClass('hidden');
  111. $('#mail_smtpsecure').removeClass('hidden');
  112. if ($('#mail_smtpauth').attr('checked')) {
  113. $('#mail_credentials').removeClass('hidden');
  114. }
  115. }
  116. });
  117. $('#mail_general_settings_form').change(function(){
  118. OC.msg.startSaving('#mail_settings_msg');
  119. var post = $( "#mail_general_settings_form" ).serialize();
  120. $.post(OC.generateUrl('/settings/admin/mailsettings'), post, function(data){
  121. OC.msg.finishedSaving('#mail_settings_msg', data);
  122. });
  123. });
  124. $('#mail_credentials_settings_submit').click(function(){
  125. OC.msg.startSaving('#mail_settings_msg');
  126. var post = $( "#mail_credentials_settings" ).serialize();
  127. $.post(OC.generateUrl('/settings/admin/mailsettings/credentials'), post, function(data){
  128. OC.msg.finishedSaving('#mail_settings_msg', data);
  129. });
  130. });
  131. $('#sendtestemail').click(function(event){
  132. event.preventDefault();
  133. OC.msg.startAction('#sendtestmail_msg', t('settings', 'Sending...'));
  134. $.post(OC.generateUrl('/settings/admin/mailtest'), '', function(data){
  135. OC.msg.finishedAction('#sendtestmail_msg', data);
  136. });
  137. });
  138. $('#shareapiExcludeGroups').change(function() {
  139. $("#selectExcludedGroups").toggleClass('hidden', !this.checked);
  140. });
  141. // run setup checks then gather error messages
  142. $.when(
  143. OC.SetupChecks.checkWebDAV(),
  144. OC.SetupChecks.checkSetup(),
  145. OC.SetupChecks.checkGeneric()
  146. ).then(function(check1, check2, check3) {
  147. var errors = [].concat(check1, check2, check3);
  148. var $el = $('#postsetupchecks');
  149. var $errorsEl;
  150. $el.find('.loading').addClass('hidden');
  151. if (errors.length === 0) {
  152. } else {
  153. $errorsEl = $el.find('.errors');
  154. for (var i = 0; i < errors.length; i++ ) {
  155. $errorsEl.append('<li>' + errors[i] + '</li>');
  156. }
  157. $errorsEl.removeClass('hidden');
  158. $el.find('.hint').removeClass('hidden');
  159. }
  160. });
  161. });