Skip to content

Commit

Permalink
[js] Improvements to indoor without coords
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
nemesifier committed Jun 2, 2020
1 parent a70b081 commit ceacac9
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions django_loci/static/django-loci/js/loci.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }; }
Expand Down Expand Up @@ -113,6 +114,10 @@ django.jQuery(function ($) {
$floorplanSelection.val('new');
$floorplanSelectionRow.hide();
}
if (!$floorplanSelection.val()) {
$indoorRows.hide();
$floorplanSelectionRow.show();
}
}

function locationSelectionChange(e, initial) {
Expand Down Expand Up @@ -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();
}
}
});
Expand All @@ -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')) {
Expand All @@ -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();
Expand Down

0 comments on commit ceacac9

Please sign in to comment.