File: application.js

package info (click to toggle)
open-build-service 2.7.1-10
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 14,828 kB
  • ctags: 6,326
  • sloc: ruby: 59,758; perl: 44,290; xml: 9,804; sh: 4,639; sql: 1,349; python: 435; makefile: 224; cpp: 46
file content (303 lines) | stat: -rw-r--r-- 10,198 bytes parent folder | download
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery-ui/widgets/menu
//= require jquery-ui/widgets/autocomplete
//= require jquery-ui/widgets/tabs
//= require jquery-ui/widgets/tooltip
//= require jquery.tokeninput
//= require jquery.flot
//= require jquery.flot.resize
//= require jquery.flot.time
//= require jquery.flot.stack.js
//= require jquery.expander.min.js
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require cocoon
//
//= require webui/application/bento/script.js
//= require webui/application/bento/global-navigation.js
//= require webui/application/bento/l10n/global-navigation-data-en_US.js
//= require webui/application/package
//= require webui/application/project
//= require webui/application/request
//= require webui/application/patchinfo
//= require webui/application/comment
//= require webui/application/attribute
//= require webui/application/main
//= require webui/application/repository_tab

// toggle visibility of an element via the CSS "display" property
// -> does NOT reserve the needed space for the element when not displayed
function toggle_display(element_id) {
    if (document.getElementById) {
        element = document.getElementById(element_id);
        if (element.style.display == "none") {
            element.style.display = "block";
        } else {
            element.style.display = "none";
        }
    }
}

// toggle visibility of an element via the CSS "display" property
// -> does NOT reserve the needed space for the element when not displayed
function toggle_display_by_name(element_name) {
    if (document.getElementsByName) {
        elements = document.getElementsByName(element_name);
        for (var i = 0; i < elements.length; i++) {
            if (elements[i].style.display == "none") {
                elements[i].style.display = "inline";
            } else {
                elements[i].style.display = "none";
            }
        }
    }
}

// open url in a new browser instance
function goto_url(url) {
    if (url === '') {
        document.forms[0].reset();
        document.forms[0].elements[0].blur();
        return;
    }
    window.open(url, 'helpwindow', 'toolbar=yes,location=yes,scrollbars=yes');
    document.forms[0].reset();
    document.forms[0].elements[0].blur();
}

function hide_dialog() {
    $(".dialog").hide();
}

function remove_dialog() {
    $(".dialog").remove();
}


function setup_buildresult_tooltip(element_id, url) {
    $('#' + element_id).tooltip({
        content: function () {
            return "<div id='" + element_id + "_tooltip' style='width: 500px;'>loading buildresult...</div>";
        }
    });
    $('#' + element_id).mouseover(function () {
        if ($('#' + element_id + '_tooltip').html() == 'loading buildresult...') {
            $('#' + element_id + '_tooltip').load(url);
        }
    });
}

function fillEmptyFields() {
    if (document.getElementById('username').value === '') {
        document.getElementById('username').value = "_";
    }
    if (document.getElementById('password').value === '') {
        document.getElementById('password').value = "_";
    }
}

function toggleBox(link, box) {
    //calculating offset for displaying popup message
    leftVal = link.position().left + "px";
    topVal = link.position().bottom + "px";
    $(box).css({
        left: leftVal,
        top: topVal
    }).toggle();
}

function toggleCheck(input) {
    if (input.is(":checked")) {
        input.removeAttr("checked");
    } else {
        input.attr("checked", "checked");
    }
}

function project_monitor_ready() {
    /* $(document).click(function() { $(".filterbox").hide(); });
     $(".filteritem input").click(function() { toggleCheck($(this)); toggleCheck($(this)); return true; });
     $(".filteritem").click(function() { toggleCheck($(this).find("input:first")); return false; }); */
    $("#statuslink").click(function () {
        toggleBox($(this), "#statusbox");
        $("#archbox").hide();
        $("#repobox").hide();
        return false;
    });
    $("#archlink").click(function () {
        toggleBox($(this), "#archbox");
        $("#statusbox").hide();
        $("#repobox").hide();
        return false;
    });
    $("#repolink").click(function () {
        toggleBox($(this), "#repobox");
        $("#archbox").hide();
        $("#statusbox").hide();
        return false;
    });

    $("#statusbox_close").click(function () {
        $("#statusbox").hide();
    });
    $("#statusbox_all").click(function () {
        $(".statusitem").attr("checked", "checked");
        return false;
    });
    $("#statusbox_none").click(function () {
        $(".statusitem").attr("checked", false);
        return false;
    });

    $("#archbox_close").click(function () {
        $("#archbox").hide();
    });
    $("#archbox_all").click(function () {
        $(".architem").attr("checked", "checked");
        return false;
    });
    $("#archbox_none").click(function () {
        $(".architem").attr("checked", false);
        return false;
    });

    $("#repobox_close").click(function () {
        $("#repobox").hide();
    });
    $("#repobox_all").click(function () {
        $(".repoitem").attr("checked", "checked");
        return false;
    });
    $("#repobox_none").click(function () {
        $(".repoitem").attr("checked", false);
        return false;
    });
}

