<commit_before>/**
 * Mail
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2015, 2016
 */

define(function(require) {
	'use strict';

	var _ = require('underscore');
	var Marionette = require('backbone.marionette');
	var OC = require('OC');
	var Radio = require('radio');
	var FolderTemplate = require('templates/folder.html');

	return Marionette.View.extend({

		tagName: 'li',

		updateElClasses: function() {
			var classes = [
				'with-counter'
			];
			if (this.model.get('unseen')) {
				classes.push('unseen');
			}
			if (this.model.get('active')) {
				classes.push('active');
			}
			if (this.model.get('specialRole')) {
				classes.push('special-' + this.model.get('specialRole'));
			}
			if (this.model.folders.length > 0) {
				classes.push('collapsible');
			}
			if (this.model.get('open')) {
				classes.push('open');
			}
			// .removeClass() does not work, https://bugs.jqueryui.com/ticket/9015
			this.$el.prop('class', '');
			var _this = this;
			_.each(classes, function(clazz) {
				_this.$el.addClass(clazz);
			});
		},

		template: FolderTemplate,

		templateContext: function() {
			var count = null;
			if (this.model.get('specialRole') === 'drafts') {
				count = this.model.get('total');
			} else {
				count = this.model.get('unseen');
			}

			var url = OC.generateUrl('apps/mail/#accounts/{accountId}/folders/{folderId}', {
				// TODO: account should be property of folder
				accountId: this.model.get('accountId'),
				folderId: this.model.get('id')
			});

			var folders = this.model.folders.length > 0 ? this.model.folders.toJSON() : undefined;

			return {
				count: count,
				url: url,
				folders: folders
			};
		},

		regions: {
			folders: '.folders'
		},

		events: {
			'click .collapse': 'collapseFolder',
			'click .folder': 'loadFolder'
		},

		modelEvents: {
			change: 'render'
		},

		collapseFolder: function(e) {
			e.preventDefault();
			this.model.toggleOpen();
		},

		loadFolder: function(e) {
			e.preventDefault();
			// TODO: account should be property of folder
			var account = require('state').accounts.get(this.model.get('accountId'));
			var folder = this.model;

			if (folder.get('noSelect')) {
				console.info('ignoring \'loadFolder\' event for noSelect folder');
				return;
			}

			Radio.navigation.trigger('folder', account.get('accountId'), folder.get('id'));
		},

		onRender: function() {<commit_msg>Fix subfolder click event propagation<commit_after>/**
 * Mail
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2015, 2016
 */

define(function(require) {
	'use strict';

	var _ = require('underscore');
	var Marionette = require('backbone.marionette');
	var OC = require('OC');
	var Radio = require('radio');
	var FolderTemplate = require('templates/folder.html');

	return Marionette.View.extend({

		tagName: 'li',

		updateElClasses: function() {
			var classes = [
				'with-counter'
			];
			if (this.model.get('unseen')) {
				classes.push('unseen');
			}
			if (this.model.get('active')) {
				classes.push('active');
			}
			if (this.model.get('specialRole')) {
				classes.push('special-' + this.model.get('specialRole'));
			}
			if (this.model.folders.length > 0) {
				classes.push('collapsible');
			}
			if (this.model.get('open')) {
				classes.push('open');
			}
			// .removeClass() does not work, https://bugs.jqueryui.com/ticket/9015
			this.$el.prop('class', '');
			var _this = this;
			_.each(classes, function(clazz) {
				_this.$el.addClass(clazz);
			});
		},

		template: FolderTemplate,

		templateContext: function() {
			var count = null;
			if (this.model.get('specialRole') === 'drafts') {
				count = this.model.get('total');
			} else {
				count = this.model.get('unseen');
			}

			var url = OC.generateUrl('apps/mail/#accounts/{accountId}/folders/{folderId}', {
				// TODO: account should be property of folder
				accountId: this.model.get('accountId'),
				folderId: this.model.get('id')
			});

			var folders = this.model.folders.length > 0 ? this.model.folders.toJSON() : undefined;

			return {
				count: count,
				url: url,
				folders: folders
			};
		},

		regions: {
			folders: '.folders'
		},

		events: {
			'click .collapse': 'collapseFolder',
			'click .folder': 'loadFolder'
		},

		modelEvents: {
			change: 'render'
		},

		collapseFolder: function(e) {
			e.preventDefault();
			this.model.toggleOpen();
		},

		loadFolder: function(e) {
			if (e.isDefaultPrevented()) {
				// Event has been handled already, e.g. by a subfolder
				return;
			}
			e.preventDefault();
			// TODO: account should be property of folder
			var account = require('state').accounts.get(this.model.get('accountId'));
			var folder = this.model;

			if (folder.get('noSelect')) {
				console.info('ignoring \'loadFolder\' event for noSelect folder');
				return;
			}

			Radio.navigation.trigger('folder', account.get('accountId'), folder.get('id'));
		},

		onRender: function() {
{'fraction_non_alphanumeric': 0.173904576436222, 'fraction_numerical': 0.005842259006815969, 'mean_word_length': 3.2551781275890637, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '1269119', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1678, 'n_words': 358}