1
0

admin.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. $(document).ready(function(){
  2. var params = OC.Util.History.parseUrlQuery();
  3. // Hack to add a trusted domain
  4. if (params.trustDomain) {
  5. var potentialDomain = params.trustDomain;
  6. potentialDomain = encodeURI(escapeHTML(potentialDomain));
  7. potentialDomain = '<span class="trusted-domain-warning">' + potentialDomain + '</span>';
  8. OC.dialogs.confirmHtml(t('settings', 'Are you really sure you want add {domain} as trusted domain?', {
  9. domain: potentialDomain
  10. }, undefined, {escape: false}),
  11. t('settings', 'Add trusted domain'), function(answer) {
  12. if(answer) {
  13. $.ajax({
  14. type: 'POST',
  15. url: OC.generateUrl('settings/admin/security/trustedDomains'),
  16. data: { newTrustedDomain: params.trustDomain }
  17. }).done(function() {
  18. window.location.replace(OC.generateUrl('settings/admin'));
  19. });
  20. }
  21. });
  22. }
  23. $('#excludedGroups').each(function (index, element) {
  24. OC.Settings.setupGroupsSelect($(element));
  25. $(element).change(function(ev) {
  26. var groups = ev.val || [];
  27. groups = JSON.stringify(groups);
  28. OCP.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').tooltip({placement: 'top'});
  37. $('#backgroundjobs input').change(function(){
  38. if($(this).is(':checked')){
  39. var mode = $(this).val();
  40. if (mode === 'ajax' || mode === 'webcron' || mode === 'cron') {
  41. OCP.AppConfig.setValue('core', 'backgroundjobs_mode', mode);
  42. // clear cron errors on background job mode change
  43. OCP.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. OCP.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(.noJSAutoUpdate)').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. OCP.AppConfig.setValue('core', $(this).attr('name'), value);
  93. });
  94. $('#shareapiDefaultExpireDate').change(function() {
  95. $("#setDefaultExpireDate").toggleClass('hidden', !this.checked);
  96. });
  97. $('#publicShareDisclaimer').change(function() {
  98. $("#publicShareDisclaimerText").toggleClass('hidden', !this.checked);
  99. if(!this.checked) {
  100. savePublicShareDisclaimerText('');
  101. }
  102. });
  103. var savePublicShareDisclaimerText = _.debounce(function(value) {
  104. var options = {
  105. success: function() {
  106. OC.msg.finishedSuccess('#publicShareDisclaimerStatus', t('core', 'Saved'));
  107. },
  108. error: function() {
  109. OC.msg.finishedError('#publicShareDisclaimerStatus', t('core', 'Not saved'));
  110. }
  111. };
  112. OC.msg.startSaving('#publicShareDisclaimerStatus');
  113. if (_.isString(value) && value !== '') {
  114. OCP.AppConfig.setValue('core', 'shareapi_public_link_disclaimertext', value, options);
  115. } else {
  116. $('#publicShareDisclaimerText').val('');
  117. OCP.AppConfig.deleteKey('core', 'shareapi_public_link_disclaimertext', options);
  118. }
  119. }, 500);
  120. $('#publicShareDisclaimerText').on('change, keyup', function() {
  121. savePublicShareDisclaimerText(this.value);
  122. });
  123. $('#allowLinks').change(function() {
  124. $("#publicLinkSettings").toggleClass('hidden', !this.checked);
  125. $('#setDefaultExpireDate').toggleClass('hidden', !(this.checked && $('#shareapiDefaultExpireDate')[0].checked));
  126. });
  127. $('#mail_smtpauth').change(function() {
  128. if (!this.checked) {
  129. $('#mail_credentials').addClass('hidden');
  130. } else {
  131. $('#mail_credentials').removeClass('hidden');
  132. }
  133. });
  134. $('#mail_smtpmode').change(function() {
  135. if ($(this).val() !== 'smtp') {
  136. $('#setting_smtpauth').addClass('hidden');
  137. $('#setting_smtphost').addClass('hidden');
  138. $('#mail_smtpsecure_label').addClass('hidden');
  139. $('#mail_smtpsecure').addClass('hidden');
  140. $('#mail_credentials').addClass('hidden');
  141. } else {
  142. $('#setting_smtpauth').removeClass('hidden');
  143. $('#setting_smtphost').removeClass('hidden');
  144. $('#mail_smtpsecure_label').removeClass('hidden');
  145. $('#mail_smtpsecure').removeClass('hidden');
  146. if ($('#mail_smtpauth').is(':checked')) {
  147. $('#mail_credentials').removeClass('hidden');
  148. }
  149. }
  150. });
  151. var changeEmailSettings = function() {
  152. if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  153. OC.PasswordConfirmation.requirePasswordConfirmation(changeEmailSettings);
  154. return;
  155. }
  156. OC.msg.startSaving('#mail_settings_msg');
  157. $.ajax({
  158. url: OC.generateUrl('/settings/admin/mailsettings'),
  159. type: 'POST',
  160. data: $('#mail_general_settings_form').serialize(),
  161. success: function(data){
  162. OC.msg.finishedSaving('#mail_settings_msg', data);
  163. },
  164. error: function(data){
  165. OC.msg.finishedError('#mail_settings_msg', data.responseJSON.message);
  166. }
  167. });
  168. };
  169. var toggleEmailCredentials = function() {
  170. if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  171. OC.PasswordConfirmation.requirePasswordConfirmation(toggleEmailCredentials);
  172. return;
  173. }
  174. OC.msg.startSaving('#mail_settings_msg');
  175. $.ajax({
  176. url: OC.generateUrl('/settings/admin/mailsettings/credentials'),
  177. type: 'POST',
  178. data: $('#mail_credentials_settings').serialize(),
  179. success: function(data){
  180. OC.msg.finishedSaving('#mail_settings_msg', data);
  181. },
  182. error: function(data){
  183. OC.msg.finishedError('#mail_settings_msg', data.responseJSON.message);
  184. }
  185. });
  186. };
  187. $('#mail_general_settings_form').change(changeEmailSettings);
  188. $('#mail_credentials_settings_submit').click(toggleEmailCredentials);
  189. $('#sendtestemail').click(function(event){
  190. event.preventDefault();
  191. OC.msg.startAction('#sendtestmail_msg', t('settings', 'Sending...'));
  192. $.post(OC.generateUrl('/settings/admin/mailtest'), '', function(data){
  193. OC.msg.finishedAction('#sendtestmail_msg', data);
  194. });
  195. });
  196. $('#allowGroupSharing').change(function() {
  197. $('#allowGroupSharing').toggleClass('hidden', !this.checked);
  198. });
  199. $('#shareapiExcludeGroups').change(function() {
  200. $("#selectExcludedGroups").toggleClass('hidden', !this.checked);
  201. });
  202. // run setup checks then gather error messages
  203. $.when(
  204. OC.SetupChecks.checkWebDAV(),
  205. OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav/', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === 'true'),
  206. OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav/', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === 'true'),
  207. OC.SetupChecks.checkSetup(),
  208. OC.SetupChecks.checkGeneric(),
  209. OC.SetupChecks.checkDataProtected()
  210. ).then(function(check1, check2, check3, check4, check5, check6) {
  211. var messages = [].concat(check1, check2, check3, check4, check5, check6);
  212. var $el = $('#postsetupchecks');
  213. $el.find('.loading').addClass('hidden');
  214. var hasMessages = false;
  215. var $errorsEl = $el.find('.errors');
  216. var $warningsEl = $el.find('.warnings');
  217. var $infoEl = $el.find('.info');
  218. for (var i = 0; i < messages.length; i++ ) {
  219. switch(messages[i].type) {
  220. case OC.SetupChecks.MESSAGE_TYPE_INFO:
  221. $infoEl.append('<li>' + messages[i].msg + '</li>');
  222. break;
  223. case OC.SetupChecks.MESSAGE_TYPE_WARNING:
  224. $warningsEl.append('<li>' + messages[i].msg + '</li>');
  225. break;
  226. case OC.SetupChecks.MESSAGE_TYPE_ERROR:
  227. default:
  228. $errorsEl.append('<li>' + messages[i].msg + '</li>');
  229. }
  230. }
  231. if ($errorsEl.find('li').length > 0) {
  232. $errorsEl.removeClass('hidden');
  233. hasMessages = true;
  234. }
  235. if ($warningsEl.find('li').length > 0) {
  236. $warningsEl.removeClass('hidden');
  237. hasMessages = true;
  238. }
  239. if ($infoEl.find('li').length > 0) {
  240. $infoEl.removeClass('hidden');
  241. hasMessages = true;
  242. }
  243. if (hasMessages) {
  244. $el.find('.hint').removeClass('hidden');
  245. } else {
  246. var securityWarning = $('#security-warning');
  247. if (securityWarning.children('ul').children().length === 0) {
  248. $('#security-warning-state').find('span').removeClass('hidden');
  249. }
  250. }
  251. });
  252. });