<commit_before>/*
 * The input for coexpression searches. This form has two main parts: a
 * GeneChooserPanel, and the coexpression search parameters.
 * 
 * Coexpression search has three main settings, plus an optional part that
 * appears if the user is doing a 'custom' analysis: Stringency, "Among query
 * genes" checkbox, and the "scope".
 * 
 * If scope=custom, a DatasetSearchField is shown.
 * 
 * @authors <NAME>
 * 
 * @version $Id$
 */

Gemma.MIN_STRINGENCY = 2;

Gemma.CoexpressionSearchForm = Ext.extend(Ext.Panel, {

	layout : 'border',
	width : 550,
	height : 300,
	frame : true,
	stateful : true,
	stateEvents : ["beforesearch"],

	// share state with main page...
	stateId : "Gemma.CoexpressionSearch",

	defaults : {
		collapsible : true,
		// split : true,
		bodyStyle : "padding:10px"
	},

	applyState : function(state, config) {
		if (state) {
			this.csc = state;
		}
	},

	getState : function() {
		return this.getCoexpressionSearchCommand();
	},

	afterRender : function(container, position) {
		Gemma.CoexpressionSearchForm.superclass.afterRender.apply(this,
				arguments);

		Ext.apply(this, {
			loadMask : new Ext.LoadMask(this.getEl(), {
				msg : "Searching  ..."
			})
		});

	},

	restoreState : function() {
		// console.log("restoreState");
		var queryStart = document.URL.indexOf("?");
		if (queryStart > -1) {
			//Ext.log("Loading from url= " + document.URL);
			this.initializeFromQueryString(document.URL.substr(queryStart + 1));
		} else if (this.csc && queryStart < 0) {
			this.initializeFromCoexpressionSearchCommand(this.csc);
		}

	},

	/**
	 * Construct the coexpression command object from the form, to be sent to
	 * the server.
	 * 
	 * @return {}
	 */
	getCoexpressionSearchCommand : function() {
		var csc = {
			geneIds : this.geneChooserPanel.getGeneIds(),
			stringency : Ext.getCmp('stringencyfield').getValue(),
			taxonId : this.geneChooserPanel.getTaxonId(),
			queryGenesOnly : Ext.getCmp('querygenesonly').getValue()
		};

		if (this.currentSet) {
			csc.eeIds = this.getActiveEeIds();
			csc.eeSetName = this.currentSet.get("name");
			csc.eeSetId = this.currentSet.get("id"); // might be -1 (=
			// temporary)
			csc.dirty = this.currentSet.dirty; // modified without save
		}
		return csc;
	},

	/**
	 * Restore state from the URL (e.g., bookmarkable link)<commit_msg>avoid overwriting state from cookie<commit_after>/*
 * The input for coexpression searches. This form has two main parts: a
 * GeneChooserPanel, and the coexpression search parameters.
 * 
 * Coexpression search has three main settings, plus an optional part that
 * appears if the user is doing a 'custom' analysis: Stringency, "Among query
 * genes" checkbox, and the "scope".
 * 
 * If scope=custom, a DatasetSearchField is shown.
 * 
 * @authors <NAME>
 * 
 * @version $Id$
 */

Gemma.MIN_STRINGENCY = 2;

Gemma.CoexpressionSearchForm = Ext.extend(Ext.Panel, {

	layout : 'border',
	width : 550,
	height : 300,
	frame : true,
	stateful : true,
	stateEvents : ["beforesearch"],

	// share state with main page...
	stateId : "Gemma.CoexpressionSearch",

	defaults : {
		collapsible : true,
		// split : true,
		bodyStyle : "padding:10px"
	},

	applyState : function(state, config) {
		if (state) {
			this.csc = state;
		}
	},

	getState : function() {
		return this.getCoexpressionSearchCommand();
	},

	afterRender : function(container, position) {
		Gemma.CoexpressionSearchForm.superclass.afterRender.apply(this,
				arguments);

		Ext.apply(this, {
			loadMask : new Ext.LoadMask(this.getEl(), {
				msg : "Searching  ..."
			})
		});

	},

	restoreState : function() {
		// console.log("restoreState");
		var queryStart = document.URL.indexOf("?");
		if (queryStart > -1) {
			// Ext.log("Loading from url= " + document.URL);
			this.initializeFromQueryString(document.URL.substr(queryStart + 1));
		} else if (this.csc && queryStart < 0) {
			this.initializeFromCoexpressionSearchCommand(this.csc);
		}

	},

	/**
	 * Construct the coexpression command object from the form, to be sent to
	 * the server.
	 * 
	 * @return {}
	 */
	getCoexpressionSearchCommand : function() {
		var newCsc = {};
		if (this.csc) {
			newCsc = this.csc;
		}

		Ext.apply(newCsc, {
			geneIds : this.geneChooserPanel.getGeneIds(),
			stringency : Ext.getCmp('stringencyfield').getValue(),
			taxonId : this.geneChooserPanel.getTaxonId(),
			queryGenesOnly : Ext.getCmp('querygenesonly').getValue()
		});

		if (this.currentSet) {
			csc.eeIds = this.getActiveEeIds();
			csc.eeSetName = this.currentSet.get("name");
			csc.eeSetId = this.currentSet.get("id"); // might be -1 (=
			// temporary)
			csc.dirty = this.currentSet.dirty; // modified without save
		}
		return csc;
	},

	/**
	 * Restore state from the URL (e.g., bookmarkable link)
{'fraction_non_alphanumeric': 0.140848026868178, 'fraction_numerical': 0.0054575986565911, 'mean_word_length': 3.503780718336484, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1795826', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1562, 'n_words': 376}