4
4
5
5
function BugForm ( ) {
6
6
this . form = $ ( '#js-ReportForm form' ) ;
7
- this . urlField = $ ( '#url' ) ;
8
7
this . descField = $ ( '#description' ) ;
9
- this . uploadField = $ ( '#image' ) ;
10
- this . problemType = $ ( '[name=problem_category]' ) ;
11
8
this . submitButtons = $ ( '#js-ReportForm .js-Button' ) ;
12
9
this . loadingIndicator = $ ( '.js-Loader' ) ;
13
10
this . reportButton = $ ( '#js-ReportBug' ) ;
@@ -18,31 +15,47 @@ function BugForm() {
18
15
this . submitType = 'github-proxy-report' ;
19
16
this . UPLOAD_LIMIT = 1024 * 1024 * 4 ;
20
17
21
- this . inputMap = {
18
+ this . inputs = {
22
19
'url' : {
23
- 'elm ' : this . urlField , // elm is a jQuery object
20
+ 'el ' : $ ( '#url' ) ,
24
21
'valid' : null ,
25
22
'helpText' : 'A URL is required.'
26
23
} ,
27
24
'problem_type' : {
28
- 'elm ' : this . problemType ,
25
+ 'el ' : $ ( '[name=problem_category]' ) ,
29
26
'valid' : null ,
30
27
'helpText' : 'Problem type required.'
31
28
} ,
32
29
'image' : {
33
- 'elm ' : this . uploadField ,
30
+ 'el ' : $ ( '#image' ) ,
34
31
// image should be valid by default because it's optional
35
32
'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.' ,
37
34
} ,
38
35
'img_too_big' : {
39
- 'elm ' : this . uploadField ,
36
+ 'el ' : $ ( '#image' ) ,
40
37
// image should be valid by default because it's optional
41
38
'valid' : true ,
42
39
'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
43
50
}
44
51
} ;
45
52
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
+
46
59
this . init = function ( ) {
47
60
this . checkParams ( ) ;
48
61
this . disableSubmits ( ) ;
@@ -209,17 +222,17 @@ function BugForm() {
209
222
210
223
this . makeInvalid = function ( id ) {
211
224
// Early return if inline help is already in place.
212
- if ( this . inputMap [ id ] . valid === false ) {
225
+ if ( this . inputs [ id ] . valid === false ) {
213
226
return ;
214
227
}
215
228
216
229
var inlineHelp = $ ( '<span></span>' , {
217
230
'class' : 'wc-Form-helpMessage' ,
218
- 'text' : this . inputMap [ id ] . helpText
231
+ 'text' : this . inputs [ id ] . helpText
219
232
} ) ;
220
233
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' )
223
236
. removeClass ( 'is-validated js-no-error' )
224
237
. addClass ( 'is-error js-form-error' ) ;
225
238
@@ -252,17 +265,17 @@ function BugForm() {
252
265
} ;
253
266
254
267
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' )
257
270
. removeClass ( 'is-error js-form-error' )
258
271
. addClass ( 'is-validated js-no-error' ) ;
259
272
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 ( ) ;
261
274
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 ) {
266
279
this . enableSubmits ( ) ;
267
280
}
268
281
} ;
@@ -363,7 +376,7 @@ function BugForm() {
363
376
var msg ;
364
377
if ( response && response . status === 415 ) {
365
378
wcEvents . trigger ( 'flash:error' ,
366
- { message : this . inputMap . image . helpText , timeout : 5000 } ) ;
379
+ { message : this . inputs . image . helpText , timeout : 5000 } ) ;
367
380
}
368
381
369
382
if ( response && response . status === 413 ) {
0 commit comments