admin.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. groups = JSON.stringify(groups);
  24. OC.AppConfig.setValue('core', $(this).attr('name'), groups);
  25. });
  26. });
  27. $('#loglevel').change(function(){
  28. $.post(OC.generateUrl('/settings/admin/log/level'), {level: $(this).val()},function(){
  29. OC.Log.reload();
  30. } );
  31. });
  32. $('#backgroundjobs span.crondate').tipsy({gravity: 's', live: true});
  33. $('#backgroundjobs input').change(function(){
  34. if($(this).attr('checked')){
  35. var mode = $(this).val();
  36. if (mode === 'ajax' || mode === 'webcron' || mode === 'cron') {
  37. OC.AppConfig.setValue('core', 'backgroundjobs_mode', mode);
  38. // clear cron errors on background job mode change
  39. OC.AppConfig.deleteKey('core', 'cronErrors');
  40. }
  41. }
  42. });
  43. $('#shareAPIEnabled').change(function() {
  44. $('#shareAPI p:not(#enable)').toggleClass('hidden', !this.checked);
  45. });
  46. $('#enableEncryption').change(function() {
  47. $('#encryptionAPI div#EncryptionWarning').toggleClass('hidden');
  48. });
  49. $('#reallyEnableEncryption').click(function() {
  50. $('#encryptionAPI div#EncryptionWarning').toggleClass('hidden');
  51. $('#encryptionAPI div#EncryptionSettingsArea').toggleClass('hidden');
  52. OC.AppConfig.setValue('core', 'encryption_enabled', 'yes');
  53. $('#enableEncryption').attr('disabled', 'disabled');
  54. });
  55. $('#startmigration').click(function(event){
  56. $(window).on('beforeunload.encryption', function(e) {
  57. return t('settings', 'Migration in progress. Please wait until the migration is finished');
  58. });
  59. event.preventDefault();
  60. $('#startmigration').prop('disabled', true);
  61. OC.msg.startAction('#startmigration_msg', t('settings', 'Migration started …'));
  62. $.post(OC.generateUrl('/settings/admin/startmigration'), '', function(data){
  63. OC.msg.finishedAction('#startmigration_msg', data);
  64. if (data['status'] === 'success') {
  65. $('#encryptionAPI div#selectEncryptionModules').toggleClass('hidden');
  66. $('#encryptionAPI div#migrationWarning').toggleClass('hidden');
  67. } else {
  68. $('#startmigration').prop('disabled', false);
  69. }
  70. $(window).off('beforeunload.encryption');
  71. });
  72. });
  73. $('#shareapiExpireAfterNDays').change(function() {
  74. var value = $(this).val();
  75. if (value <= 0) {
  76. $(this).val("1");
  77. }
  78. });
  79. $('#shareAPI input:not(#excludedGroups)').change(function() {
  80. var value = $(this).val();
  81. if ($(this).attr('type') === 'checkbox') {
  82. if (this.checked) {
  83. value = 'yes';
  84. } else {
  85. value = 'no';
  86. }
  87. }
  88. OC.AppConfig.setValue('core', $(this).attr('name'), value);
  89. });
  90. $('#shareapiDefaultExpireDate').change(function() {
  91. $("#setDefaultExpireDate").toggleClass('hidden', !this.checked);
  92. });
  93. $('#allowLinks').change(function() {
  94. $("#publicLinkSettings").toggleClass('hidden', !this.checked);
  95. $('#setDefaultExpireDate').toggleClass('hidden', !(this.checked && $('#shareapiDefaultExpireDate')[0].checked));
  96. });
  97. $('#mail_smtpauth').change(function() {
  98. if (!this.checked) {
  99. $('#mail_credentials').addClass('hidden');
  100. } else {
  101. $('#mail_credentials').removeClass('hidden');
  102. }
  103. });
  104. $('#mail_smtpmode').change(function() {
  105. if ($(this).val() !== 'smtp') {
  106. $('#setting_smtpauth').addClass('hidden');
  107. $('#setting_smtphost').addClass('hidden');
  108. $('#mail_smtpsecure_label').addClass('hidden');
  109. $('#mail_smtpsecure').addClass('hidden');
  110. $('#mail_credentials').addClass('hidden');
  111. } else {
  112. $('#setting_smtpauth').removeClass('hidden');
  113. $('#setting_smtphost').removeClass('hidden');
  114. $('#mail_smtpsecure_label').removeClass('hidden');
  115. $('#mail_smtpsecure').removeClass('hidden');
  116. if ($('#mail_smtpauth').attr('checked')) {
  117. $('#mail_credentials').removeClass('hidden');
  118. }
  119. }
  120. });
  121. $('#mail_general_settings_form').change(function(){
  122. OC.msg.startSaving('#mail_settings_msg');
  123. var post = $( "#mail_general_settings_form" ).serialize();
  124. $.post(OC.generateUrl('/settings/admin/mailsettings'), post, function(data){
  125. OC.msg.finishedSaving('#mail_settings_msg', data);
  126. });
  127. });
  128. $('#mail_credentials_settings_submit').click(function(){
  129. OC.msg.startSaving('#mail_settings_msg');
  130. var post = $( "#mail_credentials_settings" ).serialize();
  131. $.post(OC.generateUrl('/settings/admin/mailsettings/credentials'), post, function(data){
  132. OC.msg.finishedSaving('#mail_settings_msg', data);
  133. });
  134. });
  135. $('#sendtestemail').click(function(event){
  136. event.preventDefault();
  137. OC.msg.startAction('#sendtestmail_msg', t('settings', 'Sending...'));
  138. $.post(OC.generateUrl('/settings/admin/mailtest'), '', function(data){
  139. OC.msg.finishedAction('#sendtestmail_msg', data);
  140. });
  141. });
  142. $('#allowGroupSharing').change(function() {
  143. $('#allowGroupSharing').toggleClass('hidden', !this.checked);
  144. });
  145. $('#shareapiExcludeGroups').change(function() {
  146. $("#selectExcludedGroups").toggleClass('hidden', !this.checked);
  147. });
  148. // run setup checks then gather error messages
  149. $.when(
  150. OC.SetupChecks.checkWebDAV(),
  151. OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav/', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === 'true'),
  152. OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav/', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === 'true'),
  153. OC.SetupChecks.checkSetup(),
  154. OC.SetupChecks.checkGeneric(),
  155. OC.SetupChecks.checkDataProtected()
  156. ).then(function(check1, check2, check3, check4, check5, check6) {
  157. var messages = [].concat(check1, check2, check3, check4, check5, check6);
  158. var $el = $('#postsetupchecks');
  159. $el.find('.loading').addClass('hidden');
  160. var hasMessages = false;
  161. var $errorsEl = $el.find('.errors');
  162. var $warningsEl = $el.find('.warnings');
  163. var $infoEl = $el.find('.info');
  164. for (var i = 0; i < messages.length; i++ ) {
  165. switch(messages[i].type) {
  166. case OC.SetupChecks.MESSAGE_TYPE_INFO:
  167. $infoEl.append('<li>' + messages[i].msg + '</li>');
  168. break;
  169. case OC.SetupChecks.MESSAGE_TYPE_WARNING:
  170. $warningsEl.append('<li>' + messages[i].msg + '</li>');
  171. break;
  172. case OC.SetupChecks.MESSAGE_TYPE_ERROR:
  173. default:
  174. $errorsEl.append('<li>' + messages[i].msg + '</li>');
  175. }
  176. }
  177. if ($errorsEl.find('li').length > 0) {
  178. $errorsEl.removeClass('hidden');
  179. hasMessages = true;
  180. }
  181. if ($warningsEl.find('li').length > 0) {
  182. $warningsEl.removeClass('hidden');
  183. hasMessages = true;
  184. }
  185. if ($infoEl.find('li').length > 0) {
  186. $infoEl.removeClass('hidden');
  187. hasMessages = true;
  188. }
  189. if (hasMessages) {
  190. $el.find('.hint').removeClass('hidden');
  191. } else {
  192. var securityWarning = $('#security-warning');
  193. if (securityWarning.children('ul').children().length === 0) {
  194. $('#security-warning-state').find('span').removeClass('hidden');
  195. }
  196. }
  197. });
  198. });