admin.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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').change(function() {
  60. var value = $(this).val();
  61. if (value <= 0) {
  62. $(this).val("1");
  63. }
  64. });
  65. $('#shareAPI input:not(.noJSAutoUpdate)').change(function() {
  66. var value = $(this).val();
  67. if ($(this).attr('type') === 'checkbox') {
  68. if (this.checked) {
  69. value = 'yes';
  70. } else {
  71. value = 'no';
  72. }
  73. }
  74. OCP.AppConfig.setValue('core', $(this).attr('name'), value);
  75. });
  76. $('#shareapiDefaultExpireDate').change(function() {
  77. $("#setDefaultExpireDate").toggleClass('hidden', !this.checked);
  78. });
  79. $('#publicShareDisclaimer').change(function() {
  80. $("#publicShareDisclaimerText").toggleClass('hidden', !this.checked);
  81. if(!this.checked) {
  82. savePublicShareDisclaimerText('');
  83. }
  84. });
  85. $('#shareApiDefaultPermissionsSection input').change(function(ev) {
  86. var $el = $('#shareApiDefaultPermissions');
  87. var $target = $(ev.target);
  88. var value = $el.val();
  89. if ($target.is(':checked')) {
  90. value = value | $target.val();
  91. } else {
  92. value = value & ~$target.val();
  93. }
  94. // always set read permission
  95. value |= OC.PERMISSION_READ;
  96. // this will trigger the field's change event and will save it
  97. $el.val(value).change();
  98. ev.preventDefault();
  99. return false;
  100. });
  101. var savePublicShareDisclaimerText = _.debounce(function(value) {
  102. var options = {
  103. success: function() {
  104. OC.msg.finishedSuccess('#publicShareDisclaimerStatus', t('core', 'Saved'));
  105. },
  106. error: function() {
  107. OC.msg.finishedError('#publicShareDisclaimerStatus', t('core', 'Not saved'));
  108. }
  109. };
  110. OC.msg.startSaving('#publicShareDisclaimerStatus');
  111. if (_.isString(value) && value !== '') {
  112. OCP.AppConfig.setValue('core', 'shareapi_public_link_disclaimertext', value, options);
  113. } else {
  114. $('#publicShareDisclaimerText').val('');
  115. OCP.AppConfig.deleteKey('core', 'shareapi_public_link_disclaimertext', options);
  116. }
  117. }, 500);
  118. $('#publicShareDisclaimerText').on('change, keyup', function() {
  119. savePublicShareDisclaimerText(this.value);
  120. });
  121. $('#allowLinks').change(function() {
  122. $("#publicLinkSettings").toggleClass('hidden', !this.checked);
  123. $('#setDefaultExpireDate').toggleClass('hidden', !(this.checked && $('#shareapiDefaultExpireDate')[0].checked));
  124. });
  125. $('#mail_smtpauth').change(function() {
  126. if (!this.checked) {
  127. $('#mail_credentials').addClass('hidden');
  128. } else {
  129. $('#mail_credentials').removeClass('hidden');
  130. }
  131. });
  132. $('#mail_smtpmode').change(function() {
  133. if ($(this).val() !== 'smtp') {
  134. $('#setting_smtpauth').addClass('hidden');
  135. $('#setting_smtphost').addClass('hidden');
  136. $('#mail_smtpsecure_label').addClass('hidden');
  137. $('#mail_smtpsecure').addClass('hidden');
  138. $('#mail_credentials').addClass('hidden');
  139. } else {
  140. $('#setting_smtpauth').removeClass('hidden');
  141. $('#setting_smtphost').removeClass('hidden');
  142. $('#mail_smtpsecure_label').removeClass('hidden');
  143. $('#mail_smtpsecure').removeClass('hidden');
  144. if ($('#mail_smtpauth').is(':checked')) {
  145. $('#mail_credentials').removeClass('hidden');
  146. }
  147. }
  148. });
  149. var changeEmailSettings = function() {
  150. if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  151. OC.PasswordConfirmation.requirePasswordConfirmation(changeEmailSettings);
  152. return;
  153. }
  154. OC.msg.startSaving('#mail_settings_msg');
  155. $.ajax({
  156. url: OC.generateUrl('/settings/admin/mailsettings'),
  157. type: 'POST',
  158. data: $('#mail_general_settings_form').serialize(),
  159. success: function(){
  160. OC.msg.finishedSuccess('#mail_settings_msg', t('settings', 'Saved'));
  161. },
  162. error: function(xhr){
  163. OC.msg.finishedError('#mail_settings_msg', xhr.responseJSON);
  164. }
  165. });
  166. };
  167. var toggleEmailCredentials = function() {
  168. if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  169. OC.PasswordConfirmation.requirePasswordConfirmation(toggleEmailCredentials);
  170. return;
  171. }
  172. OC.msg.startSaving('#mail_settings_msg');
  173. $.ajax({
  174. url: OC.generateUrl('/settings/admin/mailsettings/credentials'),
  175. type: 'POST',
  176. data: $('#mail_credentials_settings').serialize(),
  177. success: function(){
  178. OC.msg.finishedSuccess('#mail_settings_msg', t('settings', 'Saved'));
  179. },
  180. error: function(xhr){
  181. OC.msg.finishedError('#mail_settings_msg', xhr.responseJSON);
  182. }
  183. });
  184. };
  185. $('#mail_general_settings_form').change(changeEmailSettings);
  186. $('#mail_credentials_settings_submit').click(toggleEmailCredentials);
  187. $('#mail_smtppassword').click(function() {
  188. if (this.type === 'text' && this.value === '********') {
  189. this.type = 'password';
  190. this.value = '';
  191. }
  192. });
  193. $('#sendtestemail').click(function(event){
  194. event.preventDefault();
  195. OC.msg.startAction('#sendtestmail_msg', t('settings', 'Sending…'));
  196. $.ajax({
  197. url: OC.generateUrl('/settings/admin/mailtest'),
  198. type: 'POST',
  199. success: function(){
  200. OC.msg.finishedSuccess('#sendtestmail_msg', t('settings', 'Email sent'));
  201. },
  202. error: function(xhr){
  203. OC.msg.finishedError('#sendtestmail_msg', xhr.responseJSON);
  204. }
  205. });
  206. });
  207. $('#allowGroupSharing').change(function() {
  208. $('#allowGroupSharing').toggleClass('hidden', !this.checked);
  209. });
  210. $('#shareapiExcludeGroups').change(function() {
  211. $("#selectExcludedGroups").toggleClass('hidden', !this.checked);
  212. });
  213. // run setup checks then gather error messages
  214. $.when(
  215. OC.SetupChecks.checkWebDAV(),
  216. OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav/', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === 'true'),
  217. OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav/', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === 'true'),
  218. OC.SetupChecks.checkSetup(),
  219. OC.SetupChecks.checkGeneric(),
  220. OC.SetupChecks.checkDataProtected()
  221. ).then(function(check1, check2, check3, check4, check5, check6) {
  222. var messages = [].concat(check1, check2, check3, check4, check5, check6);
  223. var $el = $('#postsetupchecks');
  224. $el.find('.loading').addClass('hidden');
  225. var hasMessages = false;
  226. var $errorsEl = $el.find('.errors');
  227. var $warningsEl = $el.find('.warnings');
  228. var $infoEl = $el.find('.info');
  229. for (var i = 0; i < messages.length; i++ ) {
  230. switch(messages[i].type) {
  231. case OC.SetupChecks.MESSAGE_TYPE_INFO:
  232. $infoEl.append('<li>' + messages[i].msg + '</li>');
  233. break;
  234. case OC.SetupChecks.MESSAGE_TYPE_WARNING:
  235. $warningsEl.append('<li>' + messages[i].msg + '</li>');
  236. break;
  237. case OC.SetupChecks.MESSAGE_TYPE_ERROR:
  238. default:
  239. $errorsEl.append('<li>' + messages[i].msg + '</li>');
  240. }
  241. }
  242. if ($errorsEl.find('li').length > 0) {
  243. $errorsEl.removeClass('hidden');
  244. hasMessages = true;
  245. }
  246. if ($warningsEl.find('li').length > 0) {
  247. $warningsEl.removeClass('hidden');
  248. hasMessages = true;
  249. }
  250. if ($infoEl.find('li').length > 0) {
  251. $infoEl.removeClass('hidden');
  252. hasMessages = true;
  253. }
  254. if (hasMessages) {
  255. $el.find('.hint').removeClass('hidden');
  256. } else {
  257. var securityWarning = $('#security-warning');
  258. if (securityWarning.children('ul').children().length === 0) {
  259. $('#security-warning-state').find('span').removeClass('hidden');
  260. }
  261. }
  262. });
  263. });