<commit_before>Template.course_edit.created = function() {
	// Show category selection right away for new courses
	var editingCategories = !this.data || !this.data._id;
	this.editingCategories = new ReactiveVar(editingCategories);
	this.selectedCategories = new ReactiveVar(this.data && this.data.categories || []);
};

Template.course_edit.helpers({
	query: function() {
		return Session.get('search');
	},

	availableCategories: function() {
		return Object.keys(categories);
	},

	availableSubcategories: function(category) {
		// Hide if parent categories not selected
		var selectedCategories = Template.instance().selectedCategories.get();
		if (selectedCategories.indexOf(category) < 0) return [];

		return categories[category];
	},

	editingCategories: function() {
		return Template.instance().editingCategories.get();
	},

	available_roles: function() {
		return Roles.find({'preset': { $ne: true }});
	},

	roleDescription: function() {
		return 'roles.'+this.type+'.description';
	},

	roleSubscription: function() {
		return 'roles.'+this.type+'.subscribe';
	},

	isChecked: function() {
		var selectedCategories = Template.instance().selectedCategories.get();
		if (selectedCategories.length && selectedCategories.indexOf(''+this) >= 0) {
			return 'checkbox-checked';
		}
		return '';
	},

	checkCategory: function() {
		var selectedCategories = Template.instance().selectedCategories.get();
		if (selectedCategories.length) {
			return selectedCategories.indexOf(''+this) >= 0 ? 'checked' : '';
		}
	},

	hasRole: function() {
		var instance = Template.instance();
		return instance.data && instance.data.members && hasRoleUser(instance.data.members, this.type, Meteor.userId()) ? 'checked' : null;
	},

	regions: function() {
		return Regions.find();
	},

	currentRegion: function(region) {
		var currentRegion = Session.get('region');
		return currentRegion && region._id == currentRegion;
	},

	isInternal: function() {
		return this.internal ? "checked" : null;
	},

	proposeFromQuery: function() {
		var parentInstance = Template.instance().parentInstance();
		var filter = parentInstance.filter;
		if (!filter) return false;

		var filterQuery = filter.toQuery();
		var results = coursesFind(filterQuery, 36);

		var filterParams = parentInstance.filter.toParams();

		return (results.count() === 0) && filterParams.search;
	},

	courseSearch: function() {
		var parentInstance = Template.instance().parentInstance();
		var filterParams = parentInstance.filter.toParams();
		if (!filterParams) return false;

		return filterParams.search;
	}
});


Template.course_edit.rendered = function() {
	var desc = this.find('#editform_description');
	if (desc) new MediumEditor(desc);
};


Template.course_edit.events({<commit_msg>use created filter variable in course.edit.js<commit_after>Template.course_edit.created = function() {
	// Show category selection right away for new courses
	var editingCategories = !this.data || !this.data._id;
	this.editingCategories = new ReactiveVar(editingCategories);
	this.selectedCategories = new ReactiveVar(this.data && this.data.categories || []);
};

Template.course_edit.helpers({
	query: function() {
		return Session.get('search');
	},

	availableCategories: function() {
		return Object.keys(categories);
	},

	availableSubcategories: function(category) {
		// Hide if parent categories not selected
		var selectedCategories = Template.instance().selectedCategories.get();
		if (selectedCategories.indexOf(category) < 0) return [];

		return categories[category];
	},

	editingCategories: function() {
		return Template.instance().editingCategories.get();
	},

	available_roles: function() {
		return Roles.find({'preset': { $ne: true }});
	},

	roleDescription: function() {
		return 'roles.'+this.type+'.description';
	},

	roleSubscription: function() {
		return 'roles.'+this.type+'.subscribe';
	},

	isChecked: function() {
		var selectedCategories = Template.instance().selectedCategories.get();
		if (selectedCategories.length && selectedCategories.indexOf(''+this) >= 0) {
			return 'checkbox-checked';
		}
		return '';
	},

	checkCategory: function() {
		var selectedCategories = Template.instance().selectedCategories.get();
		if (selectedCategories.length) {
			return selectedCategories.indexOf(''+this) >= 0 ? 'checked' : '';
		}
	},

	hasRole: function() {
		var instance = Template.instance();
		return instance.data && instance.data.members && hasRoleUser(instance.data.members, this.type, Meteor.userId()) ? 'checked' : null;
	},

	regions: function() {
		return Regions.find();
	},

	currentRegion: function(region) {
		var currentRegion = Session.get('region');
		return currentRegion && region._id == currentRegion;
	},

	isInternal: function() {
		return this.internal ? "checked" : null;
	},

	proposeFromQuery: function() {
		var parentInstance = Template.instance().parentInstance();
		var filter = parentInstance.filter;
		if (!filter) return false;

		var filterQuery = filter.toQuery();
		var results = coursesFind(filterQuery, 36);

		var filterParams = filter.toParams();

		return (results.count() === 0) && filterParams.search;
	},

	courseSearch: function() {
		var parentInstance = Template.instance().parentInstance();
		var filterParams = parentInstance.filter.toParams();
		if (!filterParams) return false;

		return filterParams.search;
	}
});


Template.course_edit.rendered = function() {
	var desc = this.find('#editform_description');
	if (desc) new MediumEditor(desc);
};


Template.course_edit.events({
{'fraction_non_alphanumeric': 0.14871981114944616, 'fraction_numerical': 0.002179044852006537, 'mean_word_length': 4.941747572815534, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5437353', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1568, 'n_words': 344}