<commit_before>import Vue from 'vue'
import _ from 'underscore'
import {trim} from '../../js/functions/utils'
import server from '../../js/services/server'

Vue.directive('validate-path',
{
// -------------------------------------------------------------------------------------------------------------------
// lifecycle

	bind ()
	{
		this.$el = $(this.el);
		this.$icon = this.$el.parent().find('.validate-path');
		this.$el
			.attr('autocomplete', 'off')
			.on('focus', this.onFocus.bind(this))
			.on('input', _.debounce(this.onInput.bind(this), 400))
			.on('blur', this.onBlur.bind(this));
	},

	update (value)
	{

	},

	unbind ()
	{
		this.$el.off();
	},

// -------------------------------------------------------------------------------------------------------------------
// methods

	onFocus ()
	{
		this.$icon.show();
		this.check();
	},

	onInput ()
	{
		this.check();
	},

	onBlur ()
	{
		this.$icon.hide();
	},

	check ()
	{
		const $el = $(this.el);
		const path = trim($el.val());
		server
			.validatePath(path)
			.then(data => {
				if ($el.is(':focus'))
				{
					this.$icon
						.attr('title', data.exists ? 'Path exists' : 'Path does not exist')
						.addClass('fa')
						.toggleClass('fa-check', data.exists)
						.toggleClass('fa-exclamation-triangle', !data.exists);
				}
				if (data.exists)
				{
					if (this.vm.onPathExists)
					{
						this.vm.onPathExists(data, this);
					}
				}
			})
	},
});<commit_msg>Fixed bug with validate-path where a field focus would reload settings<commit_after>import Vue from 'vue'
import _ from 'underscore'
import {trim} from '../../js/functions/utils'
import server from '../../js/services/server'

Vue.directive('validate-path',
{
// -------------------------------------------------------------------------------------------------------------------
// lifecycle

	bind ()
	{
		this.$el = $(this.el);
		this.$icon = this.$el.parent().find('.validate-path');
		this.$el
			.attr('autocomplete', 'off')
			.on('focus', this.onFocus.bind(this))
			.on('input', _.debounce(this.onInput.bind(this), 400))
			.on('blur', this.onBlur.bind(this));
	},

	update (value)
	{

	},

	unbind ()
	{
		this.$el.off();
	},

// -------------------------------------------------------------------------------------------------------------------
// methods

	onFocus ()
	{
		this.$icon.show();
		this.check();
	},

	onInput ()
	{
		this.check(true);
	},

	onBlur ()
	{
		this.$icon.hide();
	},

	check (update)
	{
		const $el = $(this.el);
		const path = trim($el.val());
		server
			.validatePath(path)
			.then(data => {
				if ($el.is(':focus'))
				{
					this.$icon
						.attr('title', data.exists ? 'Path exists' : 'Path does not exist')
						.addClass('fa')
						.toggleClass('fa-check', data.exists)
						.toggleClass('fa-exclamation-triangle', !data.exists);
				}
				if (data.exists && update)
				{
					if (this.vm.onPathExists)
					{
						this.vm.onPathExists(data, this);
					}
				}
			})
	},
});
{'fraction_non_alphanumeric': 0.33624454148471616, 'fraction_numerical': 0.002015451797111186, 'mean_word_length': 1.5716753022452505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1684479', 'n_tokens_mistral': 1148, 'n_tokens_neox': 948, 'n_words': 164}