summaryrefslogtreecommitdiffstats
path: root/extensions/REMO/web/js/payment.js
blob: a03e611fb36db232f0ce77364148966c97f21023 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, v. 2.0. */

var bug_cache = {};

function validateAndSubmit() {
    var alert_text = '';
    if(!isFilledOut('firstname')) alert_text += "Please enter your first name\n";
    if(!isFilledOut('lastname')) alert_text += "Please enter your last name\n";
    if(!isFilledOut('wikiprofile')) alert_text += "Please enter a wiki user profile.\n";
    if(!isFilledOut('wikipage')) alert_text += "Please enter a wiki page address.\n";
    if(!isFilledOut('bug_id')) alert_text += "Please enter a valid bug id to attach this additional information to.\n";
    if(!isFilledOut('expenseform')) alert_text += "Please enter an expense form to upload.\n";
    if(!isFilledOut('receipts')) alert_text += "Please enter a receipts file to upload.\n";

    if (alert_text) {
        alert(alert_text);
        return false;
    }

    return true;
}

function getBugInfo (evt) {
    var bug_id = parseInt(this.value);
    var div = $("#bug_info");

    if (!bug_id) {
        div.text("");
        return true;
    }
    div.show();

    if (bug_cache[bug_id]) {
        div.text(bug_cache[bug_id]);
        return true;
    }

    div.text('Getting bug info...');

    var url = ("rest/bug/" + bug_id +
               "?include_fields=product,component,status,summary&Bugzilla_api_token=" + BUGZILLA.api_token);
    $.getJSON(url).done(function(data) {
        var bug_message = "";
        if (data) {
            if (data.bugs[0].product !== 'Mozilla Reps'
                || data.bugs[0].component !== 'Budget Requests')
            {
                bug_message = "You can only attach budget payment " +
                    "information to bugs under the product " +
                    "'Mozilla Reps' and component 'Budget Requests'.";
            }
            else {
                bug_message = "Bug " + bug_id + " - " + data.bugs[0].status +
                    " - " + data.bugs[0].summary;
            }
        }
        else {
            bug_message = "Get bug failed: " + data.responseText;
        }
        div.text(bug_message);
        bug_cache[bug_id] = bug_message;
    }).fail(function(res, x, y) {
        if (res.responseJSON && res.responseJSON.error) {
            div.text(res.responseJSON.message);
        }
    });
    return true;
}

$(document).ready(function () {
    $("#bug_id").blur(getBugInfo);
    $("#receivedpayment").change(function() {
        if (!$('#receivedpayment').is(':checked')) {
            $('#paymentinfo').show();
        }
        else {
            $('#paymentinfo').hide();
        }
    });
});