<commit_before>(function() {

var ui = angular.module('axelor.ui');

function TableLayout(items, attrs, $scope, $compile) {

	var colWidths = attrs.widths,
		numCols = +attrs.cols || 4,
		curCol = 0,
		layout = [[]];

	function add(item, label) {
		
		if (item.is('br')) {
			curCol = 0;
			item.hide();
			return layout.push([]);
		}

		var row = _.last(layout),
			cell = null,
			colspan = +item.attr('x-colspan') || 1,
			rowspan = +item.attr('x-rowspan') || 1;
		
		if (curCol + colspan >= numCols + 1) {
			curCol = 0, row = [];
			layout.push(row);
		}
		
		if (label) {
			cell = {};
			cell.elem = label;
			cell.css = label.attr('x-cell-css');
			row.push(cell);
			if (rowspan > 1) cell.rowspan = rowspan;
			if (colspan > 1) colspan -= 1;
			curCol += 1;
		}

		cell = {};
		cell.elem = item;
		cell.css = item.attr('x-cell-css');
		if (colspan > 1) cell.colspan = colspan;
		if (rowspan > 1) cell.rowspan = rowspan;
	
		row.push(cell);
		curCol += colspan;
	}

	// auto-generate colWidths
	if (numCols > 3 && !colWidths) {
		var labelCols = Math.floor(numCols / 2),
			itemCols = Math.ceil(numCols / 2),
			forLabels = 30 / labelCols,
			forItems = 70 / itemCols;

		colWidths = [];
		for(var i = 0 ; i < numCols ; i++) {
			colWidths[i] = (i % 2 == 1 || i >= (labelCols * 2) ? forItems : forLabels) + "%";
		}
	}

	if (colWidths && angular.isString(colWidths)) {
		colWidths = colWidths.trim().split(/\s*,\s*/);
		for(var i = 0 ; i < colWidths.length; i++) {
			var width = colWidths[i];
			if (/^(\d+)$/.test(width)) width = width + 'px';
			if (width == '*') width = 'auto';
			colWidths[i] = width;
		}
	}

	items.each(function(){
		var el = $(this),
			title = el.attr('x-title'),
			noTitle = el.attr('x-show-title') == 'false';

		if (numCols > 1 && !noTitle && title) {
			var label = $('<label ui-label></label>').html(title).attr('x-for-widget', el.attr('id')),
				labelElem = $compile(label)($scope);
			el.data('label', labelElem);
			return add(el, labelElem);
		}
		add(el);
	});
	
	var table = $('<table class="form-layout"></table');
	
	if (_.isArray(colWidths)) {
		var colGroup = $('<colgroup></colgroup>').appendTo(table);
		_.each(colWidths, function(cw) {
			$('<col></col>').css('width', cw).appendTo(colGroup);
		});
	}

	_.each(layout, function(row){
		var tr = $('<tr></tr>'),
			numCells = 0;
		_.each(row, function(cell, i) {
				el = $('<td></td>')
					.addClass(cell.css)
					.attr('colspan', cell.colspan)
					.attr('rowspan', cell.rowspan)
					.append(cell.elem)
					.appendTo(tr);
				numCells += cell.colspan || 1;
		});

		// append remaining cells
		for (var i = 0 ; i < numCols - numCells ; i++) {
			$('<td></td>').appendTo(tr);
		}
		
		tr.appendTo(table);
	});
	
	return table;
} //- TableLayout


ui.directive('uiTableLayout', ['$compile', function($compile) {

	return function(scope, element, attrs) {
		var items = attrs.layoutAfter ?
		               element.find(attrs.layoutAfter).nextAll() :
		               element.children();
		

		var layout = TableLayout(items, attrs, scope, $compile);
		var brTags = element.children('br:hidden'); // detach all the <br> tags

		scope.$on('$destroy', function(){
			brTags.remove();
		});

		element.append(layout);
	};

}]);

})(this);<commit_msg>Fixed layout issues (RM-1056).<commit_after>(function() {

var ui = angular.module('axelor.ui');

function TableLayout(items, attrs, $scope, $compile) {

	var colWidths = attrs.widths,
		numCols = +attrs.cols || 4,
		curCol = 0,
		layout = [[]];

	function add(item, label) {
		
		if (item.is('br')) {
			curCol = 0;
			item.hide();
			return layout.push([]);
		}

		var row = _.last(layout),
			cell = null,
			colspan = +item.attr('x-colspan') || 1,
			rowspan = +item.attr('x-rowspan') || 1;
		
		if (curCol + colspan + (label ? 1 : 0) >= numCols + 1) {
			curCol = 0, row = [];
			layout.push(row);
		}
		
		if (label) {
			cell = {};
			cell.elem = label;
			cell.css = label.attr('x-cell-css');
			row.push(cell);
			if (rowspan > 1) cell.rowspan = rowspan;
			if (colspan > 1) colspan -= 1;
			curCol += 1;
		}

		cell = {};
		cell.elem = item;
		cell.css = item.attr('x-cell-css');
		if (colspan > 1) cell.colspan = colspan;
		if (rowspan > 1) cell.rowspan = rowspan;
	
		row.push(cell);
		curCol += colspan;
	}

	// auto-generate colWidths
	if (numCols > 3 && !colWidths) {
		var labelCols = Math.floor(numCols / 2),
			itemCols = Math.ceil(numCols / 2),
			forLabels = 20 / labelCols,
			forItems = 80 / itemCols;

		colWidths = [];
		for(var i = 0 ; i < numCols ; i++) {
			colWidths[i] = (i % 2 == 1 || i >= (labelCols * 2) ? forItems : forLabels) + "%";
		}
	}

	if (colWidths && angular.isString(colWidths)) {
		colWidths = colWidths.trim().split(/\s*,\s*/);
		for(var i = 0 ; i < colWidths.length; i++) {
			var width = colWidths[i];
			if (/^(\d+)$/.test(width)) width = width + 'px';
			if (width == '*') width = 'auto';
			colWidths[i] = width;
		}
	}

	items.each(function(){
		var el = $(this),
			title = el.attr('x-title'),
			noTitle = el.attr('x-show-title') == 'false';

		if (numCols > 1 && !noTitle && title) {
			var label = $('<label ui-label></label>').html(title).attr('x-for-widget', el.attr('id')),
				labelElem = $compile(label)($scope);
			el.data('label', labelElem);
			return add(el, labelElem);
		}
		add(el);
	});
	
	var table = $('<table class="form-layout form-debug"></table');
	
	_.each(layout, function(row){
		var tr = $('<tr></tr>'),
			numCells = 0;
		_.each(row, function(cell, i) {
				el = $('<td></td>')
					.addClass(cell.css)
					.attr('colspan', cell.colspan)
					.attr('rowspan', cell.rowspan)
					.append(cell.elem)
					.appendTo(tr);
				if (_.isArray(colWidths) && colWidths[i]) {
					el.width(colWidths[i]);
				}
				numCells += cell.colspan || 1;
		});

		// append remaining cells
		for (var i = 0 ; i < numCols - numCells ; i++) {
			$('<td></td>').appendTo(tr);
		}
		
		tr.appendTo(table);
	});
	
	return table;
} //- TableLayout


ui.directive('uiTableLayout', ['$compile', function($compile) {

	return function(scope, element, attrs) {
		var items = attrs.layoutAfter ?
		               element.find(attrs.layoutAfter).nextAll() :
		               element.children();
		

		var layout = TableLayout(items, attrs, scope, $compile);
		var brTags = element.children('br:hidden'); // detach all the <br> tags

		scope.$on('$destroy', function(){
			brTags.remove();
		});

		element.append(layout);
	};

}]);

})(this);
{'fraction_non_alphanumeric': 0.20884406516679596, 'fraction_numerical': 0.009930178432893715, 'mean_word_length': 2.9185410334346504, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 43, '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': '3307371', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2420, 'n_words': 511}