<commit_before>Ui.LBox.extend('Form.Field',
/**@lends Form.Field#*/
{
	label: undefined,
	labelBox: undefined,
	require: false,
	description: undefined,
	validation: undefined,
	defaultValue: undefined,
	/**Object will have to prepend Ui.Element here*/
	fieldBox: undefined,
	/**contains labelBox + fieldBox*/
	contentBox: undefined,
	labelAlign: undefined,
	error: undefined,
	background: undefined,
	uiElt: undefined,
	/**Type of the Ui.Element, will be used in setUiElement as default type
	for the create (if left undefined will be Ui.Element)*/
	uiEltType: Ui.Element,
	
	constructor: function(config){
		this.addEvents("change");
		//Default field width
		this.setWidth(200);
		//By default use the styleProperty
		this.labelAlign = this.getStyleProperty('labelAlign');
		//If label are align on top of the field, then use a VBox, otherwise HBox an
		var boxType = this.labelAlign ==='top' ? Ui.VBox : Ui.HBox;
		var lblHorizontalAlign = this.labelAlign ==='right' ? 'right' : 'left';

		this.setMargin(2);
		this.setContent([
			{type: Ui.Rectangle, name: 'background', opacity: 0.0, fill: 'pink', radius: 8},
			{
				type: boxType, margin: 5, name: 'contentBox',
				content: [
					{
						//Handle label with multiple colors...
						type: Ui.HBox, name: 'labelBox', spacing: 2,
						horizontalAlign: lblHorizontalAlign, verticalAlign: 'top',
						content: [{type: Ui.Label, name: 'label'}]
					},
					{
						type: Ui.VBox, name: 'fieldBox',
						content: [
							{type: Ui.Text, name: 'description', textAlign: 'left', color: '#444444'},
							{type: Ui.Text, name: 'error', color: 'red', textAlign: 'left', fontWeight: 'bold'}
						]
					}
				]
			}
		]);
	},

	/**
	 * Change label alignement
	 * @param top|left|right
	 */
	setLabelAlign: function(align){
		if(this.labelAlign !== align){
			this.labelAlign = align;

			this.contentBox.clear();
			this.remove(this.contentBox);

			var boxType = this.labelAlign ==='top' ? Ui.VBox : Ui.HBox;
			var lblHorizontalAlign = this.labelAlign ==='right' ? 'right' : 'left';
			this.contentBox = new boxType({content: [this.labelBox, this.fieldBox]});
			this.labelBox.setHorizontalAlign(lblHorizontalAlign);

			this.append(this.contentBox);
		}
	},

	/**
	 * Define the type of the Ui.Element in the Form.Field
	 * and create an element with a blank config which can be override with the uiElement config param
	 */
	setUiElementType: function(type) {
		this.uiEltType = type;
		this.setUiElement({});
	},

	setLabel: function(label){
		this.label.setText(label);
	},
	
	setRequire: function(require){
		this.require = require;
		if(this.require){
			this.labelBox.append(new Ui.Label({text: '*', color: 'red', fontWeight: 'bold'}));
		}
		else if(this.labelBox.getChildren().length > 1){
			this.labelBox.remove(this.labelBox.getLastChild());
		}
	},
	
	isRequire: function(){
		return this.require;
	},
	
	setDescription: function(description){
		this.description.setText(description);
	},
	
	setValidation: function(validation){
		this.validation = validation;
	},
	
	getValidation: function(){
		return this.validation;
	},
	
	setDefaultValue: function(defaultValue){
		this.defaultValue = defaultValue;
		this.setValue(this.defaultValue);
	},
	
	getError: function(){
		return this.error.getText();
	},
	
	setError: function(error){
		if(error !== ''){
			this.background.setOpacity(1.0);
		}
		else{
			this.background.setOpacity(0.0);
		}
		this.error.setText(error);
	},
	
	validate: function(){
		this.setError('');
	},
	
	setRequireError: function(){
		this.setError('Champs obligatoire');
	},
	
	getValue: function(){
		return this.uiElt !== undefined ? this.uiElt.getValue() : undefined;
	},
	
	setValue: function(value){
		if(this.uiElt !== undefined){
			this.uiElt.setValue(value);
		}
	},
	
	setUiElement: function(elt){
		if(this.uiElt !== undefined){
			this.fieldBox.remove(this.uiElt);
		}
		this.uiElt = this.uiEltType.create(elt);
		this.fieldBox.prepend(this.uiElt);
	},
	
	reset: function(){
		if(this.defaultValue !== undefined){
			this.setValue(this.defaultValue);
		}
	},
	
	/**Need to be override*/
	isValid: function(){
		return true;
	},

	onChange: function(){
		this.fireEvent("change", this);
	}
},{},
{
	style: {
		/**can be left, right, top*/
		labelAlign: 'top'
	}
});

