Merge branch '11454-wb-federated-search'
[arvados.git] / apps / workbench / app / assets / javascripts / users.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 $(document).
6     on('notifications:recount',
7        function() {
8            var menu = $('.notification-menu');
9            n = $('.notification', menu).not('.empty').length;
10            $('.notification-count', menu).html(n>0 ? n : '');
11        }).
12     on('ajax:success', 'form.new_authorized_key',
13        function(e, data, status, xhr) {
14            $(e.target).parents('.notification').eq(0).fadeOut('slow', function() {
15                $('<li class="alert alert-success daxalert">SSH key added.</li>').hide().replaceAll(this).fadeIn('slow');
16                $(document).trigger('notifications:recount');
17            });
18        }).
19     on('ajax:complete', 'form.new_authorized_key',
20        function(e, data, status, xhr) {
21            $($('input[name=disable_element]', e.target).val()).
22                fadeTo(200, 1.0);
23        }).
24     on('ajax:error', 'form.new_authorized_key',
25        function(e, xhr, status, error) {
26            var error_div;
27            response = $.parseJSON(xhr.responseText);
28            error_div = $(e.target).parent().find('div.ajax-errors');
29            if (error_div.length == 0) {
30                $(e.target).parent().append('<div class="alert alert-error ajax-errors"></div>');
31                error_div = $(e.target).parent().find('div.ajax-errors');
32            }
33            if (response.errors) {
34                error_div.html($('<p/>').text(response.errors).html());
35            } else {
36                error_div.html('<p>Sorry, request failed.</p>');
37            }
38            error_div.show();
39            $($('input[name=disable_element]', e.target).val()).
40                fadeTo(200, 1.0);
41        }).
42     on('click', 'form[data-remote] input[type=submit]',
43        function(e) {
44            $(e.target).parents('form').eq(0).parent().find('div.ajax-errors').html('').hide();
45            $($(e.target).
46              parents('form').
47              find('input[name=disable_element]').
48              val()).
49                fadeTo(200, 0.3);
50            return true;
51        });