<commit_before>////////////////////////////////////////////////////////////////////////////////
// Directory Selector Control
//
// Tree control designed specifically to display directories
////////////////////////////////////////////////////////////////////////////////
/*global jQuery */
var app = app || {};

app.controls = function (controls, $, services) {
	// tells whether an object has any own propertes
	function hasOwnProperties(obj) {
		var prop;
		for (prop in obj) {
			if (obj.hasOwnProperty(prop)) {
				return true;
			}
		}
		return false;
	}				

	// directory selection handler
	function onSelect($node, node) {
		var $dirsel = $node.closest('div.popup');
		$dirsel
			.find('button.ok')
				.removeAttr('disabled');
	}
	
	// directory expand / collapse handler
	// loads child directories on demand
	function onExpandCollapse($node, node) {
		var expanded = node.expanded(),
				empty = !hasOwnProperties(node.json()),
				$spinner;
	
		// acquiring sub-nodes when expanding an empty node
		if (expanded && empty) {
			$spinner = $node
				.closest('div.popup')
					.find('div.spinner')
						.show();
			services.getdirs(node.path().join('/'), function (json) {
				$spinner.hide();
				empty = !hasOwnProperties(json.data);
				if (empty) {
					// no subdirs, removing expand button
					$node
						.removeClass('expanded')
						.addClass('dead');
				} else {
					// has subdirs, creating child nodes
					node
						.json(json.data)
						.render();
				}
			});
		}
	}

	controls.dirsel = function () {		
		var self = controls.control.create(controls.popup('centered')),
				base_init = self.init,
				tree = controls.tree(onSelect, onExpandCollapse),
				onCancel, onOk;
		
		// initial service call for root dirs
		services.getdirs(null, function (json) {
			// initial tree contents
			tree
				.build(json.data)
				.appendTo(self);
				
			// re-rendering full control
			self
				.render()
				.find('div.spinner')
					.hide();
		});

		//////////////////////////////
		// Setters / getters

		self.onCancel = function (value) {
			onCancel = value;
			return self;
		};
		
		self.onOk = function (value) {
			onOk = value;
			return self;
		};
		
		self.selected = function () {
			return '/' + tree.selected().join('/');
		};
		
		//////////////////////////////
		// Overrides

		self.init = function (elem) {
			base_init.call(self, elem);
			elem<commit_msg>spinner on folder selector control is on by default<commit_after>////////////////////////////////////////////////////////////////////////////////
// Directory Selector Control
//
// Tree control designed specifically to display directories
////////////////////////////////////////////////////////////////////////////////
/*global jQuery */
var app = app || {};

app.controls = function (controls, $, services) {
	// tells whether an object has any own propertes
	function hasOwnProperties(obj) {
		var prop;
		for (prop in obj) {
			if (obj.hasOwnProperty(prop)) {
				return true;
			}
		}
		return false;
	}				

	// directory selection handler
	function onSelect($node, node) {
		var $dirsel = $node.closest('div.popup');
		$dirsel
			.find('button.ok')
				.removeAttr('disabled');
	}
	
	// directory expand / collapse handler
	// loads child directories on demand
	function onExpandCollapse($node, node) {
		var expanded = node.expanded(),
				empty = !hasOwnProperties(node.json()),
				$spinner;
	
		// acquiring sub-nodes when expanding an empty node
		if (expanded && empty) {
			$spinner = $node
				.closest('div.popup')
					.find('div.spinner')
						.show();
			services.getdirs(node.path().join('/'), function (json) {
				$spinner.hide();
				empty = !hasOwnProperties(json.data);
				if (empty) {
					// no subdirs, removing expand button
					$node
						.removeClass('expanded')
						.addClass('dead');
				} else {
					// has subdirs, creating child nodes
					node
						.json(json.data)
						.render();
				}
			});
		}
	}

	controls.dirsel = function () {		
		var self = controls.control.create(controls.popup('centered')),
				base_init = self.init,
				tree = controls.tree(onSelect, onExpandCollapse),
				onCancel, onOk;
		
		// initial service call for root dirs
		services.getdirs(null, function (json) {
			// initial tree contents
			tree
				.build(json.data)
				.appendTo(self);
				
			// re-rendering full control
			self
				.render()
				.find('div.spinner')
					.hide();
		});

		//////////////////////////////
		// Setters / getters

		self.onCancel = function (value) {
			onCancel = value;
			return self;
		};
		
		self.onOk = function (value) {
			onOk = value;
			return self;
		};
		
		self.selected = function () {
			return '/' + tree.selected().join('/');
		};
		
		//////////////////////////////
		// Overrides

		self.init = function (elem) {
			base_init.call(self, elem);
			elem
				.find('div.spinner')
					.show()
				.end()
{'fraction_non_alphanumeric': 0.22067553735926304, 'fraction_numerical': 0.0, 'mean_word_length': 1.913536076326774, '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': '2957026', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1417, 'n_words': 356}