<commit_before>var Controller = ( function(w) {'use strict';

		var $ = w.jQuery, ui = w.Ui, uiVersions = w.Versions, uiLanguages = w.Languages, waypoint = w.Waypoint, geolocator = w.Geolocator, searchAddress = w.SearchAddress, searchPoi = w.SearchPoi, route = w.Route, analyse = w.AccessibilityAnalysis, preferences = w.Preferences, openRouteService = w.OpenRouteService, Map = w.Map,
		//the map
		map,
		//Timeout for service responses
		SERVICE_TIMEOUT_INTERVAL = 10000,
		//timer
		timerRoute; //TODO more timers for various service calls

		function Controller() {
			//path to the proxy-script as workaround for JavaScript security errors
			OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

			//IE does not know console...
			if (!window.console) {
				window.console = {};
				window.console.log = function() {
				};
			}
		}

		/* *********************************************************************
		* GENERAL
		* *********************************************************************/

		/**
		 *called when sidebar toggles and the map area is resized
		 */
		function handleMapUpdate() {
			map.theMap.updateSize();
		}

		/* *********************************************************************
		* WAYPOINTS
		* *********************************************************************/

		/**
		 * parses the user input for the waypoint search and calls the Waypoint module to build a search request
		 * @param atts: query: the search query; wpIndex: index of the waypoint; searchIds: map feature ids of previous searches
		 */
		function handleWaypointRequest(atts) {
			ui.searchWaypointChangeToSearchingState(true, atts.wpIndex);
			var lastSearchResults = atts.searchIds;
			lastSearchResults = lastSearchResults ? lastSearchResults.split(' ') : null;

			if (lastSearchResults) {
				map.clearMarkers(map.SEARCH, lastSearchResults);
			}

			waypoint.incrRequestCounterWaypoint(atts.wpIndex);
			waypoint.find(atts.query, handleSearchWaypointResults, handleSearchWaypointFailure, atts.wpIndex, preferences.language);
		}

		/**
		 * forwards the waypoint search results to the Ui to display the addresses and to the map in order to add markers.
		 * @param results: results of the search query in XML format
		 * @param wpIndex: index of the waypoint
		 */
		function handleSearchWaypointResults(results, wpIndex) {
			//IE doesn't know responseXML, it can only provide text that has to be parsed to XML...
			results = results.responseXML ? results.responseXML : util.parseStringToDOM(results.responseText);

			//when the service gives response but contains an error the response is handeled as success, not error. We have to check for an error tag here:
			var responseError = util.getElementsByTagNameNS(results, namespaces.xls, 'ErrorList').length;
			if (parseInt(responseError) > 0) {
				//service response contains an error, switch to error handling function
				handleSearchWaypointFailure(wpIndex);
			} else {

				waypoint.decrRequestCounterWaypoint(wpIndex);
				if (waypoint.getRequestCounterWaypoint(wpIndex) == 0) {
					var listOfPoints = waypoint.parseResultsToPoints(results, wpIndex);

					ui.searchWaypointChangeToSearchingState(false, wpIndex);

					if (listOfPoints.length) {
						var listOfFeatures = map.addSearchAddressResultMarkers(listOfPoints, wpIndex);
						ui.updateSearchWaypointResultList(results, listOfFeatures, map.SEARCH, wpIndex);
					} else {
						ui.showSearchWaypointError(wpIndex)
					}

				}
			}
		}

		/**
		 * calls the UI to show a search error
		 * @param: wpIndex: index of the waypoint
		 */
		function handleSearchWaypointFailure(wpIndex) {
			waypoint.decrRequestCounterWaypoint(wpIndex);
			if (waypoint.getRequestCounterWaypoint(wpIndex) == 0) {
				ui.searchWaypointChangeToSearchingState(false, wpIndex);
				ui.showSearchWaypointError();
			}
		}

		/**
		 * the user selects one of the search results as new waypoint. The corresponding map feature is set, other search results are removed. Ui and internal variables are updated.
		 * @param atts: wpIndex: index of the waypoint; featureId: map feature id of the selected marker; searchIds: string of all search features for this search
		 */
		function handleWaypointResultClick(atts) {
			var wpIndex = atts.wpIndex;
			var featureId = atts.featureId;
			var searchIds = atts.searchIds;
			if (searchIds) {
				searchIds = searchIds.split(' ');
			}

			var type = selectWaypointType(wpIndex);
			var waypointResultId = map.addWaypointMarker(wpIndex, featureId, type);
			map.clearMarkers(map.SEARCH, searchIds);

			waypoint.setWaypoint(wpIndex, true);

			var position = map.convertFeatureIdToPositionString(waypointResultId, map.ROUTE_POINTS);
			ui.setWaypointFeatureId(wpIndex, waypointResultId, position, map.ROUTE_POINTS);

			//update preferences<commit_msg>Fixes #35<commit_after>var Controller = ( function(w) {'use strict';

		var $ = w.jQuery, ui = w.Ui, uiVersions = w.Versions, uiLanguages = w.Languages, waypoint = w.Waypoint, geolocator = w.Geolocator, searchAddress = w.SearchAddress, searchPoi = w.SearchPoi, route = w.Route, analyse = w.AccessibilityAnalysis, preferences = w.Preferences, openRouteService = w.OpenRouteService, Map = w.Map,
		//the map
		map,
		//Timeout for service responses
		SERVICE_TIMEOUT_INTERVAL = 10000,
		//timer
		timerRoute; //TODO more timers for various service calls

		function Controller() {
			//path to the proxy-script as workaround for JavaScript security errors
			OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

			//IE does not know console...
			if (!window.console) {
				window.console = {};
				window.console.log = function() {
				};
			}
		}

		/* *********************************************************************
		* GENERAL
		* *********************************************************************/

		/**
		 *called when sidebar toggles and the map area is resized
		 */
		function handleMapUpdate() {
			map.theMap.updateSize();
		}

		/* *********************************************************************
		* WAYPOINTS
		* *********************************************************************/

		/**
		 * parses the user input for the waypoint search and calls the Waypoint module to build a search request
		 * @param atts: query: the search query; wpIndex: index of the waypoint; searchIds: map feature ids of previous searches
		 */
		function handleWaypointRequest(atts) {
			ui.searchWaypointChangeToSearchingState(true, atts.wpIndex);
			var lastSearchResults = atts.searchIds;
			lastSearchResults = lastSearchResults ? lastSearchResults.split(' ') : null;

			if (lastSearchResults) {
				map.clearMarkers(map.SEARCH, lastSearchResults);
			}

			waypoint.incrRequestCounterWaypoint(atts.wpIndex);
			waypoint.find(atts.query, handleSearchWaypointResults, handleSearchWaypointFailure, atts.wpIndex, preferences.language);
		}

		/**
		 * forwards the waypoint search results to the Ui to display the addresses and to the map in order to add markers.
		 * @param results: results of the search query in XML format
		 * @param wpIndex: index of the waypoint
		 */
		function handleSearchWaypointResults(results, wpIndex) {
			//IE doesn't know responseXML, it can only provide text that has to be parsed to XML...
			results = results.responseXML ? results.responseXML : util.parseStringToDOM(results.responseText);

			//when the service gives response but contains an error the response is handeled as success, not error. We have to check for an error tag here:
			var responseError = util.getElementsByTagNameNS(results, namespaces.xls, 'ErrorList').length;
			if (parseInt(responseError) > 0) {
				//service response contains an error, switch to error handling function
				handleSearchWaypointFailure(wpIndex);
			} else {

				waypoint.decrRequestCounterWaypoint(wpIndex);
				if (waypoint.getRequestCounterWaypoint(wpIndex) == 0) {
					var listOfPoints = waypoint.parseResultsToPoints(results, wpIndex);

					ui.searchWaypointChangeToSearchingState(false, wpIndex);

					if (listOfPoints.length) {
						var listOfFeatures = map.addSearchAddressResultMarkers(listOfPoints, wpIndex);
						ui.updateSearchWaypointResultList(results, listOfFeatures, map.SEARCH, wpIndex);
					} else {
						ui.showSearchWaypointError(wpIndex)
					}

				}
			}
		}

		/**
		 * calls the UI to show a search error
		 * @param: wpIndex: index of the waypoint
		 */
		function handleSearchWaypointFailure(wpIndex) {
			waypoint.decrRequestCounterWaypoint(wpIndex);
			if (waypoint.getRequestCounterWaypoint(wpIndex) == 0) {
				ui.searchWaypointChangeToSearchingState(false, wpIndex);
				ui.showSearchWaypointError();
			}
		}

		/**
		 * the user selects one of the search results as new waypoint. The corresponding map feature is set, other search results are removed. Ui and internal variables are updated.
		 * @param atts: wpIndex: index of the waypoint; featureId: map feature id of the selected marker; searchIds: string of all search features for this search
		 */
		function handleWaypointResultClick(atts) {
			var wpIndex = atts.wpIndex;
			var featureId = atts.featureId;
			var searchIds = atts.searchIds;
			if (searchIds) {
				searchIds = searchIds.split(' ');
			}

			var type = selectWaypointType(wpIndex);
			var waypointResultId = map.addWaypointMarker(wpIndex, featureId, type);
			map.clearMarkers(map.SEARCH, searchIds);

			waypoint.setWaypoint(wpIndex, true);

			var position = map.convertFeatureIdToPositionString(waypointResultId, map.ROUTE_POINTS);
			map.zoomToMarker(util.convertPositionStringToLonLat(position), 14);
			ui.setWaypointFeatureId(wpIndex, waypointResultId, position, map.ROUTE_POINTS);

			//update preferences
{'fraction_non_alphanumeric': 0.14515962392809176, 'fraction_numerical': 0.0020663291662361815, 'mean_word_length': 4.229605618584549, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1011969', 'n_tokens_mistral': 3223, 'n_tokens_neox': 2677, 'n_words': 772}