-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33997 from dimagi/riese/bbox
Save the projects default location bounding box and use in on search results
- Loading branch information
Showing
6 changed files
with
368 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 107 additions & 107 deletions
214
corehq/apps/hqwebapp/static/hqwebapp/js/bootstrap3/widgets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,125 @@ | ||
hqDefine("hqwebapp/js/bootstrap3/widgets",[ | ||
'jquery', | ||
'underscore', | ||
'@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.min', | ||
'hqwebapp/js/initial_page_data', | ||
'select2/dist/js/select2.full.min', | ||
'jquery-ui/ui/widgets/datepicker', | ||
], function ($, _, MapboxGeocoder, initialPageData) { | ||
var init = function () { | ||
var MAPBOX_ACCESS_TOKEN = initialPageData.get( | ||
"mapbox_access_token" | ||
); | ||
// .hqwebapp-select2 is a basic select2-based dropdown or multiselect | ||
_.each($(".hqwebapp-select2"), function (element) { | ||
$(element).select2({ | ||
width: '100%', | ||
}); | ||
if (window.USE_BOOTSTRAP5 && $(element).hasClass('is-invalid')) { | ||
$(element).data('select2').$container.addClass('is-invalid'); | ||
} | ||
if (window.USE_BOOTSTRAP5 && $(element).hasClass('is-valid')) { | ||
$(element).data('select2').$container.addClass('is-valid'); | ||
} | ||
'jquery', | ||
'underscore', | ||
'@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.min', | ||
'hqwebapp/js/initial_page_data', | ||
'select2/dist/js/select2.full.min', | ||
'jquery-ui/ui/widgets/datepicker', | ||
], function ($, _, MapboxGeocoder, initialPageData) { | ||
var init = function () { | ||
var MAPBOX_ACCESS_TOKEN = initialPageData.get( | ||
"mapbox_access_token" | ||
); | ||
// .hqwebapp-select2 is a basic select2-based dropdown or multiselect | ||
_.each($(".hqwebapp-select2"), function (element) { | ||
$(element).select2({ | ||
width: '100%', | ||
}); | ||
if (window.USE_BOOTSTRAP5 && $(element).hasClass('is-invalid')) { | ||
$(element).data('select2').$container.addClass('is-invalid'); | ||
} | ||
if (window.USE_BOOTSTRAP5 && $(element).hasClass('is-valid')) { | ||
$(element).data('select2').$container.addClass('is-valid'); | ||
} | ||
}); | ||
|
||
// .hqwebapp-autocomplete also allows for free text entry | ||
_.each($(".hqwebapp-autocomplete"), function (input) { | ||
var $input = $(input); | ||
$input.select2({ | ||
multiple: true, | ||
tags: true, | ||
width: '100%', | ||
}); | ||
// .hqwebapp-autocomplete also allows for free text entry | ||
_.each($(".hqwebapp-autocomplete"), function (input) { | ||
var $input = $(input); | ||
$input.select2({ | ||
multiple: true, | ||
tags: true, | ||
width: '100%', | ||
}); | ||
}); | ||
|
||
_.each($(".hqwebapp-autocomplete-email"), function (input) { | ||
var $input = $(input); | ||
$input.select2({ | ||
multiple: true, | ||
placeholder: ' ', | ||
tags: true, | ||
tokenSeparators: [','], | ||
width: '100%', | ||
createTag: function (params) { | ||
// Support pasting in comma-separated values | ||
var terms = parseEmails(params.term); | ||
if (terms.length === 1) { | ||
return { | ||
id: terms[0], | ||
text: terms[0], | ||
}; | ||
} | ||
$input.select2('close'); | ||
var values = $input.val() || []; | ||
if (!_.isArray(values)) { | ||
values = [values]; | ||
_.each($(".hqwebapp-autocomplete-email"), function (input) { | ||
var $input = $(input); | ||
$input.select2({ | ||
multiple: true, | ||
placeholder: ' ', | ||
tags: true, | ||
tokenSeparators: [','], | ||
width: '100%', | ||
createTag: function (params) { | ||
// Support pasting in comma-separated values | ||
var terms = parseEmails(params.term); | ||
if (terms.length === 1) { | ||
return { | ||
id: terms[0], | ||
text: terms[0], | ||
}; | ||
} | ||
$input.select2('close'); | ||
var values = $input.val() || []; | ||
if (!_.isArray(values)) { | ||
values = [values]; | ||
} | ||
_.each(terms, function (term) { | ||
if (!_.contains(values, term)) { | ||
$input.append(new Option(term, term)); | ||
values.push(term); | ||
} | ||
_.each(terms, function (term) { | ||
if (!_.contains(values, term)) { | ||
$input.append(new Option(term, term)); | ||
values.push(term); | ||
} | ||
}); | ||
$input.val(values).trigger("change"); | ||
}); | ||
$input.val(values).trigger("change"); | ||
|
||
return null; | ||
}, | ||
}); | ||
return null; | ||
}, | ||
}); | ||
}); | ||
|
||
_.each($(".geocoder-proximity"), function (input) { | ||
var $input = $(input).find('input'); | ||
|
||
function getGeocoderItem(item) { | ||
var inputEl = $input; | ||
var geoObj = {}; | ||
geoObj.place_name = item.place_name; | ||
geoObj.coordinates = { | ||
longitude: item.geometry.coordinates[0], | ||
latitude: item.geometry.coordinates[1], | ||
}; | ||
inputEl.attr("value", JSON.stringify(geoObj)); | ||
return item.place_name; | ||
} | ||
|
||
function getGeocoderValue() { | ||
var geocoderValue = $input.val(); | ||
if (geocoderValue) { | ||
geocoderValue = JSON.parse(geocoderValue); | ||
return geocoderValue.place_name; | ||
} | ||
return null; | ||
} | ||
_.each($(".geocoder-proximity"), function (input) { | ||
var $input = $(input).find('input'); | ||
|
||
var geocoder = new MapboxGeocoder({ | ||
accessToken: MAPBOX_ACCESS_TOKEN, | ||
types: | ||
"country,region,place,postcode,locality,neighborhood", | ||
getItemValue: getGeocoderItem, | ||
}); | ||
function getGeocoderItem(item) { | ||
var inputEl = $input; | ||
var geoObj = {}; | ||
geoObj.place_name = item.place_name; | ||
geoObj.coordinates = { | ||
longitude: item.geometry.coordinates[0], | ||
latitude: item.geometry.coordinates[1], | ||
}; | ||
geoObj.bbox = item.bbox; | ||
inputEl.attr("value", JSON.stringify(geoObj)); | ||
return item.place_name; | ||
} | ||
|
||
geocoder.addTo(".geocoder-proximity"); | ||
var geocoderValue = getGeocoderValue(); | ||
function getGeocoderValue() { | ||
var geocoderValue = $input.val(); | ||
if (geocoderValue) { | ||
geocoder.setInput(getGeocoderValue()); | ||
geocoderValue = JSON.parse(geocoderValue); | ||
return geocoderValue.place_name; | ||
} | ||
return null; | ||
} | ||
|
||
var geocoder = new MapboxGeocoder({ | ||
accessToken: MAPBOX_ACCESS_TOKEN, | ||
types: | ||
"country,region,place,postcode,locality,neighborhood", | ||
getItemValue: getGeocoderItem, | ||
}); | ||
|
||
$('.date-picker').datepicker({ dateFormat: "yy-mm-dd" }); | ||
}; | ||
geocoder.addTo(".geocoder-proximity"); | ||
var geocoderValue = getGeocoderValue(); | ||
if (geocoderValue) { | ||
geocoder.setInput(getGeocoderValue()); | ||
} | ||
}); | ||
|
||
$('.date-picker').datepicker({ dateFormat: "yy-mm-dd" }); | ||
}; | ||
|
||
var parseEmails = function (input) { | ||
return $.trim(input).split(/[, ]\s*/); | ||
}; | ||
var parseEmails = function (input) { | ||
return $.trim(input).split(/[, ]\s*/); | ||
}; | ||
|
||
$(function () { | ||
init(); | ||
}); | ||
$(function () { | ||
init(); | ||
}); | ||
|
||
return { | ||
init: init, | ||
parseEmails: parseEmails, // export for testing | ||
}; | ||
} | ||
); | ||
return { | ||
init: init, | ||
parseEmails: parseEmails, // export for testing | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.