| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <div class="bx-form-input-location-__name__ bx-form-input-location-cont bx-clearfix">
- __inputs__
- <div class="bx-form-input-location-status-cont bx-def-font-small bx-def-font-grayed bx-def-margin-thd-top bx-clearfix">
- <div class="bx-form-input-location-status ok"><i class="sys-icon sys-colored col-green1-dark check-circle"></i> <bx_text:_sys_location_status_ok /></div>
- <div class="bx-form-input-location-status fail"><i class="sys-icon sys-colored col-red1-dark times-circle"></i> <bx_text:_sys_location_status_fail /></div>
- <div class="bx-form-input-location-status undef"><i class="sys-icon sys-colored question-circle"></i> <bx_text:_sys_location_status_undef /></div>
- <div class="bx-form-input-location-status loading"><i class="sys-icon sys-colored sync-alt"></i> <bx_text:_sys_loading /></div>
- <div class="bx-form-input-location-copyright"></div>
- </div>
- </div>
- <script>
- (function () {
- var getLocationString = function (sMode) {
- var sCountry = $('select[name="__name___country"] :selected').text();
- var sCountryCode = $('select[name="__name___country"]').val();
- var sZip = $('input[name="__name___zip"]').val();
- var sState = $('input[name="__name___state"]').val();
- var sCity = $('input[name="__name___city"]').val();
- var sStreet = $('input[name="__name___street"]').val();
- var sNum = $('input[name="__name___street_number"]').val();
- if (!sCountryCode || !sCountryCode.length)
- return '';
- sRet = sZip.length ? sZip : '';
- if ('undefined' !== typeof(sMode) && 'zip_only' == sMode) {
- return sZip.length ? sRet : '';
- }
- if ('undefined' !== typeof(sMode) && 'city_only' == sMode) {
- return (sCity.length ? sCity + ', ': '') + (sState.length ? sState + ', ': '') + sCountry;
- }
- sRet = (sCity.length ? sCity + ', ': '') + (sState.length ? sState + ', ': '') + sRet;
-
- if (sCity.length)
- sRet = (sStreet.length && sNum.length ? sNum + ' ' : '') + (sStreet.length ? sStreet + ', ' : '') + sRet;
- if ('undefined' !== typeof(sMode) && 'address_wo_zip' == sMode) {
- return sCity.length && sStreet.length ?
- (sStreet.length && sNum.length ? sNum + ' ' : '') + (sStreet.length ? sStreet + ', ' : '') + (sCity.length ? sCity + ', ': '') + (sState.length ? sState : '') : '';
- }
- return sRet;
- }
- var geocode = function (a, i, sCountryCode) {
- var s = a[i];
- $.getJSON('__nominatim_server__/search/?q=' + encodeURIComponent(s) + '&countrycodes=' + sCountryCode + '&addressdetails=1&format=json&limit=1&email=__nominatim_email__', function (oResult) {
- glBxLocationFieldPlainGeocodingRequest = false;
- if (('object' === typeof oResult) && oResult.length && ('undefined' !== typeof oResult[0].lat) && ('undefined' !== typeof oResult[0].lon)) {
- $('input[name="__name___lat"]').val(oResult[0].lat);
- $('input[name="__name___lng"]').val(oResult[0].lon);
- if ('undefined' !== typeof(oResult[0].address)) {
- if ('undefined' !== typeof(oResult[0].address.state) && 0 == $('input[name="__name___state"]').val().length)
- $('input[name="__name___state"]').val(oResult[0].address.state);
- if (0 == $('input[name="__name___city"]').val().length) {
- if ('undefined' !== typeof(oResult[0].address.city))
- $('input[name="__name___city"]').val(oResult[0].address.city);
- else if ('undefined' !== typeof(oResult[0].address.town))
- $('input[name="__name___city"]').val(oResult[0].address.town);
- else if ('undefined' !== typeof(oResult[0].address.village))
- $('input[name="__name___city"]').val(oResult[0].address.village);
- }
- }
- if ('undefined' !== typeof(oResult[0].licence))
- $('.bx-form-input-location-__name__ .bx-form-input-location-copyright').html(oResult[0].licence);
- setLocationStatus('ok');
- }
- else {
- i += 1;
- if ('undefined' !== typeof(a[i])) {
- geocode(a, i, sCountryCode);
- }
- else {
- $('input[name="__name___lat"]').val(0);
- $('input[name="__name___lng"]').val(0);
- setLocationStatus('fail');
- }
- }
- });
- }
- var setLocationStatus = function (s) {
- $('.bx-form-input-location-__name__ .bx-form-input-location-status').hide();
- $('.bx-form-input-location-__name__ .bx-form-input-location-status.' + s).show();
- }
- setLocationStatus('undef');
- $(document).ready(function () {
- $('input[name^="__name__"],select[name^="__name__"]').on('change', function () {
- if ('undefined' !== typeof(glBxLocationFieldPlainGeocodingRequest) && glBxLocationFieldPlainGeocodingRequest) { // cancel previous request
- clearTimeout(glBxLocationFieldPlainGeocodingRequest);
- glBxLocationFieldPlainGeocodingRequest = null;
- }
- if ('hidden' == this.type)
- return;
-
- var s = getLocationString();
- if (!s) {
- setLocationStatus('undef');
- return;
- }
- var a = [s];
- if (s = getLocationString('address_wo_zip'))
- a.push(s);
- if (s = getLocationString('zip_only'))
- a.push(s);
- if (s = getLocationString('city_only'))
- a.push(s);
-
- glBxLocationFieldPlainGeocodingRequest = setTimeout(function () {
- setLocationStatus('loading');
- geocode(a, 0, $('select[name="__name___country"]').val());
- }, 1500);
- });
- if (getLocationString()) {
- if (parseFloat($('input[name="__name___lat"]').val()) && parseFloat($('input[name="__name___lng"]').val()))
- setLocationStatus('ok');
- else
- setLocationStatus('fail');
- }
- else {
- setLocationStatus('undef');
- }
- });
- })();
- </script>
|