Passed
Push — master ( 2b7bb3...0db2dd )
by Clint A
06:52
created

assets/total-selected-charges.js   A

Complexity

Total Complexity 7
Complexity/F 1.75

Size

Lines of Code 40
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
eloc 24
nc 1
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 7
mnd 1
bc 8
fnc 4
bpm 2
cpm 1.75
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A total-selected-charges.js ➔ ??? 0 14 2
A total-selected-charges.js ➔ selectedTotal 0 22 2
1
import forEach from 'lodash.foreach'
2
import currency from 'currency.js'
3
4
function selectedTotal() {
5
  let total = 0.0
6
7
  forEach(
8
    document.getElementsByClassName('charges__item-checkbox-input'),
9
    element => {
10
      if (element.checked) {
11
        total += Number.parseFloat(element.dataset.feeBalance)
12
      }
13
    }
14
  )
15
16
  document.getElementById('totalSelectedAmount').innerHTML = `$${currency(
17
    total
18
  )}`
19
20
  if (total > 0) {
21
    document.getElementById('submitButton').removeAttribute('disabled')
22
  } else {
23
    document.getElementById('submitButton').setAttribute('disabled', 'disabled')
24
  }
25
}
26
27
document.addEventListener('DOMContentLoaded', () => {
28
  if (!document.getElementsByClassName('charges__item-checkbox-input').length) {
29
    return
30
  }
31
32
  selectedTotal()
33
34
  forEach(
35
    document.getElementsByClassName('charges__item-checkbox-input'),
36
    element => {
37
      element.addEventListener('click', selectedTotal)
38
    }
39
  )
40
})
41