From 2846e6838a9abd6c14c4fbb662ba732b8c0e9eb1 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 10 Dec 2019 17:06:04 +0100 Subject: [PATCH] MOBILE-2159 geolocation: Improve error message when permission is denied --- src/addon/mod/data/fields/latlong/component/latlong.ts | 10 ++++++++++ src/addon/mod/data/lang/en.json | 1 + src/assets/lang/en.json | 1 + 3 files changed, 12 insertions(+) diff --git a/src/addon/mod/data/fields/latlong/component/latlong.ts b/src/addon/mod/data/fields/latlong/component/latlong.ts index 767487e9d..013c4586e 100644 --- a/src/addon/mod/data/fields/latlong/component/latlong.ts +++ b/src/addon/mod/data/fields/latlong/component/latlong.ts @@ -117,9 +117,19 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo this.form.controls['f_' + this.field.id + '_0'].setValue(result.coords.latitude); this.form.controls['f_' + this.field.id + '_1'].setValue(result.coords.longitude); }).catch((error) => { + if (this.isPositionError(error) && error.code === error.PERMISSION_DENIED) { + this.domUtils.showErrorModal('addon.mod_data.locationpermissiondenied', true); + + return; + } + this.domUtils.showErrorModalDefault(error, 'Error getting location'); }).finally(() => { modal.dismiss(); }); } + + protected isPositionError(error?: any): error is PositionError { + return error && 'code' in error && 'PERMISSION_DENIED' in error; + } } diff --git a/src/addon/mod/data/lang/en.json b/src/addon/mod/data/lang/en.json index 54de61215..de89c6bca 100644 --- a/src/addon/mod/data/lang/en.json +++ b/src/addon/mod/data/lang/en.json @@ -22,6 +22,7 @@ "foundrecords": "Found records: {{$a.num}}/{{$a.max}} (Reset filters)", "gettinglocation": "Getting location", "latlongboth": "Both latitude and longitude are required.", + "locationpermissiondenied": "Permission to access your location has been denied.", "menuchoose": "Choose...", "modulenameplural": "Databases", "more": "More", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 93693ba6f..e0fb0fd71 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -501,6 +501,7 @@ "addon.mod_data.foundrecords": "Found records: {{$a.num}}/{{$a.max}} (Reset filters)", "addon.mod_data.gettinglocation": "Getting location", "addon.mod_data.latlongboth": "Both latitude and longitude are required.", + "addon.mod_data.locationpermissiondenied": "Permission to access your location has been denied.", "addon.mod_data.menuchoose": "Choose...", "addon.mod_data.modulenameplural": "Databases", "addon.mod_data.more": "More",