summaryrefslogtreecommitdiffstats
path: root/js/pkgsubmit.js
blob: d5f69314cbde03f1a2236a1e8cbe32551516e1fe (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function isLogFile(path) {

    var ext = path.split(".").pop();
    if (["log", "done", "youri"].indexOf(ext) < 0) {
        return true;
    }

    return false;
}

function isShortFile(path) {

    var ext  = path.split(".").pop();
    var file = path.split("/").pop();

    if (["done"].indexOf(ext) >= 0
        || ["status.log"].indexOf(file) >= 0) {
        return true;
    }

    return false;
}

$(function () {

    $('.status-link').on("click", function (ev) {
        if (!ev.metaKey) {
            ev.preventDefault();

            var key  = $(this).attr("href");
            var elId = 'e' + key.replace(/\/|\./g, '-');
            var el   = $("#" + elId);

            if (el.length == 0) {
                $(this).parent().parent().after($("<tr />",
                    {
                        class: "build-files-list",
                        id: elId,
                        html: '<td colspan="4">loading</td>'
                    }
                ));
                $.get(
                    "/log_files.php",
                    {"k": $(this).attr("href")},
                    function (data) {
                        $("#" + elId).html('<td colspan="4">' + data + '</td>');
                    }
                );
            } else {
                el.toggle();
            }
        }
    });

    $("table#submitted-packages tbody").on("click", "tr td li a.view-inline", function (ev) {

        if (isLogFile($(this).attr("href"))) {
            return true;
        }

        if (!ev.metaKey) {
            ev.preventDefault();

            var elId = 'view-' + $(this).attr("href").replace(/\/|\./g, '-');
            var cId  = elId + '-container';
            var c    = $("#" + cId);
            var el   = $("#" + elId);

            if (c.length == 0) {
                $(this).after($("<div />", {
                        id: cId
                    })
                    .addClass(isShortFile($(this).attr("href")) ? "short" : "")
                    .append($("<textarea />", {
                        id: elId,
                        class: "file-view",
                        html: "loading..."
                    }))
                );

                $.get(
                    "/" + $(this).attr("href"),
                    {},
                    function (data) {
                        $("#" + elId).html(data)
                        .before(
                            $("<div />", {
                                class: "controls"
                            })
                            .append($("<button />", {
                                    class: "gototop",
                                    html: "top"
                                }).on("click", function (ev) {
                                    $("#" + elId).animate({ scrollTop: 0 }, 200);
                                })
                            )
                            .append($("<button />", {
                                    class: "gotobo",
                                    html: "bottom"
                                }).on("click", function (ev) {
                                    var d = $("#" + elId);
                                    d.animate({ scrollTop: d.prop("scrollHeight") }, 200);
                                })
                            )
                        )
                    }
                );
            } else {
                c.toggle();
            }
        }
    });
});