123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- (function( $ ) {
-
- $.fn.ocFederationAddServer = function() {
-
- var $wrapper = $(this),
-
- $btnAddServer = $wrapper.find("#ocFederationAddServerButton"),
- $btnSubmit = $wrapper.find("#ocFederationSubmit"),
-
- $inpServerUrl = $wrapper.find("#serverUrl"),
-
- $msgBox = $wrapper.find("#ocFederationAddServer .msg"),
- $srvList = $wrapper.find("#listOfTrustedServers");
-
- $btnAddServer.on('click', function() {
- $btnAddServer.addClass('hidden');
- $wrapper.find(".serverUrl").removeClass('hidden');
- $inpServerUrl
- .focus();
- });
-
- $srvList.on('click', 'li > .icon-delete', function() {
- var $this = $(this).parent();
- var id = $this.attr('id');
- removeServer( id );
- });
- $btnSubmit.on("click", function()
- {
- addServer($inpServerUrl.val());
- });
- $inpServerUrl.on("change keyup", function (e) {
- console.log("typing away");
- var url = $(this).val();
-
- if ( url.length > 0 )
- $btnSubmit.removeClass("hidden")
- else
- $btnSubmit.addClass("hidden")
- if (e.keyCode === 13) {
- addServer(url);
- } else if (e.keyCode === 27) {
- $btnAddServer.removeClass('hidden');
- $inpServerUrl.val("").addClass('hidden');
- $btnSubmit.addClass('hidden');
- }
- });
- };
-
- function addServer( url ) {
- OC.msg.startSaving('#ocFederationAddServer .msg');
- $.post(
- OC.generateUrl('/apps/federation/trusted-servers'),
- {
- url: url
- }
- ).done(function (data) {
- $("#serverUrl").attr('value', '');
- $("#listOfTrustedServers").prepend(
- $('<li>')
- .attr('id', data.id)
- .html('<span class="status indeterminate"></span>' +
- data.url +
- '<span class="icon icon-delete"></span>')
- );
- OC.msg.finishedSuccess('#ocFederationAddServer .msg', data.message);
- })
- .fail(function (jqXHR) {
- OC.msg.finishedError('#ocFederationAddServer .msg', JSON.parse(jqXHR.responseText).message);
- });
- };
- function removeServer( id ) {
- $.ajax({
- url: OC.generateUrl('/apps/federation/trusted-servers/' + id),
- type: 'DELETE',
- success: function(response) {
- $("#ocFederationSettings").find("#" + id).remove();
- }
- });
- }
- })( jQuery );
- window.addEventListener('DOMContentLoaded', function () {
- $('#ocFederationSettings').ocFederationAddServer();
- });
|