<commit_before>import PleaseLogin from '/imports/ui/lib/please-login.js';
import '/imports/StringTools.js';

import '/imports/ui/components/price-policy/price-policy.js';
import '/imports/ui/components/region-tag/region-tag.js';

Template.courseEdit.created = function() {
	var instance = this;

	instance.busy(false);

	// 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 || []);

	instance.editableDescription = Editable(
		false,
		false,
		mf('course.description.placeholder', "Describe your idea, so that more people will find it and that they`ll know what to expect."),
		false
	);

	instance.autorun(function() {
		instance.editableDescription.setText(Template.currentData().description);
	});

	if (instance.data.group) {
		instance.subscribe('group', instance.data.group);
	}
};

Template.courseEdit.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();
	},

	availableRoles() {
		return Roles.filter(role => {
			if (role.preset) return false;

			if (this.isFrame) {
				const neededRoles = this.neededRoles;
				if (neededRoles && neededRoles.length) {
					if (neededRoles.includes(role.type)) return true;
				} else {
					if (role.type !== 'host') return true;
					return false;
				}
			} else {
				return 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' : '';
		}
	},
<commit_msg>small code improvement<commit_after>import PleaseLogin from '/imports/ui/lib/please-login.js';
import '/imports/StringTools.js';

import '/imports/ui/components/price-policy/price-policy.js';
import '/imports/ui/components/region-tag/region-tag.js';

Template.courseEdit.created = function() {
	var instance = this;

	instance.busy(false);

	// 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 || []);

	instance.editableDescription = Editable(
		false,
		false,
		mf('course.description.placeholder', "Describe your idea, so that more people will find it and that they`ll know what to expect."),
		false
	);

	instance.autorun(function() {
		instance.editableDescription.setText(Template.currentData().description);
	});

	if (instance.data.group) {
		instance.subscribe('group', instance.data.group);
	}
};

Template.courseEdit.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();
	},

	availableRoles() {
		return Roles.filter(role => {
			if (role.preset) return false;

			if (this.isFrame) {
				const neededRoles = this.neededRoles;
				if (neededRoles && neededRoles.length) {
					if (neededRoles.includes(role.type)) return true;
				} else if (role.type !== 'host') {
					return true;
				}
			} else {
				return 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' : '';
		}
	},

{'fraction_non_alphanumeric': 0.14581657280772325, 'fraction_numerical': 0.0012067578439259854, 'mean_word_length': 4.417211328976035, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3299371', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1471, 'n_words': 310}