| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <div class="bx-form-input-location-__name__ __minimized__ 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 eForm = $('#__form_id__');
- eForm.on('submit', function (ev) {
- if (typeof(glBxLocationDisableFormSubmit) !== 'undefined' && glBxLocationDisableFormSubmit)
- ev.preventDefault();
- });
- var disableFormSubmit = function (b) {
- glBxLocationDisableFormSubmit = b;
- if (b)
- eForm.find('[type=submit]').addClass('bx-btn-disabled').attr('disabled', true);
- else
- eForm.find('[type=submit]').removeClass('bx-btn-disabled').attr('disabled', false);
- }
- var getLocationParams = function (sMode) {
- var sCountry = eForm.find('select[name="__name___country"] :selected').text();
- var sCountryCode = eForm.find('select[name="__name___country"]').val();
- var sZip = eForm.find('input[name="__name___zip"]').val();
- var sState = eForm.find('input[name="__name___state"]').val();
- var sCity = eForm.find('input[name="__name___city"]').val();
- var sStreet = eForm.find('input[name="__name___street"]').val();
- var sNum = eForm.find('input[name="__name___street_number"]').val();
- if (!sCountryCode || !sCountryCode.length)
- return '';
- sRet = '&country=' + encodeURIComponent(sCountry);
- if (sZip !== undefined && sZip.length && sMode !== 'no_street_no_zip')
- sRet += '&postalcode=' + encodeURIComponent(sZip);
- if (sZip !== undefined && 'zip_only' == sMode)
- return sZip.length ? sRet : '';
- if (sState.length)
- sRet += '&state=' + encodeURIComponent(sState);
- if (sCity.length)
- sRet += ('county_as_city' == sMode ? '&county=' : '&city=') + encodeURIComponent(sCity);
-
- if (sStreet !== undefined && sStreet.length && sMode !== 'no_street_no_zip')
- sRet += '&street=' + (sNum.length ? encodeURIComponent(sNum) + ' ' : '') + encodeURIComponent(sStreet);
- return sRet;
- }
- var geocode = function (a, i) {
- var s = a[i];
- $.getJSON('__nominatim_server__/search?addressdetails=1' + s + '&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)) {
- eForm.find('input[name="__name___lat"]').val(oResult[0].lat);
- eForm.find('input[name="__name___lng"]').val(oResult[0].lon);
- if ('undefined' !== typeof(oResult[0].address)) {
- if ('undefined' !== typeof(oResult[0].address.state) && 0 == eForm.find('input[name="__name___state"]').val().length)
- eForm.find('input[name="__name___state"]').val(oResult[0].address.state);
- else if (__normalize_names__ && eForm.find('input[name="__name___state"]').val() != oResult[0].address.state)
- eForm.find('input[name="__name___state"]').val(oResult[0].address.state);
- var sCity = '';
- if ('undefined' !== typeof(oResult[0].address.city))
- sCity = oResult[0].address.city;
- else if ('undefined' !== typeof(oResult[0].address.town))
- sCity = oResult[0].address.town;
- else if ('undefined' !== typeof(oResult[0].address.village))
- sCity = oResult[0].address.village;
- if (sCity && 0 == $('input[name="__name___city"]').val().length)
- eForm.find('input[name="__name___city"]').val(sCity);
- else if (__normalize_names__ && sCity && eForm.find('input[name="__name___city"]').val() != sCity)
- eForm.find('input[name="__name___city"]').val(sCity);
- }
- 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);
- }
- else {
- eForm.find('input[name="__name___lat"]').val(0);
- eForm.find('input[name="__name___lng"]').val(0);
- setLocationStatus('fail');
- }
- }
- });
- }
- var setLocationStatus = function (s) {
- eForm.find('.bx-form-input-location-__name__ .bx-form-input-location-status').hide();
- eForm.find('.bx-form-input-location-__name__ .bx-form-input-location-status.' + s).show();
- if ('loading' !== s)
- disableFormSubmit(false);
- }
- setLocationStatus('undef');
- $(document).ready(function () {
- eForm.find('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 = getLocationParams();
- if (!s) {
- setLocationStatus('undef');
- return;
- }
- var a = [s];
- if (s = getLocationParams('zip_only'))
- a.push(s);
- if (s = getLocationParams('no_street_no_zip'))
- a.push(s);
-
- disableFormSubmit(true);
- glBxLocationFieldPlainGeocodingRequest = setTimeout(function () {
- setLocationStatus('loading');
- geocode(a, 0);
- }, 1500);
- });
- if (getLocationParams()) {
- if (parseFloat(eForm.find('input[name="__name___lat"]').val()) && parseFloat(eForm.find('input[name="__name___lng"]').val()))
- setLocationStatus('ok');
- else
- setLocationStatus('fail');
- }
- else {
- setLocationStatus('undef');
- }
- });
- })();
- </script>
|