<commit_before>"use strict";

Template.eventEditLocation.onCreated(function() {
	var instance = this;
	instance.parent = instance.parentInstance(); // Something, somewhere, must have gone terribly wrong (for this line to exist)

	instance.locationTracker = LocationTracker();
	instance.changed = new ReactiveVar(false);
	instance.location = new ReactiveVar();
	instance.search = new ReactiveVar('');

	instance.autorun(function() {
		var regionId = instance.parent.selectedRegion.get();
		instance.locationTracker.setRegion(regionId);
	});

	instance.autorun(function() {
		if (instance.changed.get()) {
			var location = instance.location.get();
			instance.locationTracker.setLocation();
			if (location.loc) instance.locationTracker.markers.insert({ candidate: true, loc: location.loc });
		} else {
			var originalLocation = instance.parent.selectedLocation.get();
			instance.location.set(originalLocation);
			instance.locationTracker.setLocation(originalLocation);
		}
	});

	// Tracked so that observe() will be stopped when the template is destroyed
	instance.autorun(function() {
		instance.locationTracker.markers.find({ proposed: true, selected: true }).observe({
			added: function(mark) {
				// When a propsed marker is selected, we clear the other location proposals and
				// store it as new location for the event
				var updLocation = instance.location.get();
				updLocation.loc = mark.loc;
				if (mark.presetName) updLocation.name = mark.presetName;
				instance.location.set(updLocation);
				instance.changed.set(true);
				instance.locationTracker.markers.remove({ proposed: true });
			},
		});
	});

	instance.autorun(function() {
		var search = instance.search.get();

		if (search.length > 0) {
			var regionId = instance.parent.selectedRegion.get();
		}
	});

	instance.autorun(function() {
		var search = instance.search.get().trim();

		instance.locationTracker.markers.remove({ proposed: true });

		if (search.length > 0) {
			var regionId = instance.parent.selectedRegion.get();
			subs.subscribe('locationsFind', { search: search, region: regionId });
			locationsFind({
				search: search,
				region: regionId
			}).observe({
				'added': function(location) {
					location.proposed = true;
					location.presetName = location.name;
					instance.locationTracker.markers.insert(location);
				}
			});
		}
	});

	// unset: no location selected
	// preset: one of the preset locations is referenced
	// own: name and coordinates were entered for this event specifically
	instance.locationIs = function(type) {
		var location = instance.location.get();
		if (!location) return 'unset' === type;
		if (location._id) return 'preset' === type;
		if (location.name) return 'own' === type;<commit_msg>record location<commit_after>"use strict";

Template.eventEditLocation.onCreated(function() {
	var instance = this;
	instance.parent = instance.parentInstance(); // Something, somewhere, must have gone terribly wrong (for this line to exist)

	instance.locationTracker = LocationTracker();
	instance.changed = new ReactiveVar(false);
	instance.location = new ReactiveVar();
	instance.search = new ReactiveVar('');

	instance.autorun(function() {
		var regionId = instance.parent.selectedRegion.get();
		instance.locationTracker.setRegion(regionId);
	});

	instance.autorun(function() {
		if (instance.changed.get()) {
			var location = instance.location.get();
			instance.locationTracker.setLocation();
			if (location.loc) instance.locationTracker.markers.insert({ candidate: true, loc: location.loc });
		} else {
			var originalLocation = instance.parent.selectedLocation.get();
			instance.location.set(originalLocation);
			instance.locationTracker.setLocation(originalLocation);
		}
	});

	// Tracked so that observe() will be stopped when the template is destroyed
	instance.autorun(function() {
		instance.locationTracker.markers.find({ proposed: true, selected: true }).observe({
			added: function(mark) {
				// When a propsed marker is selected, we clear the other location proposals and
				// store it as new location for the event
				var updLocation = instance.location.get();
				updLocation.loc = mark.loc;
				if (mark.presetName) updLocation.name = mark.presetName;
				if (mark.preset) {
					updLocation._id = mark._id;
				}
				instance.location.set(updLocation);
				instance.changed.set(true);
				instance.locationTracker.markers.remove({ proposed: true });
			},
		});
	});

	instance.autorun(function() {
		var search = instance.search.get();

		if (search.length > 0) {
			var regionId = instance.parent.selectedRegion.get();
		}
	});

	instance.autorun(function() {
		var search = instance.search.get().trim();

		instance.locationTracker.markers.remove({ proposed: true });

		if (search.length > 0) {
			var regionId = instance.parent.selectedRegion.get();
			subs.subscribe('locationsFind', { search: search, region: regionId });
			locationsFind({
				search: search,
				region: regionId
			}).observe({
				'added': function(location) {
					location.proposed = true;
					location.presetName = location.name;
					location.preset = true;
					instance.locationTracker.markers.insert(location);
				}
			});
		}
	});

	// unset: no location selected
	// preset: one of the preset locations is referenced
	// own: name and coordinates were entered for this event specifically
	instance.locationIs = function(type) {
		var location = instance.location.get();
		if (!location) return 'unset' === type;
		if (location._id) return 'preset' === type;
		if (location.name) return 'own' === type;
{'fraction_non_alphanumeric': 0.13239791329375786, 'fraction_numerical': 0.0007195538765965102, 'mean_word_length': 4.110294117647059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5551301', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1584, 'n_words': 396}