summaryrefslogtreecommitdiffstats
path: root/extensions/REMO/web/js/moz_reps.js
blob: fa29f512a0612d7d80149014b7724df3ca5521d2 (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
/* 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. */

$(document).ready(function() {
    'use strict';

    var first_time = $("#first_time");
    first_time.prop("checked", true);
    first_time.change(function(evt) {
        if (!this.checked) {
            $("#prior_bug").show();
            $("#prior_bug label").addClass("required");
        }
        else {
            $("#prior_bug").hide();
            $("#prior_bug label").removeClass("required");
        }
    }).change();

    $("#underage").change(function(evt) {
        if (this.checked) {
            $('#underage_warning').show();
            $('#submit').prop("disabled", true);
        }
        else {
            $('#underage_warning').hide();
            $('#submit').prop("disabled", false);
        }
    }).change();

    $("#privacy").change(function(evt) {
        if (this.checked) {
            $('#submit').prop("disabled", false);
        }
        else {
            $('#submit').prop("disabled", true);
        }
    }).change();

    $('#tmRequestForm').submit(function (event) {
        var mozillian_re = /^https?:\/\/(www\.)?mozillians.org\/([^\/]+\/)?u\/[^\/]+\/?$/i;
        var errors = [];
        var missing = false;

        $('label.required').each(function (index) {
            var id = $(this).attr("for");
            var input = $("#" + id);
            var value = input.val().trim();

            if (id == 'mozillian') {
                if (!value.match(mozillian_re)) {
                    input.addClass("missing");
                    errors.push("The Mozillian Account URL is invalid");
                    event.preventDefault();
                }
                else {
                    input.removeClass("missing");
                }
            }
            else {
                if (value == "") {
                    input.addClass("missing");
                    missing = true;
                    event.preventDefault();
                }
                else {
                    input.removeClass("missing");
                }
            }
        });

        if (missing) {
            errors.push("There are missing required fields");
        }

        if (errors.length) {
            alert(errors.join("\n"));
        }

        $('#short_desc').val(
            "Application Form: " + $('#first_name').val() + ' ' + $('#last_name').val()
        );
    });
});