You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings-admin.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. (function( $ ) {
  21. // ocFederationAddServer
  22. $.fn.ocFederationAddServer = function() {
  23. /* Go easy on jquery and define some vars
  24. ========================================================================== */
  25. var $wrapper = $(this),
  26. // Buttons
  27. $btnAddServer = $wrapper.find("#ocFederationAddServerButton"),
  28. $btnSubmit = $wrapper.find("#ocFederationSubmit"),
  29. // Inputs
  30. $inpServerUrl = $wrapper.find("#serverUrl"),
  31. // misc
  32. $msgBox = $wrapper.find("#ocFederationAddServer .msg"),
  33. $srvList = $wrapper.find("#listOfTrustedServers");
  34. /* Interaction
  35. ========================================================================== */
  36. $btnAddServer.on('click', function() {
  37. $btnAddServer.addClass('hidden');
  38. $wrapper.find(".serverUrl").removeClass('hidden');
  39. $inpServerUrl
  40. .focus();
  41. });
  42. // trigger server removal
  43. $srvList.on('click', 'li > .icon-delete', function() {
  44. var $this = $(this).parent();
  45. var id = $this.attr('id');
  46. removeServer( id );
  47. });
  48. $btnSubmit.on("click", function()
  49. {
  50. addServer($inpServerUrl.val());
  51. });
  52. $inpServerUrl.on("change keyup", function (e) {
  53. console.log("typing away");
  54. var url = $(this).val();
  55. // toggle add-button visibility based on input length
  56. if ( url.length > 0 )
  57. $btnSubmit.removeClass("hidden")
  58. else
  59. $btnSubmit.addClass("hidden")
  60. if (e.keyCode === 13) { // add server on "enter"
  61. addServer(url);
  62. } else if (e.keyCode === 27) { // hide input filed again in ESC
  63. $btnAddServer.removeClass('hidden');
  64. $inpServerUrl.val("").addClass('hidden');
  65. $btnSubmit.addClass('hidden');
  66. }
  67. });
  68. };
  69. /* private Functions
  70. ========================================================================== */
  71. function addServer( url ) {
  72. OC.msg.startSaving('#ocFederationAddServer .msg');
  73. $.post(
  74. OC.generateUrl('/apps/federation/trusted-servers'),
  75. {
  76. url: url
  77. }
  78. ).done(function (data) {
  79. $("#serverUrl").attr('value', '');
  80. $("#listOfTrustedServers").prepend(
  81. $('<li>')
  82. .attr('id', data.id)
  83. .html('<span class="status indeterminate"></span>' +
  84. data.url +
  85. '<span class="icon icon-delete"></span>')
  86. );
  87. OC.msg.finishedSuccess('#ocFederationAddServer .msg', data.message);
  88. })
  89. .fail(function (jqXHR) {
  90. OC.msg.finishedError('#ocFederationAddServer .msg', JSON.parse(jqXHR.responseText).message);
  91. });
  92. };
  93. function removeServer( id ) {
  94. $.ajax({
  95. url: OC.generateUrl('/apps/federation/trusted-servers/' + id),
  96. type: 'DELETE',
  97. success: function(response) {
  98. $("#ocFederationSettings").find("#" + id).remove();
  99. }
  100. });
  101. }
  102. })( jQuery );
  103. window.addEventListener('DOMContentLoaded', function () {
  104. $('#ocFederationSettings').ocFederationAddServer();
  105. });