diff options
Diffstat (limited to 'apps/federation/js/settings-admin.js')
-rw-r--r-- | apps/federation/js/settings-admin.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/apps/federation/js/settings-admin.js b/apps/federation/js/settings-admin.js new file mode 100644 index 00000000000..a1f02a09efe --- /dev/null +++ b/apps/federation/js/settings-admin.js @@ -0,0 +1,70 @@ +/** + * @author Björn Schießle <schiessle@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +$(document).ready(function () { + + // show input field to add a new trusted server + $("#ocFederationAddServer").on('click', function() { + $('#ocFederationAddServerButton').addClass('hidden'); + $("#serverUrl").removeClass('hidden'); + $("#serverUrl").focus(); + }); + + // add new trusted server + $("#serverUrl").keyup(function (e) { + if (e.keyCode === 13) { // add server on "enter" + var url = $('#serverUrl').val(); + OC.msg.startSaving('#ocFederationAddServer .msg'); + $.post( + OC.generateUrl('/apps/federation/trusted-servers'), + { + url: url + } + ).done(function (data) { + $('#serverUrl').attr('value', ''); + $('ul#listOfTrustedServers').prepend( + $('<li>').attr('id', data.id).text(data.url) + ); + OC.msg.finishedSuccess('#ocFederationAddServer .msg', data.message); + }) + .fail(function (jqXHR) { + OC.msg.finishedError('#ocFederationAddServer .msg', JSON.parse(jqXHR.responseText).message); + }); + } else if (e.keyCode === 27) { // hide input filed again in ESC + $('#ocFederationAddServerButton').toggleClass('hidden'); + $("#serverUrl").toggleClass('hidden'); + } + }); + + // remove trusted server from list + $( "#listOfTrustedServers" ).on('click', 'li', function() { + var id = $(this).attr('id'); + var $this = $(this); + $.ajax({ + url: OC.generateUrl('/apps/federation/trusted-servers/' + id), + type: 'DELETE', + success: function(response) { + $this.remove(); + } + }); + + }); + +}); |