Frontend: Allow paste of lat/lng in single operation (#3568)

This speeds up the workflow when pasting location found in external mapping application
This commit is contained in:
Reuben Dowle 2023-07-24 01:48:43 +12:00 committed by GitHub
parent 5ca3329e2d
commit ce13135743
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -158,6 +158,7 @@
placeholder=""
color="secondary-dark"
class="input-latitude"
@paste="pastePosition"
></v-text-field>
</v-flex>
@ -174,6 +175,7 @@
placeholder=""
color="secondary-dark"
class="input-longitude"
@paste="pastePosition"
></v-text-field>
</v-flex>
@ -469,6 +471,27 @@ export default {
this.time = taken.toFormat("HH:mm:ss");
},
pastePosition(event) {
/* If text is pasted in the form of "XXX.XXXX, YYY.YYYY" (for example if
* pasting a position from external mapping app) then auto-fill both lat
* and lng fields
*/
let paste = (event.clipboardData || window.clipboardData).getData("text");
let s = paste.split(/[ ,]+/);
if (s.length == 2)
{
let lat = parseFloat(s[0]);
let lng = parseFloat(s[1]);
if(!isNaN(lat) && lat >= -90 && lat <= 90 &&
!isNaN(lng) && lng >= -180 && lng <= 180)
{
event.preventDefault();
this.model.Lat = lat;
this.model.Lng = lng;
}
}
},
updateModel() {
if (!this.model.hasId()) {
return;