admin.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. $(document).ready(function(){
  2. $('#excludedGroups').each(function (index, element) {
  3. OC.Settings.setupGroupsSelect($(element));
  4. $(element).change(function(ev) {
  5. var groups = ev.val || [];
  6. groups = JSON.stringify(groups);
  7. OCP.AppConfig.setValue('core', $(this).attr('name'), groups);
  8. });
  9. });
  10. $('#loglevel').change(function(){
  11. $.post(OC.generateUrl('/settings/admin/log/level'), {level: $(this).val()},function(){
  12. OC.Log.reload();
  13. } );
  14. });
  15. $('#backgroundjobs span.crondate').tooltip({placement: 'top'});
  16. $('#backgroundjobs input').change(function(){
  17. if($(this).is(':checked')){
  18. var mode = $(this).val();
  19. if (mode === 'ajax' || mode === 'webcron' || mode === 'cron') {
  20. OCP.AppConfig.setValue('core', 'backgroundjobs_mode', mode, {
  21. success: function() {
  22. // clear cron errors on background job mode change
  23. OCP.AppConfig.deleteKey('core', 'cronErrors');
  24. }
  25. });
  26. }
  27. }
  28. });
  29. $('#shareAPIEnabled').change(function() {
  30. $('#shareAPI p:not(#enable)').toggleClass('hidden', !this.checked);
  31. });
  32. $('#enableEncryption').change(function() {
  33. $('#encryptionAPI div#EncryptionWarning').toggleClass('hidden');
  34. });
  35. $('#reallyEnableEncryption').click(function() {
  36. $('#encryptionAPI div#EncryptionWarning').toggleClass('hidden');
  37. $('#encryptionAPI div#EncryptionSettingsArea').toggleClass('hidden');
  38. OCP.AppConfig.setValue('core', 'encryption_enabled', 'yes');
  39. $('#enableEncryption').attr('disabled', 'disabled');
  40. });
  41. $('#startmigration').click(function(event){
  42. $(window).on('beforeunload.encryption', function(e) {
  43. return t('settings', 'Migration in progress. Please wait until the migration is finished');
  44. });
  45. event.preventDefault();
  46. $('#startmigration').prop('disabled', true);
  47. OC.msg.startAction('#startmigration_msg', t('settings', 'Migration started …'));
  48. $.post(OC.generateUrl('/settings/admin/startmigration'), '', function(data){
  49. OC.msg.finishedAction('#startmigration_msg', data);
  50. if (data['status'] === 'success') {
  51. $('#encryptionAPI div#selectEncryptionModules').toggleClass('hidden');
  52. $('#encryptionAPI div#migrationWarning').toggleClass('hidden');
  53. } else {
  54. $('#startmigration').prop('disabled', false);
  55. }
  56. $(window).off('beforeunload.encryption');
  57. });
  58. });
  59. $('#shareapiExpireAfterNDays').on('input', function() {
  60. this.value = this.value.replace(/\D/g, '');
  61. });
  62. $('#shareAPI input:not(.noJSAutoUpdate)').change(function() {
  63. var value = $(this).val();
  64. if ($(this).attr('type') === 'checkbox') {
  65. if (this.checked) {
  66. value = 'yes';
  67. } else {
  68. value = 'no';
  69. }
  70. }
  71. OCP.AppConfig.setValue('core', $(this).attr('name'), value);
  72. });
  73. $('#shareapiDefaultExpireDate').change(function() {
  74. $("#setDefaultExpireDate").toggleClass('hidden', !this.checked);
  75. });
  76. $('#publicShareDisclaimer').change(function() {
  77. $("#publicShareDisclaimerText").toggleClass('hidden', !this.checked);
  78. if(!this.checked) {
  79. savePublicShareDisclaimerText('');
  80. }
  81. });
  82. $('#shareApiDefaultPermissionsSection input').change(function(ev) {
  83. var $el = $('#shareApiDefaultPermissions');
  84. var $target = $(ev.target);
  85. var value = $el.val();
  86. if ($target.is(':checked')) {
  87. value = value | $target.val();
  88. } else {
  89. value = value & ~$target.val();
  90. }
  91. // always set read permission
  92. value |= OC.PERMISSION_READ;
  93. // this will trigger the field's change event and will save it
  94. $el.val(value).change();
  95. ev.preventDefault();
  96. return false;
  97. });
  98. var savePublicShareDisclaimerText = _.debounce(function(value) {
  99. var options = {
  100. success: function() {
  101. OC.msg.finishedSuccess('#publicShareDisclaimerStatus', t('core', 'Saved'));
  102. },
  103. error: function() {
  104. OC.msg.finishedError('#publicShareDisclaimerStatus', t('core', 'Not saved'));
  105. }
  106. };
  107. OC.msg.startSaving('#publicShareDisclaimerStatus');
  108. if (_.isString(value) && value !== '') {
  109. OCP.AppConfig.setValue('core', 'shareapi_public_link_disclaimertext', value, options);
  110. } else {
  111. $('#publicShareDisclaimerText').val('');
  112. OCP.AppConfig.deleteKey('core', 'shareapi_public_link_disclaimertext', options);
  113. }
  114. }, 500);
  115. $('#publicShareDisclaimerText').on('change, keyup', function() {
  116. savePublicShareDisclaimerText(this.value);
  117. });
  118. $('#allowLinks').change(function() {
  119. $("#publicLinkSettings").toggleClass('hidden', !this.checked);
  120. $('#setDefaultExpireDate').toggleClass('hidden', !(this.checked && $('#shareapiDefaultExpireDate')[0].checked));
  121. });
  122. $('#mail_smtpauth').change(function() {
  123. if (!this.checked) {
  124. $('#mail_credentials').addClass('hidden');
  125. } else {
  126. $('#mail_credentials').removeClass('hidden');
  127. }
  128. });
  129. $('#mail_smtpmode').change(function() {
  130. if ($(this).val() !== 'smtp') {
  131. $('#setting_smtpauth').addClass('hidden');
  132. $('#setting_smtphost').addClass('hidden');
  133. $('#mail_smtpsecure_label').addClass('hidden');
  134. $('#mail_smtpsecure').addClass('hidden');
  135. $('#mail_credentials').addClass('hidden');
  136. $('#mail_sendmailmode_label, #mail_sendmailmode').removeClass('hidden');
  137. } else {
  138. $('#setting_smtpauth').removeClass('hidden');
  139. $('#setting_smtphost').removeClass('hidden');
  140. $('#mail_smtpsecure_label').removeClass('hidden');
  141. $('#mail_smtpsecure').removeClass('hidden');
  142. if ($('#mail_smtpauth').is(':checked')) {
  143. $('#mail_credentials').removeClass('hidden');
  144. }
  145. $('#mail_sendmailmode_label, #mail_sendmailmode').addClass('hidden');
  146. }
  147. });
  148. var changeEmailSettings = function() {
  149. if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  150. OC.PasswordConfirmation.requirePasswordConfirmation(changeEmailSettings);
  151. return;
  152. }
  153. OC.msg.startSaving('#mail_settings_msg');
  154. $.ajax({
  155. url: OC.generateUrl('/settings/admin/mailsettings'),
  156. type: 'POST',
  157. data: $('#mail_general_settings_form').serialize(),
  158. success: function(){
  159. OC.msg.finishedSuccess('#mail_settings_msg', t('settings', 'Saved'));
  160. },
  161. error: function(xhr){
  162. OC.msg.finishedError('#mail_settings_msg', xhr.responseJSON);
  163. }
  164. });
  165. };
  166. var toggleEmailCredentials = function() {
  167. if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  168. OC.PasswordConfirmation.requirePasswordConfirmation(toggleEmailCredentials);
  169. return;
  170. }
  171. OC.msg.startSaving('#mail_settings_msg');
  172. $.ajax({
  173. url: OC.generateUrl('/settings/admin/mailsettings/credentials'),
  174. type: 'POST',
  175. data: $('#mail_credentials_settings').serialize(),
  176. success: function(){
  177. OC.msg.finishedSuccess('#mail_settings_msg', t('settings', 'Saved'));
  178. },
  179. error: function(xhr){
  180. OC.msg.finishedError('#mail_settings_msg', xhr.responseJSON);
  181. }
  182. });
  183. };
  184. $('#mail_general_settings_form').change(changeEmailSettings);
  185. $('#mail_credentials_settings_submit').click(toggleEmailCredentials);
  186. $('#mail_smtppassword').click(function() {
  187. if (this.type === 'text' && this.value === '********') {
  188. this.type = 'password';
  189. this.value = '';
  190. }
  191. });
  192. $('#sendtestemail').click(function(event){
  193. event.preventDefault();
  194. OC.msg.startAction('#sendtestmail_msg', t('settings', 'Sending…'));
  195. $.ajax({
  196. url: OC.generateUrl('/settings/admin/mailtest'),
  197. type: 'POST',
  198. success: function(){
  199. OC.msg.finishedSuccess('#sendtestmail_msg', t('settings', 'Email sent'));
  200. },
  201. error: function(xhr){
  202. OC.msg.finishedError('#sendtestmail_msg', xhr.responseJSON);
  203. }
  204. });
  205. });
  206. $('#allowGroupSharing').change(function() {
  207. $('#allowGroupSharing').toggleClass('hidden', !this.checked);
  208. });
  209. $('#shareapiExcludeGroups').change(function() {
  210. $("#selectExcludedGroups").toggleClass('hidden', !this.checked);
  211. });
  212. var setupChecks = function () {
  213. // run setup checks then gather error messages
  214. $.when(
  215. OC.SetupChecks.checkWebDAV(),
  216. OC.SetupChecks.checkWellKnownUrl('/.well-known/webfinger', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true && !!oc_appconfig.core.public_webfinger, [200, 501]),
  217. OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
  218. OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
  219. OC.SetupChecks.checkSetup(),
  220. OC.SetupChecks.checkGeneric(),
  221. OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/Nunito-Regular.woff2'), oc_defaults.docPlaceholderUrl),
  222. OC.SetupChecks.checkDataProtected()
  223. ).then(function (check1, check2, check3, check4, check5, check6, check7, check8) {
  224. var messages = [].concat(check1, check2, check3, check4, check5, check6, check7, check8);
  225. var $el = $('#postsetupchecks');
  226. $('#security-warning-state-loading').addClass('hidden');
  227. var hasMessages = false;
  228. var $errorsEl = $el.find('.errors');
  229. var $warningsEl = $el.find('.warnings');
  230. var $infoEl = $el.find('.info');
  231. for (var i = 0; i < messages.length; i++) {
  232. switch (messages[i].type) {
  233. case OC.SetupChecks.MESSAGE_TYPE_INFO:
  234. $infoEl.append('<li>' + messages[i].msg + '</li>');
  235. break;
  236. case OC.SetupChecks.MESSAGE_TYPE_WARNING:
  237. $warningsEl.append('<li>' + messages[i].msg + '</li>');
  238. break;
  239. case OC.SetupChecks.MESSAGE_TYPE_ERROR:
  240. default:
  241. $errorsEl.append('<li>' + messages[i].msg + '</li>');
  242. }
  243. }
  244. if ($errorsEl.find('li').length > 0) {
  245. $errorsEl.removeClass('hidden');
  246. hasMessages = true;
  247. }
  248. if ($warningsEl.find('li').length > 0) {
  249. $warningsEl.removeClass('hidden');
  250. hasMessages = true;
  251. }
  252. if ($infoEl.find('li').length > 0) {
  253. $infoEl.removeClass('hidden');
  254. hasMessages = true;
  255. }
  256. if (hasMessages) {
  257. $('#postsetupchecks-hint').removeClass('hidden');
  258. if ($errorsEl.find('li').length > 0) {
  259. $('#security-warning-state-failure').removeClass('hidden');
  260. } else {
  261. $('#security-warning-state-warning').removeClass('hidden');
  262. }
  263. } else {
  264. var securityWarning = $('#security-warning');
  265. if (securityWarning.children('ul').children().length === 0) {
  266. $('#security-warning-state-ok').removeClass('hidden');
  267. } else {
  268. $('#security-warning-state-failure').removeClass('hidden');
  269. }
  270. }
  271. });
  272. };
  273. if (document.getElementById('security-warning') !== null) {
  274. setupChecks();
  275. }
  276. // server info
  277. var serverInfoForm = $('#server-info-form');
  278. var serverInfoWorkingTimeoutHandle;
  279. var serverInfoSubmitButton = $('#server-info-submit-button');
  280. /**
  281. * Sets the server info submit button state to default.
  282. */
  283. function setServerInfoButtonDefault() {
  284. serverInfoSubmitButton.removeClass('button-success');
  285. serverInfoSubmitButton.removeClass('button-error');
  286. serverInfoSubmitButton.removeClass('button-working');
  287. }
  288. /**
  289. * Sets the server info submit button state to working.
  290. */
  291. function setServerInfoButtonWorking() {
  292. serverInfoSubmitButton.removeClass('button-success');
  293. serverInfoSubmitButton.removeClass('button-error');
  294. serverInfoSubmitButton.addClass('button-working');
  295. }
  296. /**
  297. * Sets the server info submit button state to success.
  298. */
  299. function setServerInfoButtonSuccess() {
  300. serverInfoSubmitButton.removeClass('button-error');
  301. serverInfoSubmitButton.removeClass('button-working');
  302. serverInfoSubmitButton.addClass('button-success');
  303. }
  304. /**
  305. * Sets the server info submit button state to error.
  306. */
  307. function setServerInfoButtonError() {
  308. serverInfoSubmitButton.removeClass('button-success');
  309. serverInfoSubmitButton.removeClass('button-working');
  310. serverInfoSubmitButton.addClass('button-error');
  311. }
  312. /**
  313. * Clears the server info working timeout, if present.
  314. */
  315. function clearServerInfoWorkingTimeout() {
  316. if (serverInfoWorkingTimeoutHandle) {
  317. clearTimeout(serverInfoWorkingTimeoutHandle);
  318. serverInfoWorkingTimeoutHandle = undefined;
  319. }
  320. }
  321. /**
  322. * Unlocks the server info form, e.g. removing readonly from inputs.
  323. */
  324. function unlockForm() {
  325. serverInfoForm.find('input, select').prop('readonly', false);
  326. serverInfoSubmitButton.prop('disabled', false);
  327. }
  328. /**
  329. * Resets the submit button state one of the form elements is changed.
  330. */
  331. serverInfoForm.find('input, select').on('keyup change', function() {
  332. setServerInfoButtonDefault();
  333. });
  334. /**
  335. * Handles the server info form submit.
  336. */
  337. serverInfoForm.on('submit', function(event) {
  338. event.stopImmediatePropagation();
  339. event.preventDefault();
  340. serverInfoForm.find('input, select').prop('readonly', true);
  341. serverInfoSubmitButton.prop('disabled', true);
  342. clearServerInfoWorkingTimeout();
  343. // start show spinner only if request takes longer than one second
  344. serverInfoWorkingTimeoutHandle = setTimeout(function() {
  345. setServerInfoButtonWorking();
  346. }, 1000);
  347. $.ajax({
  348. url: OC.generateUrl('/settings/serverinfo'),
  349. type: 'POST',
  350. data: serverInfoForm.serialize(),
  351. success: function() {
  352. clearServerInfoWorkingTimeout();
  353. setServerInfoButtonSuccess();
  354. unlockForm();
  355. serverInfoSubmitButton.blur();
  356. },
  357. error: function() {
  358. clearServerInfoWorkingTimeout();
  359. setServerInfoButtonError();
  360. unlockForm();
  361. serverInfoSubmitButton.blur();
  362. }
  363. });
  364. });
  365. });