<commit_before>;(function() {	
	"use strict";
	owid.namespace("App.Views.Form.EntitiesSectionView");

	var ColorPicker = App.Views.UI.ColorPicker;

	/**
	 * Responsible for the "Pick your countries" section in the editor
	 **/
	App.Views.Form.EntitiesSectionView = owid.View.extend({
		el: "#form-view #data-tab .entities-section",
		events: {
			"change .countries-select": "onCountriesSelect",
			"change [name='add-country-mode']": "onAddCountryModeChange",			
			"click .country-label .fa-remove": "onRemoveEntity",
			"click .country-label": "onEntityColorpicker"
		},

		initialize: function(options) {
			this.dispatcher = options.dispatcher;
			this.$currentEntities = this.$el.find(".selected-countries-box");
			this.$entitiesSelect = this.$el.find(".countries-select");
			this.$addCountryControlInput = this.$el.find("[name='add-country-control']");
			this.listenTo(App.VariableData, "change:availableEntities", this.render.bind(this));
			this.listenTo(App.ChartModel, "change:selected-countries", this.render.bind(this));
			this.listenTo(App.ChartModel, "change:add-country-mode", this.renderAddCountryMode.bind(this));
			this.render();
		},

		render: function() {
			var availableEntities = App.VariableData.get("availableEntities"),
				selectedEntities = App.ChartModel.get("selected-countries"),
				selectedEntitiesById = App.ChartModel.getSelectedEntitiesById();

			// Show all the entities that are already selected
			this.$currentEntities.empty();
			_.each(selectedEntities, function(entity) {
				var $li = $("<li class='country-label'><span class='fa fa-remove'></span>" + entity.name + "</li>");
				$li.attr("data-id", entity.id);
				$li.attr("data-name", entity.name);
				if (entity.color) {
					$li.css("background-color", entity.color);
					$li.attr("data-color", entity.color);
				}
				this.$currentEntities.append($li);
			}.bind(this));

			// Fill the entity selector with default option and the available non-selected entities
			this.$entitiesSelect.empty();
			this.$entitiesSelect.append("<option selected disabled>Select entity</option>");
			_.each(availableEntities, function(entity) {
				if (!selectedEntitiesById[entity.id])
					this.$entitiesSelect.append($("<option value='" + entity.id + "'>" + entity.name + "</option>"));
			}.bind(this));
		},

		renderAddCountryMode: function() {
			// Allow choosing whether or not the viewer can add their own countries
			var addCountryMode = App.ChartModel.get("add-country-mode");
			this.$el.find("[name='add-country-mode']").filter("[value='" + addCountryMode + "']").prop("checked", true);
		},

		onRemoveEntity: function(evt) {
			var $li = $(evt.target).closest(".country-label");
			App.ChartModel.removeSelectedCountry($li.attr("data-id"));
		},

		onEntityColorpicker: function(evt) {
			var $li = $(evt.target).closest(".country-label");
			if (this.colorPicker) this.colorPicker.onClose();
			this.colorPicker = new ColorPicker({ target: $li, currentColor: $li.attr("data-color") });
			this.colorPicker.onSelected = function(value) {
				$li.css("background-color", value);
				$li.attr("data-color", value);
				App.ChartModel.updateSelectedCountry($li.attr("data-id"), value);
			};
		},

		onCountriesSelect: function(evt) {
			var selectedId = this.$entitiesSelect.val(),
				entity = App.VariableData.get("entityKey")[selectedId];

			App.ChartModel.addSelectedCountry({ id: +selectedId, name: entity.name });
		},

		onAddCountryModeChange: function(evt) {
			var $input = $("[name='add-country-mode']:checked");
			App.ChartModel.set("add-country-mode", $input.val());
		}
	});
})();<commit_msg>render add-country-mode setting correctly<commit_after>;(function() {	
	"use strict";
	owid.namespace("App.Views.Form.EntitiesSectionView");

	var ColorPicker = App.Views.UI.ColorPicker;

	/**
	 * Responsible for the "Pick your countries" section in the editor
	 **/
	App.Views.Form.EntitiesSectionView = owid.View.extend({
		el: "#form-view #data-tab .entities-section",
		events: {
			"change .countries-select": "onCountriesSelect",
			"change [name='add-country-mode']": "onAddCountryModeChange",			
			"click .country-label .fa-remove": "onRemoveEntity",
			"click .country-label": "onEntityColorpicker"
		},

		initialize: function(options) {
			this.dispatcher = options.dispatcher;
			this.$currentEntities = this.$el.find(".selected-countries-box");
			this.$entitiesSelect = this.$el.find(".countries-select");
			this.$addCountryControlInput = this.$el.find("[name='add-country-control']");
			this.listenTo(App.VariableData, "change:availableEntities", this.render.bind(this));
			this.listenTo(App.ChartModel, "change:selected-countries", this.render.bind(this));
			this.listenTo(App.ChartModel, "change:add-country-mode", this.renderAddCountryMode.bind(this));
			this.render();
			this.renderAddCountryMode();
		},

		render: function() {
			var availableEntities = App.VariableData.get("availableEntities"),
				selectedEntities = App.ChartModel.get("selected-countries"),
				selectedEntitiesById = App.ChartModel.getSelectedEntitiesById();

			// Show all the entities that are already selected
			this.$currentEntities.empty();
			_.each(selectedEntities, function(entity) {
				var $li = $("<li class='country-label'><span class='fa fa-remove'></span>" + entity.name + "</li>");
				$li.attr("data-id", entity.id);
				$li.attr("data-name", entity.name);
				if (entity.color) {
					$li.css("background-color", entity.color);
					$li.attr("data-color", entity.color);
				}
				this.$currentEntities.append($li);
			}.bind(this));

			// Fill the entity selector with default option and the available non-selected entities
			this.$entitiesSelect.empty();
			this.$entitiesSelect.append("<option selected disabled>Select entity</option>");
			_.each(availableEntities, function(entity) {
				if (!selectedEntitiesById[entity.id])
					this.$entitiesSelect.append($("<option value='" + entity.id + "'>" + entity.name + "</option>"));
			}.bind(this));
		},

		renderAddCountryMode: function() {
			// Allow choosing whether or not the viewer can add their own countries
			var addCountryMode = App.ChartModel.get("add-country-mode");
			this.$el.find("[name='add-country-mode']").filter("[value='" + addCountryMode + "']").prop("checked", true);
		},

		onRemoveEntity: function(evt) {
			var $li = $(evt.target).closest(".country-label");
			App.ChartModel.removeSelectedCountry($li.attr("data-id"));
		},

		onEntityColorpicker: function(evt) {
			var $li = $(evt.target).closest(".country-label");
			if (this.colorPicker) this.colorPicker.onClose();
			this.colorPicker = new ColorPicker({ target: $li, currentColor: $li.attr("data-color") });
			this.colorPicker.onSelected = function(value) {
				$li.css("background-color", value);
				$li.attr("data-color", value);
				App.ChartModel.updateSelectedCountry($li.attr("data-id"), value);
			};
		},

		onCountriesSelect: function(evt) {
			var selectedId = this.$entitiesSelect.val(),
				entity = App.VariableData.get("entityKey")[selectedId];

			App.ChartModel.addSelectedCountry({ id: +selectedId, name: entity.name });
		},

		onAddCountryModeChange: function(evt) {
			var $input = $("[name='add-country-mode']:checked");
			App.ChartModel.set("add-country-mode", $input.val());
		}
	});
})();
{'fraction_non_alphanumeric': 0.1782286811077598, 'fraction_numerical': 0.0, 'mean_word_length': 4.547528517110266, 'pattern_counts': {'":': 8, '<': 19, '<?xml version=': 0, '>': 19, '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': '6266090', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2276, 'n_words': 390}