Passed
Push — master ( 62d7d9...8230b1 )
by Alexander
03:29
created

mutable.js ➔ populateProductVersion   C

Complexity

Conditions 9

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
rs 6.6666
c 0
b 0
f 0
cc 9
1
$(document).ready((function () {
2
    if ($('#id_version').find('option').length === 0) {
3
        populateProductVersion();
4
    }
5
6
    $('#add_id_product').click(function () {
7
        return showRelatedObjectPopup(this);
8
    });
9
10
    $('#add_id_version').click(function () {
11
        return showRelatedObjectPopup(this);
12
    });
13
14
    $('#add_id_build').click(function() {
15
        return showRelatedObjectPopup(this);
16
    });
17
18
    document.getElementById('id_product').onchange = function () {
19
        $('#id_product').selectpicker('refresh');
20
        populateProductVersion();
21
    };
22
23
    document.getElementById('id_version').onchange = function () {
24
        $('#id_version').selectpicker('refresh');
25
    }
26
27
    document.getElementById('id_build').onchange = function() {
28
        $('#id_build').selectpicker('refresh');
29
    };
30
}));
31
32
// TODO: this entire file is mostly duplicate with testplans/js/mutable.js
33
function populateProductVersion() {
34
    let product_id = $('#id_product').val();
35
36
    let href = $('#add_id_version')[0].href;
37
    $('#add_id_version')[0].href = href.slice(0, href.indexOf('&product'));
38
    $('#add_id_version')[0].href += `&product=${product_id}`;
39
    $('#id_version').find('option').remove();
40
    update_version_select_from_product();
41
42
    let build_href = $('#add_id_build')[0].href;
43
    $('#add_id_build')[0].href = build_href.slice(0, build_href.indexOf('&product'));
44
    $('#add_id_build')[0].href += `&product=${product_id}`;
45
    update_build_select_from_product();
46
}
47