function monitor_ready() {
    $(".scheduler_status").hover(
        function () {
            $(this).find(".statustext").fadeIn();
        },
        function () {
            $(this).find(".statustext").hide();
        }
    );
}

function resizeMonitorBoxes() {
    /* needs work */
}

function insertServiceRow() {
    var name = $('#add_new_parameter').value;
    var service = $('#servicename').value;
    var value = $('#add_new_value').value;
    var number = $('#count_parameters').value + 1;

    $('#pTable tr:last').before('<tr class=\"row_' + number + '\">' +
        '<td>' + name + '</td>' +
        '<td id="added_parameter_' + number + '">...</td>' +
        '<td><a href=\"#\" onclick=\"\$(\'tr.row_' + number + '\').remove(); return false;\">X</a></td>' +
        '</tr>');

    document.getElementById('count_parameters').value = number;

    var path = "/package/service_parameter_value?number=" + number + "&servicename=" + encodeURIComponent(service) + "&parameter=" + encodeURIComponent(name) + "&value=" + encodeURIComponent(value) + "&package=<%= CGI.escape(@package.name) %>&project=<%= CGI.escape(@project.name) %>";
    $("#pTable td#added_parameter_" + number).load(path);
}


$(document).ajaxSend(function (event, request, settings) {
    if (typeof(CSRF_PROTECT_AUTH_TOKEN) == "undefined") return;
    // settings.data is a serialized string like "foo=bar&baz=boink" (or null)
    settings.data = settings.data || "";
    settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(CSRF_PROTECT_AUTH_TOKEN);
});

// Could be handy elsewhere ;-)
var URL_REGEX = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;

// jquery.dataTables setup:
$(document).ready(function () {
    $.extend($.fn.dataTable.defaults, {
        'iDisplayLength': 25,
    });
});

function change_role(obj) {
    var td = obj.parent("td");
    var type = td.data("type");
    var role = td.data("role");

    var url;
    data = {project: $('#involved_users').data("project"), package: $('#involved_users').data("package"), role: role};
    data[type + 'id'] = td.data(type);
    if (obj.is(':checked')) {
        url = $('#involved_users').data("save-" + type);
    } else {
        url = $('#involved_users').data("remove");
    }

    $('#' + type + '_spinner').show();
    $('#' + type + '_table input').animate({opacity: 0.2}, 500);
    $('#' + type + '_table input').attr("disabled", "true");

    $.ajax({
        url: url,
        type: 'POST',
        data: data,
        complete: function () {
            $('#' + type + '_spinner').hide();
            $('#' + type + '_table input').animate({opacity: 1}, 200);
            $('#' + type + '_table input').removeAttr('disabled');
        }
    });
}

function collapse_expand(file_id) {
    placeholder = $('#diff_view_' + file_id + '_placeholder');
    if (placeholder.attr('id')) {
        $.ajax({
            url: placeholder.parents('.table_wrapper').data("url"),
            type: 'POST',
            data: { text: placeholder.text(), uid: placeholder.data('uid') },
            success: function (data) {
                $('#diff_view_' + file_id).show();
                $('#diff_view_' + file_id + '_placeholder').html(data);
                $('#diff_view_' + file_id + '_placeholder').attr('id', '');
                use_codemirror(placeholder.data('uid'), true, placeholder.data("mode"));
                $('#collapse_' + file_id).show();
                $('#expand_' + file_id).hide();
            },
            error: function (data) {
                $('#diff_view_' + file_id).hide();
                $('#collapse_' + file_id).hide();
                $('#expand_' + file_id).show();
            },
        });
    } else {
        $('#diff_view_' + file_id).toggle();
        $('#collapse_' + file_id).toggle();
        $('#expand_' + file_id).toggle();
    }
}

// used in testing
function select_from_autocomplete(toselect) {
    $('ul.ui-autocomplete li.ui-menu-item a').each(function (index) {
        if ($(this).text() == toselect) { $(this).trigger('mouseenter').click(); }
    });
}