summaryrefslogtreecommitdiffstats
path: root/extensions/BMO/web/js/dev_engagement.js
blob: ae6551617de07d91ff7da78e6a883f8e540b19fc (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
/* 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 DE = {
  formUpdate: function () {
    var sections = {
      developer_event_warning: false,
      code_of_conduct_warning: false,
      mozilla_attending_warning: false,
      mozillian_profile_url_section: false,
      mozilla_attending_list_section: false,
      code_of_conduct_url_section: false,
      speaker_needed_detail_section: false,
      previous_event_details_section: false
    };
    var commit_disabled = false;

    if (fieldValue('developer_event') == 'No') {
      commit_disabled = true;
      sections.developer_event_warning = true;
    }

    if (fieldValue('mozilla_attending') == 'No') {
      sections.mozilla_attending_warning = true;
    }
    else if (fieldValue('mozilla_attending') == 'Yes') {
      sections.mozilla_attending_list_section = true;
    }

    if (fieldValue('code_of_conduct') == 'No') {
      commit_disabled = true;
      sections.code_of_conduct_warning = true;
    }
    else if (fieldValue('code_of_conduct') == 'Yes') {
      sections.code_of_conduct_url_section = true;
    }

    if (fieldValue('vouched_mozillian') == 'Yes') {
      sections.mozillian_profile_url_section = true;
    }

    if (fieldValue('previous_event') == 'Yes') {
      sections.previous_event_details_section = true;
    }

    if (fieldValue('speaker_needed') == 'Yes') {
      sections.speaker_needed_detail_section = true;
    }

    for (section in sections) {
      if (sections[section]) {
        DE.removeClass(document.getElementById(section),
                               'bz_default_hidden');
      }
      else {
        DE.addClass(document.getElementById(section),
                            'bz_default_hidden');
      }
    }
    YAHOO.util.Dom.get('commit').disabled = commit_disabled;
  },
  focusOther: function (id, other_id) {
    var cb = document.getElementById(id);
    var input = document.getElementById(other_id);
    input.disabled = !cb.checked;
    if (cb.checked) input.focus();
  },
  onSubmit: function (ev) {
    var alert_text = '';
    // Required fields check
    var required_text_fields = {
      'name' : 'Please enter your name.',
      'email' : 'Please enter your email address.',
      'role' : 'Please enter your role.',
      'event' : 'Please enter the event name.',
      'start_date' : 'Please enter the event start date.',
      'end_date' : 'Please enter the event end date.',
      'location' : 'Please enter a location description for the event.',
      'attendees' : 'Please enter number of expected attendees.',
      'audience' : 'Please enter the intended audience for the event.',
      'desc' : 'Please enter a description of the event.',
    };

    var required_selects = {
      'vouched_mozillian' : 'Please select if you are a vouched mozillian.',
      'developer_event' : 'Please select if this is a developer event.',
      'mozilla_attending' : 'Please select if Mozilla is attending the event.',
      'code_of_conduct' : 'Please select if the event has a code of conduct.',
      'event_location' : 'Please a location for the event.',
      'previous_event' : 'Please select if Mozilla has sponsored this event before.',
    };

    if (fieldValue('vouched_mozillian') == 'Yes')
      required_text_fields['mozillian_profile_url']
        = 'Please enter your mozillian profile url.';
    if (fieldValue('mozilla_attending') == 'Yes')
      required_text_fields['mozilla_attending_list']
        = 'Please enter a list of Mozilla persons attending the event.';
    if (fieldValue('code_of_conduct') == 'Yes')
      required_text_fields['code_of_conduct_url']
        = 'Please enter a code of conduct url.';
    if (fieldValue('previous_event') == 'Yes') {
      required_text_fields['previous_event_year']
        = 'Please select a year for the previous sponsored event.';
      required_text_fields['previous_event_name']
        = 'Please enter a name for the previous sponsored event.';
    }

    var relevant_products = [
      'product_fxos',
      'product_fx',
      'product_webmaker',
      'product_persona',
      'product_marketplace',
      'product_tb',
      'product_fow',
      'product_devtools',
      'product_other',
    ];
    var found = 0;
    for (var i = 0, l = relevant_products.length; i < l; i ++) {
      if (isChecked(relevant_products[i])) found = 1;
    }
    if (!found)
      alert_text += "Please check one or more relevant products.\n";
    if (isChecked('product_other'))
      required_text_fields['product_other_text']
        = 'Please enter a value for other relevant product.';

    var request_types = [
      'request_keynote',
      'request_talk',
      'request_workshop',
      'request_sponsorship',
      'request_other'
    ];
    found = 0;
    for (var i = 0, l = request_types.length; i < l; i ++) {
      if (isChecked(request_types[i])) found = 1;
    }
    if (!found)
      alert_text += "Please check one or more items being requested of Mozilla.\n";
    if (isChecked('request_other'))
      required_text_fields['request_other_text']
        = 'Please enter a value for other item being requested.';

    for (field in required_text_fields) {
      if (!isFilledOut(field))
        alert_text += required_text_fields[field] + "\n";
    }
    for (field in required_selects) {
      if (!fieldValue(field))
        alert_text += required_selects[field] + "\n";
    }
    if (alert_text != '') {
      alert(alert_text);
      YAHOO.util.Event.stopEvent(ev);
    }

    // Whiteboard value
    var wb = '';
    var location_wb_map = {
      'Africa' : 'africa',
      'Asia' : 'asia',
      'Australia' : 'australia',
      'Europe' : 'europe',
      'North America' : 'north-america',
      'Central / South America' : 'central-south-america',
      'Multiple' : 'multiple',
      'Online only' : 'online',
    };
    wb += '[location:' + location_wb_map[fieldValue('event_location')] + '] ';

    var request_items = [];
    if (document.getElementById('request_keynote').checked)
      request_items.push('keynote');
    if (document.getElementById('request_talk').checked)
      request_items.push('talk');
    if (document.getElementById('request_workshop').checked)
      request_items.push('workshop');
    if (document.getElementById('request_sponsorship').checked)
      request_items.push('sponsorship');
    if (document.getElementById('request_other').checked)
      request_items.push('other');
    wb += '[requesting:' + request_items.join(',') + '] ';

    var product_items = [];
    if (document.getElementById('product_fxos').checked)
      product_items.push('firefox-os');
    if (document.getElementById('product_fx').checked)
      product_items.push('firefox-web-browser');
    if (document.getElementById('product_webmaker').checked)
      product_items.push('webmaker');
    if (document.getElementById('product_persona').checked)
      product_items.push('persona');
    if (document.getElementById('product_marketplace').checked)
      product_items.push('marketplace');
    if (document.getElementById('product_tb').checked)
      product_items.push('thunderbird');
    if (document.getElementById('product_fow').checked)
      product_items.push('open-web');
    if (document.getElementById('product_devtools').checked)
      product_items.push('developer-tools');
    if (document.getElementById('product_other').checked)
      product_items.push('other');
    wb += '[products:' + product_items.join(',') + '] ';

    if (fieldValue('developer_event') == 'Yes')
      wb += '[developer-event:true] ';
    var mozilla_attending = fieldValue('mozilla_attending') == 'Yes' ? 'true' : 'false';
    wb += '[mozilla-already-attending:' + mozilla_attending + '] ';
    var vouched = fieldValue('vouched_mozillian') == 'Yes' ? 'true' : 'false';
    wb += '[requested-by-mozillian:' + vouched + '] ';
    if (fieldValue('code_of_conduct') == 'Yes')
      wb += '[code-of-conduct:true] ';
    var previous_event = fieldValue('previous_event') == 'Yes' ? 'true' : 'false';
    wb += '[past-sponsorship:' + previous_event + '] ';
    var needs_speaker = fieldValue('speaker_needed') == 'Yes' ? 'true' : 'false';
    wb += '[needs-speaker:' + needs_speaker + '] ';
    var sponsor_booth = fieldValue('sponsor_booth') == 'Yes' ? 'true' : 'false';
    wb += '[option-to-sponsor-booth:' + sponsor_booth + '] ';
    wb += '[expected-attendees:' + fieldValue('attendees') + '] ';
    var prospectus = fieldValue('data') ? 'true' : 'false';
    wb += '[prospectus:' + prospectus + '] ';
    document.getElementById('status_whiteboard').value = wb.replace(/ $/, '');

    var summary = document.getElementById('event').value + ', ' + DE.long_start_date();
    var loc = document.getElementById('location').value;
    if (loc)
      summary = summary + ' (' + loc + ')';
    document.getElementById('short_desc').value = summary;
    document.getElementById('bug_file_loc').value = document.getElementById('link').value;
    document.getElementById('cf_due_date').value = document.getElementById('start_date').value;
  },
  long_start_date: function () {
    var ymd = document.getElementById('start_date').value.split('-');
    if (ymd.length != 3)
      return '';
    var month = YAHOO.bugzilla.calendar_start_date.cfg.getProperty('MONTHS_LONG')[ymd[1] - 1];
    return month + ' ' + ymd[0];
  },
  hasClass: function (element, class_name) {
    return element.className.match(new RegExp('(\\s|^)' + class_name + '(\\s|$)'));
  },
  addClass: function (element, class_name) {
    if (!DE.hasClass(element, class_name))
      element.className += " " + class_name;
  },
  removeClass: function (element, class_name) {
    if (DE.hasClass(element, class_name)) {
        var reg = new RegExp('(\\s|^)' + class_name + '(\\s|$)');
        element.className = element.className.replace(reg,' ');
    }
  },
  init: function() {
    YAHOO.util.Event.on('dev_form', 'submit', DE.onSubmit);
    YAHOO.util.Event.on('product_other', 'change', function () {
      DE.focusOther('product_other', 'product_other_text');
    });
    YAHOO.util.Event.on('request_other', 'change', function () {
      DE.focusOther('request_other', 'request_other_text');
    });
    var select_inputs = [
      'developer_event',
      'code_of_conduct',
      'vouched_mozillian',
      'mozilla_attending',
      'speaker_needed',
      'previous_event'
    ];
    for (var i = 0, l = select_inputs.length; i < l; i++) {
      YAHOO.util.Event.on(select_inputs[i], 'change', DE.formUpdate);
    }
    DE.formUpdate();
    createCalendar('start_date');
    createCalendar('end_date');
  }
};
YAHOO.util.Event.onDOMReady(DE.init);