summaryrefslogtreecommitdiff
path: root/media/archweb.js
blob: 49f2a319a287846a7264f5a2a16c59d69a6c2cfe (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* tablesorter custom parsers for various pages:
 * devel/index.html, mirrors/status.html, todolists/view.html */
if (typeof $.tablesorter !== 'undefined') {
    $.tablesorter.addParser({
        id: 'pkgcount',
        is: function(s) { return false; },
        format: function(s) {
            var m = s.match(/\d+/);
            return m ? parseInt(m[0]) : 0;
        },
        type: 'numeric'
    });
    $.tablesorter.addParser({
        id: 'todostatus',
        is: function(s) { return false; },
        format: function(s) {
            return s.match(/incomplete/i) ? 1 : 0;
        },
        type: 'numeric'
    });
    $.tablesorter.addParser({
        /* sorts numeric, but put '', 'unknown', and '∞' last. */
        id: 'mostlydigit',
        special: ['', 'unknown', '∞'],
        is: function(s, table) {
            var c = table.config;
            return ($.inArray(s, this.special) > -1) || $.tablesorter.isDigit(s, c);
        },
        format: function(s) {
            if ($.inArray(s, this.special) > -1) return Number.MAX_VALUE;
            return $.tablesorter.formatFloat(s);
        },
        type: 'numeric'
    });
    $.tablesorter.addParser({
        /* sorts duration; put '', 'unknown', and '∞' last. */
        id: 'duration',
        re: /^([0-9]+):([0-5][0-9])$/,
        special: ['', 'unknown', '∞'],
        is: function(s) {
            return ($.inArray(s, this.special) > -1) || this.re.test(s);
        },
        format: function(s) {
            if ($.inArray(s, this.special) > -1) return Number.MAX_VALUE;
            var matches = this.re.exec(s);
            if (!matches) return Number.MAX_VALUE;
            return matches[1] * 60 + matches[2];
        },
        type: 'numeric'
    });
    $.tablesorter.addParser({
        id: 'longDateTime',
        re: /^(\d{4})-(\d{2})-(\d{2}) ([012]\d):([0-5]\d)(:([0-5]\d))?( (\w+))?$/,
        is: function(s) {
            return this.re.test(s);
        },
        format: function(s) {
            var matches = this.re.exec(s);
            if (!matches) return 0;
            /* skip group 6, group 7 is optional seconds */
            if (matches[7] == undefined) matches[7] = 0;
            /* The awesomeness of the JS date constructor. Month needs to be
             * between 0-11, because things have to be difficult. */
            var date = new Date(matches[1], matches[2] - 1, matches[3],
                matches[4], matches[5], matches[7]);
            return $.tablesorter.formatFloat(date.getTime());
        },
        type: 'numeric'
    });
    $.tablesorter.addParser({
        id: 'filesize',
        re: /^(\d+(?:\.\d+)?) (bytes?|KB|MB|GB|TB|PB)$/,
        is: function(s) {
            return this.re.test(s);
        },
        format: function(s) {
            var matches = this.re.exec(s);
            if (!matches) return 0;
            var size = parseFloat(matches[1]);
            var suffix = matches[2];

            switch(suffix) {
                case 'byte':
                case 'bytes':
                    return size;
                case 'KB':
                    return size * 1024;
                case 'MB':
                    return size * 1024 * 1024;
                case 'GB':
                    return size * 1024 * 1024 * 1024;
                case 'TB':
                    return size * 1024 * 1024 * 1024 * 1024;
                case 'PB':
                    return size * 1024 * 1024 * 1024 * 1024 * 1024;
            }
        },
        type: 'numeric'
    });
}

/* news/add.html */
function enablePreview() {
    $('#news-preview-button').click(function(event) {
        event.preventDefault();
        $.post('/news/preview/', {
                data: $('#id_content').val(),
                csrfmiddlewaretoken: $('#newsform input[name=csrfmiddlewaretoken]').val()
            },
            function(data) {
                $('#news-preview-data').html(data);
                $('#news-preview').show();
            }
        );
        $('#news-preview-title').html($('#id_title').val());
    });
}

/* packages/details.html */
function ajaxifyFiles() {
    $('#filelink').click(function(event) {
        event.preventDefault();
        $.get(this.href, function(data) {
            $('#pkgfilelist').html(data);
        });
    });
}

/* packages/differences.html */
function filter_packages() {
    // start with all rows, and then remove ones we shouldn't show
    var rows = $('#tbody_differences').children();
    var all_rows = rows;
    if (!$('#id_multilib').is(':checked')) {
        rows = rows.not('.multilib').not('.multilib-testing');
    }
    var arch = $('#id_archonly').val();
    if (arch !== 'all') {
        rows = rows.filter('.' + arch);
    }
    if (!$('#id_minor').is(':checked')) {
        // this check is done last because it is the most expensive
        var pat = /(.*)-(.+)/;
        rows = rows.filter(function(index) {
            var cells = $(this).children('td');

            // all this just to get the split version out of the table cell
            var ver_a = cells.eq(2).find('span').text().match(pat);
            if (!ver_a) return true;

            var ver_b = cells.eq(3).find('span').text().match(pat);
            if (!ver_b) return true;

            // first check pkgver
            if (ver_a[1] !== ver_b[1]) return true;
            // pkgver matched, so see if rounded pkgrel matches
            if (Math.floor(parseFloat(ver_a[2])) ==
                Math.floor(parseFloat(ver_b[2]))) return false;
            // pkgrel didn't match, so keep the row
            return true;
        });
    }
    // hide all rows, then show the set we care about
    all_rows.hide();
    rows.show();
    // make sure we update the odd/even styling from sorting
    $('.results').trigger('applyWidgets');
}
function filter_reset() {
    $('#id_archonly').val('both');
    $('#id_multilib').removeAttr('checked');
    $('#id_minor').removeAttr('checked');
    filter_packages();
}

/* todolists/view.html */
function todolist_flag() {
    var link = this;
    $.getJSON(link.href, function(data) {
        if (data.complete) {
            $(link).text('Complete').addClass(
                'complete').removeClass('incomplete');
        } else {
            $(link).text('Incomplete').addClass(
                'incomplete').removeClass('complete');
        }
        /* let tablesorter know the cell value has changed */
        $('.results').trigger('updateCell', $(link).closest('td'));
    });
    return false;
}

/* signoffs.html */
function signoff_package() {
    var link = this;
    $.getJSON(link.href, function(data) {
        if (data.created) {
            var signoff = $('<li>').addClass('signed-username').text(data.user);
            $(link).append(signoff);
        }
        /* update the approved column to reflect reality */
        if (data.approved) {
            var approved = $(link).closest('tr').children('.signoff-no');
            approved.text('Yes').addClass(
                'signoff-yes').removeClass('signoff-no');
        } else {
            var approved = $(link).closest('tr').children('.signoff-yes');
            approved.text('No').addClass(
                'signoff-no').removeClass('signoff-yes');
        }
        $('.results').trigger('updateCell', approved);
    });
    return false;
}