<commit_before>"use strict";

// Pre-create a plain Collection so it can be used in the model's relations.
var Tasks = Backbone.Collection.extend({

	initialize: function () {

		// Track parent.
		// (Setting parent to null on remove is dangerous and pointless.)
		this.on('add', function (model) {

			var changed = false;
			if (model.get('parentId') != this.parent.id) {

				// New place in the the project tree.
				model.set({parentId: this.parent.id});
				changed = true;
			}

			// The model will probably be saved in updateOrdering, so
			// check if the order changed (was saved), otherwise save.
			// Don't wanna save twice.
			var oldOrdering = model.get('ordering');
			setTimeout(function () {

				var saved = true;

				if (oldOrdering == model.get('ordering')) {

					saved = false;
				}

				if (changed && !saved) {

					model.save()
				}
			}, 0);

		}.bind(this));

		// Track relative order.
		this.on('add',    this.updateOrdering, this);
		this.on('remove', this.updateOrdering, this);

		// Re-project.
		this.on('add', function (model) {

			model.projectRoot().calculateProjection();
		});


		// Make done propagate up.
		this.on('change:done', function () {

			if (this.parent) {

				// I'd be happier if this wasn't saved until the changed child was.
				this.parent.save({'done': _.every(this.pluck('done'))});
			}

		}.bind(this));
	},


	create: function () {

		// Same as default, but auto-create the guid locally, and trigger 'focus' event.

		var topCollection = this;
		while (topCollection.parent.collection) {
			topCollection = topCollection.parent.collection;
		}

		var _arguments = _.toArray(arguments);
		_arguments[0] = _arguments[0] || {
			id: makeGuid(),
			parentId: this.parent.id,
			projectId: topCollection.parent.id
		};
		Backbone.Collection.prototype.create.apply(this, _arguments).trigger('focus');
	},


	updateOrdering: function () {

		this.models.forEach(function (model, index) {

			if (model.get('ordering') != index) {

				model.save({ordering: index});
			}
		});
	}
});

var Task = Backbone.Model.extend({

	defaults: {
		color: 'white',
		tasks: []
	},


	relations: {
		tasks: Tasks
	},<commit_msg>Made task creation not unnecessarily save at once.<commit_after>"use strict";

// Pre-create a plain Collection so it can be used in the model's relations.
var Tasks = Backbone.Collection.extend({

	initialize: function () {

		// Track parent.
		// (Setting parent to null on remove is dangerous and pointless.)
		this.on('add', function (model) {

			var changed = false;
			if (model.get('parentId') != this.parent.id) {

				// New place in the the project tree.
				model.set({parentId: this.parent.id});
				changed = true;
			}

			// The model will probably be saved in updateOrdering, so
			// check if the order changed (was saved), otherwise save.
			// Don't wanna save twice.
			var oldOrdering = model.get('ordering');
			setTimeout(function () {

				var saved = true;

				if (oldOrdering == model.get('ordering')) {

					saved = false;
				}

				if (changed && !saved) {

					model.save()
				}
			}, 0);

		}.bind(this));

		// Track relative order.
		this.on('add',    this.updateOrdering, this);
		this.on('remove', this.updateOrdering, this);

		// Re-project.
		this.on('add', function (model) {

			model.projectRoot().calculateProjection();
		});


		// Make done propagate up.
		this.on('change:done', function () {

			if (this.parent) {

				// I'd be happier if this wasn't saved until the changed child was.
				this.parent.save({'done': _.every(this.pluck('done'))});
			}

		}.bind(this));
	},


	create: function () {

		// Auto-create the guid locally, and trigger 'focus' event.

		var newTask = new Task({
			id: makeGuid(),
			parentId: this.parent.id,
			projectId: this.parent.projectRoot().id
		});

		this.add(newTask);

		newTask.trigger('focus');
	},


	updateOrdering: function () {

		this.models.forEach(function (model, index) {

			if (model.get('ordering') != index) {

				model.save({ordering: index});
			}
		});
	}
});

var Task = Backbone.Model.extend({

	defaults: {
		color: 'white',
		tasks: []
	},


	relations: {
		tasks: Tasks
	},
{'fraction_non_alphanumeric': 0.1565196548418025, 'fraction_numerical': 0.0009587727708533077, 'mean_word_length': 2.947965941343425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '63145', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1305, 'n_words': 363}