summaryrefslogtreecommitdiffstats
path: root/extensions/MozProjectReview/web/js/moz_project_review.js
blob: 3d1caf528a564a0f9bde372afe09722c793b2649 (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
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
/* 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.
 */

$(function() {
    'use strict';
    var required_fields = {
        "initial_questions": {
            "comment": "Please enter a value for description in the initial questions section.",
            "key_initiative": "Please select a value for key initiative in the initial questions section.",
            "contract_type": "Please select a value for contract type in the initial questions section.",
            "mozilla_data": "Please select a value for mozilla data in the initial questions section.",
            "vendor_cost": "Please select a value for vendor cost in the initial questions section.",
            "timeframe": "Please select a value for timeframe in the initial questions section.",
            "contract_priority": "Please select a value for priority in the initial questions section.",
            "internal_org": "Please select a value for the internal organization in the initial questions section."
        },
        "key_initiative_other": {
            "key_initiative_other": "Please enter a value for other key initiative in the initial questions section."
        },
        "mozilla_data_explain_row": {
            "mozilla_data_explain": "Please enter a value for mozilla data access explanation in the initial questions section."
        },
        "contract_type_other": {
            "contract_type_other": "Please enter a value for other contract type in the initial questions section."
        },
        "contract_specific_questions": {
            "other_party": "Please enter a value for vendor name in the contract specific questions.",
            "vendor_services_where": "Please enter a value for the where the services will be provided in the contract specific questions.",
        },
        "independent_contractor_questions": {
            "independent_contractor_prev_work": "Please select a value for previous work in the independent contractor section.",
            "independent_contractor_incorporated": "Please select a value for incorporated in the independent contractor section.",
            "independent_contractor_staff_agency": "Please select a value for staffing agency in the independent contractor section.",
            "independent_contractor_other_clients": "Please select a value for other clients in the independent contractor section.",
            "independent_contractor_dupe_services": "Please select a value for in the independent contractor section.",
            "independent_contractor_self_manage": "Please select a value for self management of time in the independent contractor section.",
            "independent_contractor_own_equipment": "Please select a value for use of contractors own equipment in the independent contractor section.",
            "independent_contractor_mozilla_facility": "Please select a value for use of Mozilla facility in the independent contractor section.",
            "independent_contractor_supervising": "Please select a value for contractor supervising Mozilla employees in the independent contractor section.",
        },
        "independent_contractor_prev_work_bug_row": {
            "independent_contractor_prev_work_bug": "Please enter a value for previous work bug id in the independent contractor section."
        },
        "independent_contractor_dupe_services_temp_row": {
            "independent_contractor_dupe_services_temp": "Please select a value for temporarily need duplicate services in the independent contractor section."
        },
        "sow_details": {
            "sow_vendor_address": "Please enter a value for SOW vendor address.",
            "sow_vendor_email": "Please enter a value for SOW vendor email for notices.",
            "sow_vendor_contact": "Please enter a value for SOW vendor contact and email address.",
            "sow_vendor_services": "Please enter a value for SOW vendor services description.",
            "sow_vendor_deliverables": "Please enter a value for SOW vendor deliverables description.",
            "sow_start_date": "Please enter a value for SOW vendor start date.",
            "sow_end_date": "Please enter a value for SOW vendor end date.",
            "sow_vendor_payment": "Please enter a value for SOW vendor payment amount.",
            "sow_vendor_payment_basis": "Please enter a value for SOW vendor payment basis.",
            "sow_vendor_cap_expenses": "Please enter a value for SOW cap on reimbursable expenses.",
            "sow_vendor_payment_schedule": "Please enter a value for SOW vendor payment schedule.",
            "sow_vendor_total_max": "Please enter a value for SOW vendor maximum total to be paid.",
        },
        "sow_vendor_mozilla_systems_explain_row": {
            "sow_vendor_mozilla_systems_explain": "Please enter a value for SOW vendor explanation for use of mozilla systems."
        },
        "sow_vendor_onsite_where_row": {
            "sow_vendor_onsite_where": "Please enter a value for SOW vendor onsite where and when."
        },
        "finance_questions": {
            "finance_purchase_inbudget": "Please enter a value for in budget in the finance questions section.",
            "finance_purchase_what": "Please enter a value for what in the finance questions section.",
            "finance_purchase_why": "Please enter a value for why in the finance questions section.",
            "finance_purchase_risk": "Please enter a value for risk in the finance questions section.",
            "finance_purchase_alternative": "Please enter a value for alternative in the finance questions section.",
        },
        "total_cost_row": {
            "total_cost": "Please enter a value for total cost"
        }
    };

    var select_inputs = [
        'contract_type',
        'independent_contractor_prev_work',
        'independent_contractor_dupe_services',
        'key_initiative',
        'mozilla_data',
        'vendor_cost',
        'sow_vendor_mozilla_systems',
        'sow_vendor_onsite'
    ];

    function init() {
        // Bind the updateSections function to each of the inputs desired
        for (var i = 0, l = select_inputs.length; i < l; i++) {
            $('#' + select_inputs[i]).change(updateSections);
        }
        updateSections();
        $('#mozProjectForm').submit(validateAndSubmit);
    }

    function updateSections(e) {
        if ($('#key_initiative').val() == 'Other') {
            $('#key_initiative_other').show();
            if ($(e.target).attr('id') == 'key_initiative') $('#key_initiative_other').focus();
        } else {
            $('#key_initiative_other').hide();
        }

        if ($('#vendor_cost').val() == '< $25,000 PO Needed'
            || $('#vendor_cost').val() == '> $25,000')
        {
            $('#finance_questions').show();
        } else {
            $('#finance_questions').hide();
        }

        var do_sec_review = [
            'Engaging a new vendor company',
            'Adding a new SOW with a vendor',
            'Extending an SOW or renewing a contract',
            'Purchasing software',
            'Signing up for an online service',
            'Other'
        ];
        var contract_type = $('#contract_type').val();
        if ((contract_type && $.inArray(contract_type, do_sec_review) >= 0)
            || $('#mozilla_data').val() == 'Yes')
        {
            $('#sec_review_questions').show();

        } else {
            $('#sec_review_questions').hide();
        }

        if ($('#mozilla_data').val() == 'Yes') {
            $('#mozilla_data_explain_row').show();
            if ($(e.target).attr('id') == 'mozilla_data') $('#mozilla_data_explain').focus();

        } else {
            $('#mozilla_data_explain_row').hide();
        }

        if (contract_type == 'Other') {
            $('#contract_type_other').show();
            if ($(e.target).attr('id') == 'contract_type') $('#contract_type_other').focus();
        }
        else {
            $('#contract_type_other').hide();
        }

        if (contract_type == 'Engaging a new vendor company'
            || contract_type == 'Engaging an individual (independent contractor, temp agency worker, incorporated)'
            || contract_type == 'Adding a new SOW with a vendor')
        {
            $('#sow_details').show();
        }
        else {
            $('#sow_details').hide();
        }

        if (contract_type == "Extending a SOW or renewing a contract"
            || contract_type == "Purchasing software"
            || contract_type == "Purchasing hardware"
            || contract_type == "Signing up for an online service"
            || contract_type == "Other")
        {
            $('#total_cost_row').show();
        }
        else {
            $('#total_cost_row').hide();
        }

        if (contract_type == 'Engaging an individual (independent contractor, temp agency worker, incorporated)') {
            $('#independent_contractor_questions').show();
        }
        else {
           $('#independent_contractor_questions').hide();
        }

        if ($('#independent_contractor_prev_work').val() == 'Yes') {
            $('#independent_contractor_prev_work_bug_row').show();
            if ($(e.target).attr('id') == 'independent_contractor_prev_work')
                $('#independent_contractor_prev_work_bug').focus();
        }
        else {
            $('#independent_contractor_prev_work_bug_row').hide();
        }

        if ($('#independent_contractor_dupe_services').val() == 'Yes') {
            $('#independent_contractor_dupe_services_temp_row').show();
            if ($(e.target).attr('id') == 'independent_contractor_dupe_services')
                $('#independent_contractor_dupe_services_temp').focus();
        }
        else {
            $('#independent_contractor_dupe_services_temp_row').hide();
        }

        if ($('#sow_vendor_mozilla_systems').val() == 'Yes') {
            $('#sow_vendor_mozilla_systems_explain_row').show();
            if ($(e.target).attr('id') == 'sow_vendor_mozilla_systems')
                $('#sow_vendor_mozilla_systems_explain').focus();
        }
        else {
            $('#sow_vendor_mozilla_systems_explain_row').hide();
        }

        if ($('#sow_vendor_onsite').val() == 'Yes') {
            $('#sow_vendor_onsite_where_row').show();
            if ($(e.target).attr('id') == 'sow_vendor_onsite')
                $('#sow_vendor_onsite_where').focus();
        }
        else {
            $('#sow_vendor_onsite_where_row').hide();
        }
    }

    function validateAndSubmit(e) {
        var alert_text = '',
            section    = '',
            field      = '';
        for (section in required_fields) {
            if ($('#' + section).is(':visible')) {
                for (field in required_fields[section]) {
                    if (!isFilledOut(field)) {
                        alert_text += required_fields[section][field] + "\n";
                    }
                }
            }
        }

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

        $('#short_desc').val('Contract for ' +
                             $('#contract_type').val() +
                             ' with ' +
                             $('#other_party').val());

        var component_map = {
            "Engaging a new vendor company,": "Vendor/Services",
            "Adding a new SOW with a vendor": "Vendor/Services",
            "Extending a SOW or renewing a contract": "Vendor/Services",
            "Purchasing hardware": "Vendor/Services",
            "Other": "Vendor/Services",
            "Engaging an individual (independent contractor, temp agency worker, incorporated)": "Independent Contractor Agreement",
            "An agreement with a partner": "Firefox Distribution or Other Partner Agreement",
            "Purchasing software": "License Review",
            "Signing up for an online service" : "License Review"
        }

        var contract_type = $('#contract_type').val();
        if (component_map[contract_type]) {
            $('#component').val(component_map[contract_type]);
        }

        return true;
    }

    //Takes a DOM element id and makes sure that it is filled out
    function isFilledOut(id)  {
        if (!id) return false;
        var str = $('#' + id).val();
        if (!str || str.length == 0) return false;
        return true;
    }

    // date pickers
    $('.date-field').datetimepicker({
        format: 'Y-m-d',
        datepicker: true,
        timepicker: false,
        scrollInput: false,
        lazyInit: false,
        closeOnDateSelect: true
    });
    $('.date-field-img')
        .click(function(event) {
            var id = $(event.target).attr('id').replace(/-img$/, '');
            $('#' + id).datetimepicker('show');
        })

    init();
});