/* global _ */ /* * oef.getLocation(fieldWrapper) * Arguments: a jQuery selector for the div wrapper of the Problem Location question. * Uses the jQuery UI Autocomplete method to display a list of address suggestions based on results from the LocationSA API. * The request is routed through a Rest */ var onEnqForm ((function(oef) { oef.getLocation = function(field_wrapper) { var base = this; var $wrapper = $(field_wrapper); var $addressField = $wrapper.find('.location-address'); // Fetch the Addresses from Location SA based on query base.fetchAddresses = function(request, response) { var addressQuery = $addressField.val(); var query_url = window.location.protocol + '//' + window.location.hostname + '/forms/rest/adress-information?query='+escape(addressQuery.replace(/[\'\"]/ig,'')); var data; $wrapper.find('.location-loader').show(); $.ajax({ type: 'GET', url: query_url, dataType: 'json' }) .done(function(d){ $wrapper.find('.location-loader').hide(); data = d['candidates']; if(!_.isEmpty(data)){ var addresses = _.map(data, function(addy) { return { label: addy['address'], value: addy['address'], location: addy['location'] }; }); response(addresses); } }) .fail(function(jqXHR, textStatus, errorThrown){ data = []; $wrapper.find('.location-loader').hide(); console.log("Addresses could not be retrieved from LocationSA. Status: "+textStatus+", Error: "+errorThrown); }); }; // Renderer for the items base.renderItem = function(ul, item){ return $("