From ceacac9226bdfd5fcfc0dae4e3774f98af9a1a38 Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Mon, 1 Jun 2020 20:14:12 -0500 Subject: [PATCH] [js] Improvements to indoor without coords - simplified: if no indoor coordinates and the object is new simply ask if user wants to save without coords - manage new case when the page first loads - don't trigger the confirmation message on existing objects --- django_loci/static/django-loci/js/loci.js | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/django_loci/static/django-loci/js/loci.js b/django_loci/static/django-loci/js/loci.js index 46ea213..5045aa0 100644 --- a/django_loci/static/django-loci/js/loci.js +++ b/django_loci/static/django-loci/js/loci.js @@ -41,7 +41,8 @@ django.jQuery(function ($) { $floorplanRow = $('.indoor .field-floorplan'), $floorplan = $floorplanRow.find('select').eq(0), $floorplanImage = $('.indoor.coords .field-image input'), - $floorplanMap = $('.indoor.coords .floorplan-widget'); + $floorplanMap = $('.indoor.coords .floorplan-widget'), + isNew = true; // define dummy gettext if django i18n is not enabled if (!gettext) { window.gettext = function (text) { return text; }; } @@ -113,6 +114,10 @@ django.jQuery(function ($) { $floorplanSelection.val('new'); $floorplanSelectionRow.hide(); } + if (!$floorplanSelection.val()) { + $indoorRows.hide(); + $floorplanSelectionRow.show(); + } } function locationSelectionChange(e, initial) { @@ -338,14 +343,15 @@ django.jQuery(function ($) { $('#content-main form').submit(function (e) { var indoorPosition = $('.field-indoor .floorplan-raw input').val(); - if ($type.val() === 'indoor' && !indoorPosition) { - if ($floorplanImage[0].files.length !== 0 && !indoorPosition) { - alert('Please set the indoor position before saving'); + if (isNew && $type.val() === 'indoor' && !indoorPosition) { + var message = gettext('You have set this location as indoor but have ' + + 'not specified indoor cordinates on a floorplan, ' + + 'do you want to save anyway?'); + if (!confirm(message)) { e.preventDefault(); - } else if ($floorplanImage[0].files.length === 0 && !indoorPosition) { - var confirmation = confirm('Do you want to save this indoor' + - 'location without indoor coordinates?'); - if (!confirmation) { e.preventDefault(); } + } else { + $floorplanSelection.val(''); + indoorForm(); } } }); @@ -368,6 +374,7 @@ django.jQuery(function ($) { if ($location.val()) { $locationSelectionRow.hide(); $geoEdit.show(); + isNew = false; } // show mobile map (hide not relevant fields) if ($isMobile.prop('checked')) { @@ -391,8 +398,10 @@ django.jQuery(function ($) { // show existing indoor if ($floorplan.val()) { $indoor.show(); - $indoorRows.show(); - $floorplanSelectionRow.hide(); + if ($floorplanSelection.val()) { + $indoorRows.show(); + $floorplanSelectionRow.hide(); + } // adding indoor } else if ($type.val() === 'indoor') { $indoor.show();