summaryrefslogtreecommitdiff
path: root/frontend/repo-create.js
blob: e2744be3965b2cc38761ff1113d183f90e648625 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$(function () {
    $('#the_form').submit(function() {
	var repo_name;
        $('#message').hide();
        $('#submit')[0].disabled = true;
        $('#spinner').show();

	repo_name = this["name"].value;
        $.xmlrpc({
            url: 'api',
            methodName: 'create_repo',
            params: [
                'sublab',
                repo_name,
                this["description"].value
            ],

            success: function(response, status, jqXHR) {
                var error;

                $('#spinner').hide();
                $('#submit')[0].disabled = false;

                if (response != 'SUCCESS') {
                    error = 'Unknown error ' + response
                    if (response == 'ERROR_NAME')
                        error = 'Invalid name';
                    if (response == 'ERROR_DESC')
                        error = 'Invalid description';
                    if (response == 'ERROR_EXISTS')
                        error = 'Repository does already exist';
                    if (response == 'ERROR_GITOLIE')
                        error = 'Couldn\'t change gitolite config';
                    if (response == 'ERROR_CGIT')
                        error = 'Couldn\'t change cgit config';
                    $('#message').text('Error creating repository: '
                                       + error).show();
                    return;
                }

                $('#the_form').hide(400);
                $('#message').text('Repository created successfuly. You will'
                                   + ' be redirected shortly.').show();
		setTimeout(function() {
		    window.location.href = 'https://git.sublab.org/' + repo_name + '/';
		}, 3000);
            },
            error: function(jqXHR, status, error) {
                $('#message').text('Coulnd\'t create Repo: ' + error);
            }
        });
        return false;
    });
    $('#message').hide();
    $('#the_form').show();
});