File tree Expand file tree Collapse file tree 3 files changed +29
-34
lines changed Expand file tree Collapse file tree 3 files changed +29
-34
lines changed Original file line number Diff line number Diff line change @@ -22,22 +22,17 @@ class ActionBar {
22
22
} ) ;
23
23
}
24
24
25
+ revealError = ( ) => {
26
+ $ ( ".x-logo-error" ) . classList . remove ( "hidden" ) ;
27
+ this . scrollToError ( ) ;
28
+ }
29
+
25
30
previewHandler ( instance : any ) {
26
- if ( instance . isImageUploaded ( ) ) {
27
- $ ( "body" ) . classList . toggle ( "x-preview" ) ;
28
- } else {
29
- $ ( ".x-logo-error" ) . classList . remove ( "hidden" ) ;
30
- this . scrollToError ( ) ;
31
- }
31
+ instance . isImageUploaded ( ) ? $ ( "body" ) . classList . toggle ( "x-preview" ) : this . revealError ( ) ;
32
32
}
33
33
34
34
printHandler ( instance : any ) {
35
- if ( instance . isImageUploaded ( ) ) {
36
- window . print ( ) ;
37
- } else {
38
- $ ( ".x-logo-error" ) . classList . remove ( "hidden" ) ;
39
- this . scrollToError ( ) ;
40
- }
35
+ instance . isImageUploaded ( ) ? window . print ( ) : this . revealError ( ) ;
41
36
}
42
37
43
38
scrollToError ( ) {
Original file line number Diff line number Diff line change @@ -39,25 +39,21 @@ class ProductsTable {
39
39
} ) ;
40
40
41
41
document . body . addEventListener ( "click" , ( e : any ) => {
42
- if ( e . target . id === `js-delete-${ this . id } ` ) {
43
- this . removeRowHandler ( ) ;
44
- }
42
+ e . target . id === `js-delete-${ this . id } ` && this . removeRowHandler ( ) ;
45
43
} ) ;
46
44
}
47
45
48
46
onQuantityHandler = ( e : any , unityEl : HTMLInputElement ) : void => {
49
- if ( unityEl . value === "" ) return ;
47
+ let value = unityEl . value || null ;
48
+
49
+ let id = e . target . attributes [ 0 ] . value ;
50
50
51
51
const amountPerRow = calculateAmountPerRow (
52
52
parseInt ( e . target . value ) ,
53
- parseInt ( unityEl . value )
53
+ parseInt ( value )
54
54
) ;
55
- if ( ! isNaN ( amountPerRow ) ) {
56
- $ ( `#js-amount-${ e . target . attributes [ 0 ] . value } ` ) . setAttribute (
57
- "value" ,
58
- `${ String ( amountPerRow ) } €`
59
- ) ;
60
- }
55
+
56
+ ! isNaN ( amountPerRow ) && $ ( `#js-amount-${ id } ` ) . setAttribute ( "value" , `${ String ( amountPerRow ) } €` ) ;
61
57
} ;
62
58
63
59
isRowFilled = ( ) : boolean => {
@@ -103,9 +99,9 @@ class ProductsTable {
103
99
<input id="js-amount-${ id } " class="js-amount" placeholder="0.00" readonly value="">
104
100
</td>
105
101
${
106
- id !== 0
107
- ? `<td class="remove-wrapper"><i id="js-delete-${ id } " class="js-delete icon icon-minus"></i></td>`
108
- : ""
102
+ id !== 0
103
+ ? `<td class="remove-wrapper"><i id="js-delete-${ id } " class="js-delete icon icon-minus"></i></td>`
104
+ : ""
109
105
}
110
106
</tr>` ;
111
107
} ;
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ export const calculateSubtotal = (selectorsArray: any): number => {
33
33
34
34
// Iterate over all amount and sum
35
35
selectorsArray . forEach ( element => {
36
- if ( element . value ) sum += parseFloat ( element . value ) ;
36
+ element . value ? sum += parseFloat ( element . value ) : null ;
37
37
} ) ;
38
38
39
39
return sum ;
@@ -52,15 +52,19 @@ export const calculateTotalAmount = (
52
52
) ;
53
53
} ;
54
54
55
+ const addError = el => {
56
+ el . classList . add ( "error" ) ;
57
+ return false ;
58
+ }
59
+
60
+ const removeError = el => {
61
+ el . classList . remove ( "error" ) ;
62
+ return true ;
63
+ }
64
+
55
65
export const isFieldValid = (
56
66
value : number ,
57
67
elemContainer : HTMLElement
58
68
) : boolean => {
59
- if ( ! value || value == 0 ) {
60
- elemContainer . classList . add ( "error" ) ;
61
- return false ;
62
- } else {
63
- elemContainer . classList . remove ( "error" ) ;
64
- return true ;
65
- }
69
+ return value && value != 0 ? removeError ( elemContainer ) : addError ( elemContainer ) ;
66
70
} ;
You can’t perform that action at this time.
0 commit comments