admin.js 6.8 KB

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