Form.Field.extend('Form.ComboField',
/**@lends Form.ComboField#*/
{
	constructor: function(config){
		this.setUiElementType(Ui.Combo);
		if(!('uiElement' in config)){
			this.setUiElement({horizontalAlign: 'left'});
		}
	}
},
/**@lends Form.ComboField#*/
{
	/**Get the current selection*/
	getValue: function(){
		return this.uiElt.getCurrent();
	},
	
	/**Set the Combo data*/
	setValue: function(value){
		this.uiElt.setData(value);
	},
	
	/**Override it cause Ui.Combo need to be left align*/
	setUiElement: function(elt){<commit_msg>Add change event on Form.ComboField<commit_after>Ui.LBox.extend('Form.Field',
/**@lends Form.Field#*/
{
	label: undefined,
	labelBox: undefined,
	requireStar: undefined,
	require: false,
	description: undefined,
	validation: undefined,
	defaultValue: undefined,
	/**Object will have to prepend Ui.Element here*/
	fieldBox: undefined,
	/**contains labelBox + fieldBox*/
	contentBox: undefined,
	labelAlign: undefined,
	error: undefined,
	background: undefined,
	uiElt: undefined,
	/**Type of the Ui.Element, will be used in setUiElement as default type
	for the create (if left undefined will be Ui.Element)*/
	uiEltType: Ui.Element,
	
	constructor: function(config){
		this.addEvents("change");
		//Default field width
		this.setWidth(200);
		//By default use the styleProperty
		this.labelAlign = this.getStyleProperty('labelAlign');
		//If label are align on top of the field, then use a VBox, otherwise HBox an
		var boxType = this.labelAlign ==='top' ? Ui.VBox : Ui.HBox;
		var lblHorizontalAlign = this.labelAlign ==='right' ? 'right' : 'left';

		this.setMargin(2);
		this.setContent([
			{type: Ui.Rectangle, name: 'background', opacity: 0.0, fill: 'pink', radius: 8},
			{
				type: boxType, margin: 5, name: 'contentBox',
				content: [
					{
						//Handle label with multiple colors...
						type: Ui.HBox, name: 'labelBox', spacing: 2,
						horizontalAlign: lblHorizontalAlign, verticalAlign: 'top',
						content: [{type: Ui.Label, name: 'label'}]
					},
					{
						type: Ui.VBox, name: 'fieldBox',
						content: [
							{type: Ui.Text, name: 'description', textAlign: 'left', color: '#444444'},
							{type: Ui.Text, name: 'error', color: 'red', textAlign: 'left', fontWeight: 'bold'}
						]
					}
				]
			}
		]);
	},

	/**
	 * Change label alignement
	 * @param top|left|right
	 */
	setLabelAlign: function(align){
		if(this.labelAlign !== align){
			this.labelAlign = align;

			this.contentBox.clear();
			this.remove(this.contentBox);

			var boxType = this.labelAlign ==='top' ? Ui.VBox : Ui.HBox;
			var lblHorizontalAlign = this.labelAlign ==='right' ? 'right' : 'left';
			this.contentBox = new boxType({content: [this.labelBox, this.fieldBox]});
			this.labelBox.setHorizontalAlign(lblHorizontalAlign);

			this.append(this.contentBox);
		}
	},

	/**
	 * Define the type of the Ui.Element in the Form.Field
	 * and create an element with a blank config which can be override with the uiElement config param
	 */
	setUiElementType: function(type) {
		this.uiEltType = type;
		this.setUiElement({});
	},

	setLabel: function(label){
		this.label.setText(label);
	},
	
	setRequire: function(require){
		this.require = require;
		if(this.require){
			this.requireStar = new Ui.Label({text: '*', color: 'red', fontWeight: 'bold'});
			this.labelBox.append(this.requireStar);
		}
		else if(this.requireStar != null && this.labelBox.hasChild(this.requireStar)){
			this.labelBox.remove(this.requireStar);
		}
	},
	
	isRequire: function(){
		return this.require;
	},
	
	setDescription: function(description){
		this.description.setText(description);
	},
	
	setValidation: function(validation){
		this.validation = validation;
	},
	
	getValidation: function(){
		return this.validation;
	},
	
	setDefaultValue: function(defaultValue){
		this.defaultValue = defaultValue;
		this.setValue(this.defaultValue);
	},
	
	getError: function(){
		return this.error.getText();
	},
	
	setError: function(error){
		if(error !== ''){
			this.background.setOpacity(1.0);
		}
		else{
			this.background.setOpacity(0.0);
		}
		this.error.setText(error);
	},
	
	validate: function(){
		this.setError('');
	},
	
	setRequireError: function(){
		this.setError('Champs obligatoire');
	},
	
	getValue: function(){
		return this.uiElt !== undefined ? this.uiElt.getValue() : undefined;
	},
	
	setValue: function(value){
		if(this.uiElt !== undefined){
			this.uiElt.setValue(value);
		}
	},
	
	setUiElement: function(elt){
		if(this.uiElt !== undefined){
			this.fieldBox.remove(this.uiElt);
		}
		this.uiElt = this.uiEltType.create(elt);
		this.fieldBox.prepend(this.uiElt);
	},
	
	reset: function(){
		if(this.defaultValue !== undefined){
			this.setValue(this.defaultValue);
		}
	},
	
	/**Need to be override*/
	isValid: function(){
		return true;
	},

	onChange: function(){
		this.fireEvent("change", this);
	}
},{},
{
	style: {
		/**can be left, right, top*/
		labelAlign: 'top'
	}
});

Form.Field.extend('Form.ComboField',
/**@lends Form.ComboField#*/
{
	constructor: function(config){
		this.setUiElementType(Ui.Combo);
		if(!('uiElement' in config)){
			this.setUiElement({horizontalAlign: 'left'});
		}

		this.connect(this.uiElt, 'change', this.onChange);
	}
},
/**@lends Form.ComboField#*/
{
	/**Get the current selection*/
	getValue: function(){
		return this.uiElt.getCurrent();
	},
	
	/**Set the Combo data*/
	setValue: function(value){
		this.uiElt.setData(value);
	},
	
	/**Override it cause Ui.Combo need to be left align*/
	setUiElement: function(elt){
{'fraction_non_alphanumeric': 0.16062123224685806, 'fraction_numerical': 0.0039848778992541125, 'mean_word_length': 3.8793619142572284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3258600', 'n_tokens_mistral': 3732, 'n_tokens_neox': 3306, 'n_words': 745}