<commit_before>Ext.namespace("Gemma");

/**
 * Remote-mode combo-box that queries for characteristics with type-ahead.
 * 
 * @class Gemma.CharacteristicCombo
 * @extends Ext.form.ComboBox
 * @version $Id$
 */
Gemma.CharacteristicCombo = Ext.extend(Ext.form.ComboBox, {

	loadingText : "Searching...",
	minChars : 2,
	selectOnFocus : true,
	listWidth : 350,
	taxonId : null, // set on initialization
	name : 'characteristicCombo',
	lazyInit : false,

	/**
	 * @Override
	 */
	initComponent : function() {

		Ext.apply(this, {

					record : Ext.data.Record.create([{
								name : "id",
								type : "int"
							}, {
								name : "value",
								type : "string"
							}, {
								name : "valueUri",
								type : "string"
							}, {
								name : "categoryUri",
								type : "string"
							}, {
								name : "category",
								type : "string"
							}, {
								name : "description",
								mapping : "this",
								convert : this.getHover.createDelegate(this)
							}, {
								name : "style",
								mapping : "this",
								convert : this.getStyle.createDelegate(this)
							}])
				});

		Ext.apply(this, {
					store : new Ext.data.Store({
								proxy : new Ext.data.DWRProxy({
											apiActionToHandlerMap : {
												read : {
													dwrFunction : AnnotationController.findTerm,
													getDwrArgsFunction : function(request) {
														// This is only used when directly calling 'load', which is not
														// usual but can be used for tests.
														return [request.params[0], this.characteristic.categoryUri,
																this.taxonId];
													}.createDelegate(this)
												}
											}
										}),
								reader : new Ext.data.ListRangeReader({
											id : "id"
										}, this.record),
								remoteSort : true
							})
				});

		Gemma.CharacteristicCombo.superclass.initComponent.call(this);

		this.tpl = new Ext.XTemplate('<tpl for="."><div ext:qtip="{description}"  style="font-size:11px" class="x-combo-list-item {style}">{value}</div></tpl>');
		this.tpl.compile();

		this.characteristic = {
			category : null,
			categoryUri : null,
			value : null,
			valueUri : null
		};

		this.on("select", function(combo, record, index) {
					this.characteristic.value = record.data.value;
					this.characteristic.valueUri = record.data.valueUri;
					/*
					 * The addition of '\t' is a complete hack to workaround an extjs limitation. It's to make sure
					 * extjs knows we want it to detect a change. See bug 1811
					 */
					combo.setValue(record.data.value + "\t");
				});

	},

	/**
	 * This is used when doing live-search - called by 'doQuery'.
	 * 
	 * @Override so we can have more than one parameter passed.
	 */
	getParams : function(query) {
		return [query, this.characteristic.categoryUri, this.taxonId];
	},

	/**
	 * 
	 * @return {}
	 */
	getCharacteristic : function() {

		/*
		 * check to see if the user has typed anything in the combo box (rather than selecting something); if they have,
		 * remove the URI from the characteristic and update its value, so we end up with a plain text. See note about
		 * hack '\t' above.
		 */
		if (this.getValue() != this.characteristic.value + "\t") {
			this.characteristic.value = this.getValue();
			this.characteristic.valueUri = null;
		}
		/*
		 * if we don't have a valueUri or categoryUri set, don't return URI fields or a VocabCharacteristic will be
		 * created when we only want a Characteristic...
		 */
		return (this.characteristic.valueUri !== null || this.characteristic.categoryUri !== null)
				? this.characteristic
				: {
					category : this.characteristic.category,
					value : this.characteristic.value
				};
	},

	/**
	 * 
	 * @param {}
	 *            value
	 * @param {}
	 *            valueUri
	 * @param {}
	 *            category
	 * @param {}
	 *            categoryUri
	 */
	setCharacteristic : function(value, valueUri, category, categoryUri) {
		this.characteristic.value = value;
		this.characteristic.valueUri = valueUri;
		this.characteristic.category = category;
		this.characteristic.categoryUri = categoryUri;
		this.setValue(value);
	},

	/**
	 * 
	 * @param {}
	 *            category
	 * @param {}
	 *            categoryUri
	 */
	setCategory : function(category, categoryUri) {
		this.characteristic.category = category;
		this.characteristic.categoryUri = categoryUri;
	},

	/*
	 * if the characteristic has a URI, use that as the description; if not, strip the " -USED- " string (added
	 * server-side)F if present.
	 */
	getHover : function(value, record) {
		if (record.valueUri) {
			return record.valueUri;
		} else {
			return (record.description.substring(0, 8) == " -USED- ")
					? record.description.substring(8)
					: record.description;
		}
	},
	getStyle : function(value, record) {
		if (record.description && record.description.substring(0, 8) == " -USED- ") {
			return record.valueUri ? "usedWithUri" : "usedNoUri";
		} else {
			return record.valueUri ? "unusedWithUri" : "unusedNoUri";
		}
	}<commit_msg>bug 2783: missed JS change to reflect value object use in back end<commit_after>Ext.namespace("Gemma");

/**
 * Remote-mode combo-box that queries for characteristics with type-ahead.
 * 
 * @class Gemma.CharacteristicCombo
 * @extends Ext.form.ComboBox
 * @version $Id$
 */
Gemma.CharacteristicCombo = Ext.extend(Ext.form.ComboBox, {

	loadingText : "Searching...",
	minChars : 2,
	selectOnFocus : true,
	listWidth : 350,
	taxonId : null, // set on initialization
	name : 'characteristicCombo',
	lazyInit : false,

	/**
	 * @Override
	 */
	initComponent : function() {

		Ext.apply(this, {

					record : Ext.data.Record.create([{
								name : "id",
								type : "int"
							}, {
								name : "value",
								type : "string"
							}, {
								name : "valueUri",
								type : "string"
							}, {
								name : "categoryUri",
								type : "string"
							}, {
								name : "category",
								type : "string"
							}, {
								name : "description",
								mapping : "this",
								convert : this.getHover.createDelegate(this)
							}, {
								name : "style",
								mapping : "this",
								convert : this.getStyle.createDelegate(this)
							}])
				});

		Ext.apply(this, {
					store : new Ext.data.Store({
								proxy : new Ext.data.DWRProxy({
											apiActionToHandlerMap : {
												read : {
													dwrFunction : AnnotationController.findTerm,
													getDwrArgsFunction : function(request) {
														// This is only used when directly calling 'load', which is not
														// usual but can be used for tests.
														return [request.params[0], this.characteristic.categoryUri,
																this.taxonId];
													}.createDelegate(this)
												}
											}
										}),
								reader : new Ext.data.ListRangeReader({
											id : "id"
										}, this.record),
								remoteSort : true
							})
				});

		Gemma.CharacteristicCombo.superclass.initComponent.call(this);

		this.tpl = new Ext.XTemplate('<tpl for="."><div ext:qtip="{description}"  style="font-size:11px" class="x-combo-list-item {style}">{value}</div></tpl>');
		this.tpl.compile();

		this.characteristic = {
			category : null,
			categoryUri : null,
			value : null,
			valueUri : null
		};

		this.on("select", function(combo, record, index) {
					this.characteristic.value = record.data.value;
					this.characteristic.valueUri = record.data.valueUri;
					/*
					 * The addition of '\t' is a complete hack to workaround an extjs limitation. It's to make sure
					 * extjs knows we want it to detect a change. See bug 1811
					 */
					combo.setValue(record.data.value + "\t");
				});

	},

	/**
	 * This is used when doing live-search - called by 'doQuery'.
	 * 
	 * @Override so we can have more than one parameter passed.
	 */
	getParams : function(query) {
		return [query, this.characteristic.categoryUri, this.taxonId];
	},

	/**
	 * 
	 * @return {}
	 */
	getCharacteristic : function() {

		/*
		 * check to see if the user has typed anything in the combo box (rather than selecting something); if they have,
		 * remove the URI from the characteristic and update its value, so we end up with a plain text. See note about
		 * hack '\t' above.
		 */
		if (this.getValue() != this.characteristic.value + "\t") {
			this.characteristic.value = this.getValue();
			this.characteristic.valueUri = null;
		}
		/*
		 * if we don't have a valueUri or categoryUri set, don't return URI fields or a VocabCharacteristic will be
		 * created when we only want a Characteristic...
		 */
		return (this.characteristic.valueUri !== null || this.characteristic.categoryUri !== null)
				? this.characteristic
				: {
					category : this.characteristic.category,
					value : this.characteristic.value
				};
	},

	/**
	 * 
	 * @param {}
	 *            value
	 * @param {}
	 *            valueUri
	 * @param {}
	 *            category
	 * @param {}
	 *            categoryUri
	 */
	setCharacteristic : function(value, valueUri, category, categoryUri) {
		this.characteristic.value = value;
		this.characteristic.valueUri = valueUri;
		this.characteristic.category = category;
		this.characteristic.categoryUri = categoryUri;
		this.setValue(value);
	},

	/**
	 * 
	 * @param {}
	 *            category
	 * @param {}
	 *            categoryUri
	 */
	setCategory : function(category, categoryUri) {
		this.characteristic.category = category;
		this.characteristic.categoryUri = categoryUri;
	},

	getHover : function(value, record) {
		return (record.valueUri)? record.valueUri: 
				(record.category)? record.category:
				  '';
	},
	getStyle : function(value, record) {
		if (record.alreadyPresentInDatabase) {
			return record.valueUri ? "usedWithUri" : "usedNoUri";
		} else {
			return record.valueUri ? "unusedWithUri" : "unusedNoUri";
		}
	}
{'fraction_non_alphanumeric': 0.1308411214953271, 'fraction_numerical': 0.0031491263713937425, 'mean_word_length': 2.3715753424657535, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1794538', 'n_tokens_mistral': 3960, 'n_tokens_neox': 2929, 'n_words': 730}