summaryrefslogtreecommitdiffstats
path: root/extensions/BugModal/web/new_bug.js
blob: d00770e3a7d05f2532c445f24d401729dc253907 (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
var initial = {}
var comp_desc = {}

$(document).ready(function() {
    bugzilla_ajax(
            {
                url: 'rest/bug_modal/initial_field_values'
            },
            function(data) {
                initial = data
            },
            function() {
                alert("Network issues. Please refresh the page and try again");
            }
        );
    var product_sel = $("#product").selectize({
        valueField: 'name',
        labelField: 'name',
        searchField: 'name',
        options: [],
        preload: true,
        create: false,
        load: function(query, callback) {
            callback(initial.products);
        }
    });
    var component_sel = $("#component").selectize({
        valueField: 'name',
        labelField: 'name',
        searchField: 'name',
        options: [],
    });

    var version_sel = $("#version").selectize({
        valueField: 'name',
        labelField: 'name',
        searchField: 'name',
        options: [],
    });

    var keywords_sel = $("#keywords").selectize({
        delimiter: ', ',
        valueField: 'name',
        labelField: 'name',
        searchField: 'name',
        options: [],
        preload: true,
        create: false,
        load: function(query, callback) {
            callback(initial.keywords);
        }
    });

    product_sel.on("change", function () {
        $('#product-throbber').show();
        $('#component').attr('disabled', true);
        bugzilla_ajax(
                {
                    url: 'rest/bug_modal/product_info?product=' + encodeURIComponent($('#product').val())
                },
                function(data) {
                    $('#product-throbber').hide();
                    $('#component').attr('disabled', false);
                    $('#comp_desc').text('Select a component to read its description.');
                    var selectize = $("#component")[0].selectize;
                    selectize.clear();
                    selectize.clearOptions();
                    selectize.load(function(callback) {
                        callback(data.components)
                    });

                    for (var i in data.components)
                        comp_desc[data.components[i]["name"]] = data.components[i]["description"];

                    selectize = $("#version")[0].selectize;
                    selectize.clear();
                    selectize.clearOptions();
                    selectize.load(function(callback) {
                        callback(data.versions);
                    });
                },
                function() {
                    alert("Network issues. Please refresh the page and try again");
                }
            );     
    });

    component_sel.on("change", function () {
        var selectize = $("#component")[0].selectize;
        $('#comp_desc').text(comp_desc[selectize.getValue()]);
    });

    $('.create-btn')
        .click(function(event) {
            event.preventDefault();
            if (document.newbugform.checkValidity && !document.newbugform.checkValidity())
                return;
            this.form.submit()
        });
    
});