<commit_before>/**
 * Groups tree
 */

!function(global, $, _) {
	'use strict';

	function ConcreteGroupsTree($element, options) {
		var my = this;
		options = options || {};
		options = $.extend({
			treeID: false,
			minimumExpandLevel: 2,
			selectNodeByKey: [],
			enableDragAndDrop: true,
            onSelect: false, // This is when you click a checkbox or radio button
            onClick: false, // this is when you click a group title when not in chooseNodeInForm mode.
			readOnly: false,
			removeNodesByID: [],
			chooseNodeInForm: false // false (no ability to choose a node as a form element), "single" uses radio, "multiple" = checkbox.
		}, options);
		my.options = options;
		my.$element = $element;
		my._menuTemplate = _.template(ConcreteGroupsTree.getMenu());
		my.setupTree();
		my.setupTreeEvents();
		return my.$element;
	}

	ConcreteGroupsTree.prototype = {

    	dragRequest: function(sourceNode, node, hitMode) {
    		var treeNodeParentID = node.parent.data.key;
    		if (hitMode == 'over') {
    			treeNodeParentID = node.data.key;
    		}
    		jQuery.fn.dialog.showLoader();
			var params = [{'name': 'sourceTreeNodeID', 'value': sourceNode.data.key}, {'name': 'treeNodeParentID', 'value': treeNodeParentID}];
			var childNodes = node.parent.getChildren();
			if (childNodes) {
				for (var i = 0; i < childNodes.length; i++) {
					var childNode = childNodes[i];
					params.push({'name': 'treeNodeID[]', 'value': childNode.data.key});
				}
			}
			$.ajax({
				dataType: 'json',
				type: 'POST',
				data: params,
				url: CCM_TOOLS_PATH + '/tree/node/drag_request',
				success: function(r) {
					ccm_parseJSON(r, function() {});
    				jQuery.fn.dialog.hideLoader();
				}
			});
    	},

		setupTree: function() {
			var my = this,
				options = my.options,
				classNames = {},
				checkbox = false,
				ajaxData = {};

			ajaxData.treeID = options.treeID;

			if (options.chooseNodeInForm) {
				checkbox = true;
				switch(options.chooseNodeInForm) {
					case 'single':
						classNames = {'checkbox': 'dynatree-radio'};
						break;
					case 'multiple':
						classNames = {'checkbox': 'dynatree-checkbox'};
						break;
							
				}
				if (options.selectNodesByKey.length) {
					ajaxData.treeNodeSelectedIDs = options.selectNodesByKey;
				}
			}
						
    		$(my.$element).dynatree({
				autoFocus: false,
				cookieId: 'ConcreteGroups',
				cookie: {
					path: CCM_REL + '/'
				},
				initAjax: {
					url: CCM_TOOLS_PATH + '/tree/load',
					type: 'post',
					data: ajaxData
				},
				onLazyRead: function(node) {
					my.reloadNode(node);
				},
                onSelect: options.onSelect,
				selectMode: 1,
				checkbox: checkbox,
				classNames: classNames,
				minExpandLevel: options.minimumExpandLevel,
				clickFolderMode: 1,
				onPostInit: function() {
		    		var $tree = my.$element;

		    		if (options.removeNodesByID.length) {
		    			for (var i = 0; i < options.removeNodesByID.length; i++) {
		    				var nodeID = options.removeNodesByID[i];
		    				var node = this.getNodeByKey(nodeID);
		    				if (node) {
		    					node.remove();
		    				}
		    			}
		    		}

					if (options.readOnly) {
			    		$tree.dynatree('disable');
					}

					if (options.chooseNodeInForm) {
						var selectedNodes = $tree.dynatree('getTree');
						selectedNodes = selectedNodes.getSelectedNodes();<commit_msg>Allow multiple node selection in group tree<commit_after>/**
 * Groups tree
 */

!function(global, $, _) {
	'use strict';

	function ConcreteGroupsTree($element, options) {
		var my = this;
		options = options || {};
		options = $.extend({
			treeID: false,
			minimumExpandLevel: 2,
			selectNodeByKey: [],
			enableDragAndDrop: true,
            onSelect: false, // This is when you click a checkbox or radio button
            onClick: false, // this is when you click a group title when not in chooseNodeInForm mode.
			readOnly: false,
			removeNodesByID: [],
			chooseNodeInForm: false // false (no ability to choose a node as a form element), "single" uses radio, "multiple" = checkbox.
		}, options);
		my.options = options;
		my.$element = $element;
		my._menuTemplate = _.template(ConcreteGroupsTree.getMenu());
		my.setupTree();
		my.setupTreeEvents();
		return my.$element;
	}

	ConcreteGroupsTree.prototype = {

    	dragRequest: function(sourceNode, node, hitMode) {
    		var treeNodeParentID = node.parent.data.key;
    		if (hitMode == 'over') {
    			treeNodeParentID = node.data.key;
    		}
    		jQuery.fn.dialog.showLoader();
			var params = [{'name': 'sourceTreeNodeID', 'value': sourceNode.data.key}, {'name': 'treeNodeParentID', 'value': treeNodeParentID}];
			var childNodes = node.parent.getChildren();
			if (childNodes) {
				for (var i = 0; i < childNodes.length; i++) {
					var childNode = childNodes[i];
					params.push({'name': 'treeNodeID[]', 'value': childNode.data.key});
				}
			}
			$.ajax({
				dataType: 'json',
				type: 'POST',
				data: params,
				url: CCM_TOOLS_PATH + '/tree/node/drag_request',
				success: function(r) {
					ccm_parseJSON(r, function() {});
    				jQuery.fn.dialog.hideLoader();
				}
			});
    	},

		setupTree: function() {
			var my = this,
				options = my.options,
				classNames = {},
				checkbox = false,
				ajaxData = {};

			ajaxData.treeID = options.treeID;

			if (options.chooseNodeInForm) {
				checkbox = true;
				switch(options.chooseNodeInForm) {
					case 'single':
						classNames = {'checkbox': 'dynatree-radio'};
						break;
					case 'multiple':
						classNames = {'checkbox': 'dynatree-checkbox'};
						break;
							
				}
				if (options.selectNodesByKey.length) {
					ajaxData.treeNodeSelectedIDs = options.selectNodesByKey;
				}
			}
						
    		$(my.$element).dynatree({
				autoFocus: false,
				cookieId: 'ConcreteGroups',
				cookie: {
					path: CCM_REL + '/'
				},
				initAjax: {
					url: CCM_TOOLS_PATH + '/tree/load',
					type: 'post',
					data: ajaxData
				},
				onLazyRead: function(node) {
					my.reloadNode(node);
				},
                onSelect: options.onSelect,
				selectMode: options.chooseNodeInForm === 'multiple' ? 3 : 1, // allow multi-select for checkboxes
				checkbox: checkbox,
				classNames: classNames,
				minExpandLevel: options.minimumExpandLevel,
				clickFolderMode: 1,
				onPostInit: function() {
		    		var $tree = my.$element;

		    		if (options.removeNodesByID.length) {
		    			for (var i = 0; i < options.removeNodesByID.length; i++) {
		    				var nodeID = options.removeNodesByID[i];
		    				var node = this.getNodeByKey(nodeID);
		    				if (node) {
		    					node.remove();
		    				}
		    			}
		    		}

					if (options.readOnly) {
			    		$tree.dynatree('disable');
					}

					if (options.chooseNodeInForm) {
						var selectedNodes = $tree.dynatree('getTree');
						selectedNodes = selectedNodes.getSelectedNodes();
{'fraction_non_alphanumeric': 0.13803636363636362, 'fraction_numerical': 0.0016, 'mean_word_length': 2.641949152542373, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6185056', 'n_tokens_mistral': 2840, 'n_tokens_neox': 2227, 'n_words': 488}