1
0

settings-admin.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. .html('<span class="status indeterminate"></span>' +
  43. data.url +
  44. '<span class="icon icon-delete"></span>')
  45. );
  46. OC.msg.finishedSuccess('#ocFederationAddServer .msg', data.message);
  47. })
  48. .fail(function (jqXHR) {
  49. OC.msg.finishedError('#ocFederationAddServer .msg', JSON.parse(jqXHR.responseText).message);
  50. });
  51. } else if (e.keyCode === 27) { // hide input filed again in ESC
  52. $('#ocFederationAddServerButton').toggleClass('hidden');
  53. $("#serverUrl").toggleClass('hidden');
  54. }
  55. });
  56. // remove trusted server from list
  57. $( "#listOfTrustedServers" ).on('click', 'li > .icon-delete', function() {
  58. var $this = $(this).parent();
  59. var id = $this.attr('id');
  60. $.ajax({
  61. url: OC.generateUrl('/apps/federation/trusted-servers/' + id),
  62. type: 'DELETE',
  63. success: function(response) {
  64. $this.remove();
  65. }
  66. });
  67. });
  68. $("#ocFederationSettings #autoAddServers").change(function() {
  69. $.post(
  70. OC.generateUrl('/apps/federation/auto-add-servers'),
  71. {
  72. autoAddServers: $(this).is(":checked")
  73. }
  74. );
  75. });
  76. });