<commit_before>/**
 *
 * iTop Search form history handler
 *
 * the widget exposes
 *
 * $(cssSelector).search_form_handler_history({"itop_root_class":"FooBarClass"}) : constructor
 * $(cssSelector).search_form_handler_history("getHistory") : history array getter
 * $(cssSelector).search_form_handler_history("historyUnshift", "field.ref") : prepend the field ref to the beginning of the history array
 *
 *
 * please take a look at the options for custom constructor values
 *
 *
 * The persistence layer rely on these two core iTop's JS functions :
 *  - GetUserPreference(sPreferenceCode, sDefaultValue)
 *  - SetUserPreference(sPreferenceCode, sPrefValue, bPersistent)
 *
 */
;
$(function()
{
	// the widget definition, where 'itop' is the namespace,
	// 'search_form_handler_history' the widget name
	$.widget( 'itop.search_form_handler_history',
	{
		// default options
		options:
		{
			"itop_root_class": null,
			"preference_code": undefined, 			// if undefined, it is computed on _create
			"history_max_length": 10,				// if the history is longer, the older entries are removed
			"history_backend_store_timeout": 5000,	// wait for this time before storing the new history in the backend
		},

		aHistory : [],
		
		iStoreHistoryTimeoutHandler : undefined,

		getHistory: function()
		{
			return me.aHistory;
		},

		historyUnshift: function(sFieldRef)
		{
			var me = this;

			var iIndexInHistory = me.aHistory.indexOf(sFieldRef);

			//if present, delete
			if (iIndexInHistory > -1)
			{
				me.aHistory.splice(iIndexInHistory, 1);
			}

			//add to the begining
			me.aHistory.unshift(sFieldRef);

			//restrain the length to me.options.history_max_length
			var iDeleteCount = me.aHistory.length - me.options.history_max_length;
			if (iDeleteCount > 0)
			{
				me.aHistory.splice(0, iDeleteCount);
			}

			me._storeHistory();

			//setter should never return a value!
			return;
		},

		/**
		 * the constructor, called by the widget factory
		 * @private
		 */
		_create: function()
		{
			var me = this;<commit_msg>search widget : widget search history draft<commit_after>/**
 *
 * iTop Search form history handler
 *
 * the widget exposes
 *
 * $(cssSelector).search_form_handler_history({"itop_root_class":"FooBarClass"}) : constructor
 * $(cssSelector).search_form_handler_history("getHistory") : history array getter
 * $(cssSelector).search_form_handler_history("historyUnshift", "field.ref") : prepend the field ref to the beginning of the history array
 *
 *
 * please take a look at the options for custom constructor values
 *
 *
 * The persistence layer rely on these two core iTop's JS functions :
 *  - GetUserPreference(sPreferenceCode, sDefaultValue)
 *  - SetUserPreference(sPreferenceCode, sPrefValue, bPersistent)
 *
 */
;
$(function()
{
	// the widget definition, where 'itop' is the namespace,
	// 'search_form_handler_history' the widget name
	$.widget( 'itop.search_form_handler_history',
	{
		// default options
		options:
		{
			"itop_root_class": null,
			"preference_code": undefined, 			// if undefined, it is computed on _create
			"history_max_length": 10,				// if the history is longer, the older entries are removed
			"history_backend_store_timeout": 5000,	// wait for this time before storing the new history in the backend
		},

		aHistory : [],
		
		iStoreHistoryTimeoutHandler : undefined,

		getHistory: function()
		{
			return me.aHistory;
		},

		historyUnshift: function(sFieldRef)
		{
			var me = this;

			//if present, delete
			var iIndexInHistory = me.aHistory.indexOf(sFieldRef);
			if (iIndexInHistory > -1)
			{
				me.aHistory.splice(iIndexInHistory, 1);
			}

			//add to the begining
			me.aHistory.unshift(sFieldRef);

			//restrain the length to me.options.history_max_length
			var iDeleteCount = me.aHistory.length - me.options.history_max_length;
			if (iDeleteCount > 0)
			{
				me.aHistory.splice(0, iDeleteCount);
			}

			//store it in the backend (with a delay in the hope to wait long enough to make bulk modifications
			me._storeHistory();

			//setter should never return a value!
			return;
		},

		/**
		 * the constructor, called by the widget factory
		 * @private
		 */
		_create: function()
		{
			var me = this;
{'fraction_non_alphanumeric': 0.10596341173675457, 'fraction_numerical': 0.004751722499406035, 'mean_word_length': 3.6674057649667406, 'pattern_counts': {'":': 10, '<': 3, '<?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': '4028787', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1292, 'n_words': 369}