Skip to content

Commit be23689

Browse files
Mike Taylordeepthivenkat
Mike Taylor
authored andcommitted
Issue webcompat#1167. Refactor imageMap
1 parent 3a14909 commit be23689

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

webcompat/static/js/lib/bugform.js

+34-21
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
function BugForm() {
66
this.form = $('#js-ReportForm form');
7-
this.urlField = $('#url');
87
this.descField = $('#description');
9-
this.uploadField = $('#image');
10-
this.problemType = $('[name=problem_category]');
118
this.submitButtons = $('#js-ReportForm .js-Button');
129
this.loadingIndicator = $('.js-Loader');
1310
this.reportButton = $('#js-ReportBug');
@@ -18,31 +15,47 @@ function BugForm() {
1815
this.submitType = 'github-proxy-report';
1916
this.UPLOAD_LIMIT = 1024 * 1024 * 4;
2017

21-
this.inputMap = {
18+
this.inputs = {
2219
'url': {
23-
'elm': this.urlField, // elm is a jQuery object
20+
'el': $('#url'),
2421
'valid': null,
2522
'helpText': 'A URL is required.'
2623
},
2724
'problem_type': {
28-
'elm': this.problemType,
25+
'el': $('[name=problem_category]'),
2926
'valid': null,
3027
'helpText': 'Problem type required.'
3128
},
3229
'image': {
33-
'elm': this.uploadField,
30+
'el': $('#image'),
3431
// image should be valid by default because it's optional
3532
'valid': true,
36-
'helpText': 'Image must be one of the following: jpg, png, gif, or bmp.'
33+
'helpText': 'Image must be one of the following: jpg, png, gif, or bmp.',
3734
},
3835
'img_too_big': {
39-
'elm': this.uploadField,
36+
'el': $('#image'),
4037
// image should be valid by default because it's optional
4138
'valid': true,
4239
'helpText': 'Please choose a smaller image (< 4MB)'
40+
},
41+
'browser': {
42+
'el': $('#browser'),
43+
'valid': true,
44+
'helpText': null
45+
},
46+
'os': {
47+
'el': $('#os'),
48+
'valid': true,
49+
'helpText': null
4350
}
4451
};
4552

53+
this.browserField = this.inputs.browser.el;
54+
this.osField = this.inputs.os.el;
55+
this.problemType = this.inputs.problem_type.el;
56+
this.uploadField = this.inputs.image.el;
57+
this.urlField = this.inputs.url.el;
58+
4659
this.init = function() {
4760
this.checkParams();
4861
this.disableSubmits();
@@ -209,17 +222,17 @@ function BugForm() {
209222

210223
this.makeInvalid = function(id) {
211224
// Early return if inline help is already in place.
212-
if (this.inputMap[id].valid === false) {
225+
if (this.inputs[id].valid === false) {
213226
return;
214227
}
215228

216229
var inlineHelp = $('<span></span>', {
217230
'class': 'wc-Form-helpMessage',
218-
'text': this.inputMap[id].helpText
231+
'text': this.inputs[id].helpText
219232
});
220233

221-
this.inputMap[id].valid = false;
222-
this.inputMap[id].elm.parents('.js-Form-group')
234+
this.inputs[id].valid = false;
235+
this.inputs[id].el.parents('.js-Form-group')
223236
.removeClass('is-validated js-no-error')
224237
.addClass('is-error js-form-error');
225238

@@ -252,17 +265,17 @@ function BugForm() {
252265
};
253266

254267
this.makeValid = function(id) {
255-
this.inputMap[id].valid = true;
256-
this.inputMap[id].elm.parents('.js-Form-group')
268+
this.inputs[id].valid = true;
269+
this.inputs[id].el.parents('.js-Form-group')
257270
.removeClass('is-error js-form-error')
258271
.addClass('is-validated js-no-error');
259272

260-
this.inputMap[id].elm.parents('.js-Form-group').find('.wc-Form-helpMessage').remove();
273+
this.inputs[id].el.parents('.js-Form-group').find('.wc-Form-helpMessage').remove();
261274

262-
if (this.inputMap['url'].valid &&
263-
this.inputMap['problem_type'].valid &&
264-
this.inputMap['image'].valid &&
265-
this.inputMap['img_too_big'].valid) {
275+
if (this.inputs['url'].valid &&
276+
this.inputs['problem_type'].valid &&
277+
this.inputs['image'].valid &&
278+
this.inputs['img_too_big'].valid) {
266279
this.enableSubmits();
267280
}
268281
};
@@ -363,7 +376,7 @@ function BugForm() {
363376
var msg;
364377
if (response && response.status === 415) {
365378
wcEvents.trigger('flash:error',
366-
{message: this.inputMap.image.helpText, timeout: 5000});
379+
{message: this.inputs.image.helpText, timeout: 5000});
367380
}
368381

369382
if (response && response.status === 413) {

0 commit comments

Comments
 (0)