1
0

settings-admin.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * @author Björn Schießle <schiessle@owncloud.com>
  3. *
  4. * @copyright Copyright (c) 2015, ownCloud, Inc.
  5. * @license AGPL-3.0
  6. *
  7. * This code is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License, version 3,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License, version 3,
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>
  18. *
  19. */
  20. $(document).ready(function () {
  21. // show input field to add a new trusted server
  22. $("#ocFederationAddServer").on('click', function() {
  23. $('#ocFederationAddServerButton').addClass('hidden');
  24. $("#serverUrl").removeClass('hidden');
  25. $("#serverUrl").focus();
  26. });
  27. // add new trusted server
  28. $("#serverUrl").keyup(function (e) {
  29. if (e.keyCode === 13) { // add server on "enter"
  30. var url = $('#serverUrl').val();
  31. OC.msg.startSaving('#ocFederationAddServer .msg');
  32. $.post(
  33. OC.generateUrl('/apps/federation/trusted-servers'),
  34. {
  35. url: url
  36. }
  37. ).done(function (data) {
  38. $('#serverUrl').attr('value', '');
  39. $('ul#listOfTrustedServers').prepend(
  40. $('<li>')
  41. .attr('id', data.id)
  42. .attr('class', 'icon-delete')
  43. .html('<span class="status indeterminate"></span>' + data.url)
  44. );
  45. OC.msg.finishedSuccess('#ocFederationAddServer .msg', data.message);
  46. })
  47. .fail(function (jqXHR) {
  48. OC.msg.finishedError('#ocFederationAddServer .msg', JSON.parse(jqXHR.responseText).message);
  49. });
  50. } else if (e.keyCode === 27) { // hide input filed again in ESC
  51. $('#ocFederationAddServerButton').toggleClass('hidden');
  52. $("#serverUrl").toggleClass('hidden');
  53. }
  54. });
  55. // remove trusted server from list
  56. $( "#listOfTrustedServers" ).on('click', 'li', function() {
  57. var id = $(this).attr('id');
  58. var $this = $(this);
  59. $.ajax({
  60. url: OC.generateUrl('/apps/federation/trusted-servers/' + id),
  61. type: 'DELETE',
  62. success: function(response) {
  63. $this.remove();
  64. }
  65. });
  66. });
  67. $("#ocFederationSettings #autoAddServers").change(function() {
  68. $.post(
  69. OC.generateUrl('/apps/federation/auto-add-servers'),
  70. {
  71. autoAddServers: $(this).is(":checked")
  72. }
  73. );
  74. });
  75. });