Completed
Push — master ( b3a018...2e1a6c )
by Simon
01:30
created

client/src/js/field/googlemapsfield.js   A

Complexity

Total Complexity 6
Complexity/F 1.2

Size

Lines of Code 33
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 33
rs 10
wmc 6
mnd 1
bc 6
fnc 5
bpm 1.2
cpm 1.2
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A googlemapsfield.js ➔ ??? 0 16 1
1
const targets = Array.from(document.body.querySelectorAll('input[data-mapsfield=mapsfield]'));
2
const latField = document.getElementById('GoogleMapsLatField');
3
const lngField = document.getElementById('GoogleMapsLngField');
4
5
let options = {};
6
let autoComplete;
7
8
const fillAddress = () => {
9
  const location = autoComplete.getPlace();
10
  const components = location.address_components;
11
12
  latField.setAttribute('value', location.geometry.location.lat());
13
  lngField.setAttribute('value', location.geometry.location.lng());
14
15
  components.forEach((component) => {
16
    component.types.forEach((type) => {
17
      const field = document.getElementById(type);
18
      if (field) {
19
        field.setAttribute('value', component.long_name);
20
      }
21
    });
22
  });
23
};
24
25
const mountMapsField = (mapsfield) => {
26
  options = Object.assign(options, window.customisations);
27
  autoComplete = new google.maps.places.Autocomplete(mapsfield, options);
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
28
  autoComplete.addListener('place_changed', fillAddress);
29
};
30
31
export default function() {
32
  targets.forEach(mountMapsField);
33
}