<commit_before>## -*- coding: utf-8 -*-
<%!

from netprofile.tpl.filters import jsone

%>\
<%namespace name="np" file="netprofile_core:templates/np.mak" />\
Ext.Loader.setConfig({enabled: true});

Ext.Loader.setPath({
	'NetProfile'           : 'static/core/webshell',
% for module in modules:
	'NetProfile.${module}' : 'static/${module}/webshell',
% endfor
	'Ext.ux'               : 'static/core/webshell/ux'
});

Ext.require([
	'Ext.data.*',
	'Ext.direct.*',
	'Ext.form.field.Field',
	'Ext.tip.*',
	'Ext.state.*',
	'Ext.util.Cookies',
	'Ext.Ajax',
% for i_ajs in res_ajs:
	'${i_ajs}',
% endfor
	'NetProfile.model.Basic',
	'NetProfile.view.CapabilityGrid',
	'Ext.ux.form.MultiField',
	'NetProfile.view.Calendar'
], function()
{
	NetProfile.currentLocale = '${cur_loc}';
	NetProfile.currentUser = '${req.user.login}';
	NetProfile.currentUserId = ${req.user.id};
	NetProfile.currentSession = '${str(req.np_session)}';
	NetProfile.userSettings = ${req.user.client_settings(req) | n,jsone};
	NetProfile.rootFolder = ${req.user.get_root_folder() | n,jsone};
	NetProfile.baseURL = '${req.host_url}';
	NetProfile.staticURL = '${req.host_url}';
	//NetProfile.rtURL = '//${rt_host}:${rt_port}';
	NetProfile.rtURL = '//' + window.location.hostname + ':${rt_port}';
	NetProfile.rtSocket = null;
	NetProfile.rtActiveUIDs = null;
	NetProfile.rtMessageRenderers = {
		file: function(val, meta, rec)
		{
			var fname = Ext.String.htmlEncode(val.fname),
				surl = NetProfile.staticURL;

			return '<a class="np-file-wrap" href="#" onclick="Ext.getCmp(\'npws_filedl\').loadFileById(' + Ext.String.htmlEncode(val.id) + '); return false;"><img class="np-file-icon" src="' + surl + '/static/core/img/mime/16/' + Ext.String.htmlEncode(val.mime) + '.png" title="' + fname + '" onerror=\'this.onerror = null; this.src="' + surl + '/static/core/img/mime/16/default.png"\' /><span title="' + fname + '">' + fname + '</span></a>';
		}
	};
	Ext.direct.Manager.addProvider(NetProfile.api.Descriptor);
	Ext.Ajax.defaultHeaders = Ext.apply(Ext.Ajax.defaultHeaders || {}, {
		'X-CSRFToken': '${req.get_csrf()}'
	});
	NetProfile.msg = function()
	{
		var msgCt;

		function createBox(t, s, cls)
		{
			return '<div class="msg ' + cls + '"><h3>' + t + '</h3><p>' + s + '</p></div>';
		}

		function getMsg(cls, title, args)
		{
			if(!msgCt)
				msgCt = Ext.DomHelper.insertFirst(document.body, { id: 'msg-div' }, true);
			var s = Ext.String.format.apply(String, args);
			var m = Ext.DomHelper.append(msgCt, createBox(title, s, cls), true);
			m.hide();
			m.slideIn('t').ghost('t', { delay: 1250, remove: true });
		}

		return {
			notify: function(title, fmt)
			{
				return getMsg('', title, Array.prototype.slice.call(arguments, 1));
			},
			warn: function(title, fmt)
			{
				return getMsg('warning', title, Array.prototype.slice.call(arguments, 1));
			},
			err: function(title, fmt)
			{
				return getMsg('error', title, Array.prototype.slice.call(arguments, 1));
			},
			init: function()
			{
				if(!msgCt)
					msgCt = Ext.DomHelper.insertFirst(document.body, { id: 'msg-div' }, true);
			}
		};
	}();

	Ext.define('Ext.data.ConnectionNPOver', {
		override: 'Ext.data.Connection',
		setOptions: function(opt, scope)
		{
			res = this.callParent(arguments);
			if(opt.rawData && (typeof(FormData) !== 'undefined') && (opt.rawData instanceof FormData))
				res.data = opt.rawData;
			return res;
		},
		setupHeaders: function(xhr, opt, data, params)
		{
			if(opt.rawData && (typeof(FormData) !== 'undefined') && (opt.rawData instanceof FormData))
				return {};
			res = this.callParent(arguments);
			return res;
		}
	});
	Ext.define('Ext.form.field.BaseErrors', {
		override: 'Ext.form.field.Base',
		getErrors: function(value)
		{
			var errs, i;

			errs = this.callParent(arguments);
			if(this.asyncErrors && this.asyncErrors.length)
				for(i in this.asyncErrors)
				{
					Ext.Array.push(errs, this.asyncErrors[i]);
				}
			return errs;
		}
	});

	Ext.define('NetProfile.data.IPAddress', {
		MAX_IPV4: 0xffffffff,
		value: null,
		getValue: function()
		{
			return this.value;
		}
	});

	Ext.define('NetProfile.data.IPv4Address', {
		extend: 'NetProfile.data.IPAddress',
		constructor: function(val)
		{
			if((val !== undefined) && (val !== null))
				this.setValue(val);
		},
		setValue: function(val)
		{
			if(Ext.isNumeric(val))
				val = parseInt(val);
			else
				val = this.parseTextual(val);
			this.value = val;
			return this;
		},
		setOctets: function(oct)
		{
			oct = this.parseOctets(oct);
			this.value = oct;
			return this;
		},
		parseOctets: function(oct)
		{
			var ip, i, ioct;

			if(oct.length !== 4)
				throw 'Invalid IPv4 octets';
			ip = 0;
			for(i = 0; i < oct.length; i++)
			{
				ioct = parseInt(oct[i]);
				if(isNaN(ioct) || (ioct < 0) || (ioct > 255) ||
						((oct[i].length > 1) && (oct[i].slice(0, 1) == '0')))
					throw 'Invalid octet ' + (i + 1) + ' in IPv4 address';
				ip = (ip | ioct) >>> 0;
				if(i < 3)
					ip = (ip << 8) >>> 0;
			}
			return ip;
		},
		parseTextual: function(val)
		{
			if(!val.match(/^[0-9.]*$/))<commit_msg>Fixed a case of empty IPv4 address<commit_after>## -*- coding: utf-8 -*-
<%!

from netprofile.tpl.filters import jsone

%>\
<%namespace name="np" file="netprofile_core:templates/np.mak" />\
Ext.Loader.setConfig({enabled: true});

Ext.Loader.setPath({
	'NetProfile'           : 'static/core/webshell',
% for module in modules:
	'NetProfile.${module}' : 'static/${module}/webshell',
% endfor
	'Ext.ux'               : 'static/core/webshell/ux'
});

Ext.require([
	'Ext.data.*',
	'Ext.direct.*',
	'Ext.form.field.Field',
	'Ext.tip.*',
	'Ext.state.*',
	'Ext.util.Cookies',
	'Ext.Ajax',
% for i_ajs in res_ajs:
	'${i_ajs}',
% endfor
	'NetProfile.model.Basic',
	'NetProfile.view.CapabilityGrid',
	'Ext.ux.form.MultiField',
	'NetProfile.view.Calendar'
], function()
{
	NetProfile.currentLocale = '${cur_loc}';
	NetProfile.currentUser = '${req.user.login}';
	NetProfile.currentUserId = ${req.user.id};
	NetProfile.currentSession = '${str(req.np_session)}';
	NetProfile.userSettings = ${req.user.client_settings(req) | n,jsone};
	NetProfile.rootFolder = ${req.user.get_root_folder() | n,jsone};
	NetProfile.baseURL = '${req.host_url}';
	NetProfile.staticURL = '${req.host_url}';
	//NetProfile.rtURL = '//${rt_host}:${rt_port}';
	NetProfile.rtURL = '//' + window.location.hostname + ':${rt_port}';
	NetProfile.rtSocket = null;
	NetProfile.rtActiveUIDs = null;
	NetProfile.rtMessageRenderers = {
		file: function(val, meta, rec)
		{
			var fname = Ext.String.htmlEncode(val.fname),
				surl = NetProfile.staticURL;

			return '<a class="np-file-wrap" href="#" onclick="Ext.getCmp(\'npws_filedl\').loadFileById(' + Ext.String.htmlEncode(val.id) + '); return false;"><img class="np-file-icon" src="' + surl + '/static/core/img/mime/16/' + Ext.String.htmlEncode(val.mime) + '.png" title="' + fname + '" onerror=\'this.onerror = null; this.src="' + surl + '/static/core/img/mime/16/default.png"\' /><span title="' + fname + '">' + fname + '</span></a>';
		}
	};
	Ext.direct.Manager.addProvider(NetProfile.api.Descriptor);
	Ext.Ajax.defaultHeaders = Ext.apply(Ext.Ajax.defaultHeaders || {}, {
		'X-CSRFToken': '${req.get_csrf()}'
	});
	NetProfile.msg = function()
	{
		var msgCt;

		function createBox(t, s, cls)
		{
			return '<div class="msg ' + cls + '"><h3>' + t + '</h3><p>' + s + '</p></div>';
		}

		function getMsg(cls, title, args)
		{
			if(!msgCt)
				msgCt = Ext.DomHelper.insertFirst(document.body, { id: 'msg-div' }, true);
			var s = Ext.String.format.apply(String, args);
			var m = Ext.DomHelper.append(msgCt, createBox(title, s, cls), true);
			m.hide();
			m.slideIn('t').ghost('t', { delay: 1250, remove: true });
		}

		return {
			notify: function(title, fmt)
			{
				return getMsg('', title, Array.prototype.slice.call(arguments, 1));
			},
			warn: function(title, fmt)
			{
				return getMsg('warning', title, Array.prototype.slice.call(arguments, 1));
			},
			err: function(title, fmt)
			{
				return getMsg('error', title, Array.prototype.slice.call(arguments, 1));
			},
			init: function()
			{
				if(!msgCt)
					msgCt = Ext.DomHelper.insertFirst(document.body, { id: 'msg-div' }, true);
			}
		};
	}();

	Ext.define('Ext.data.ConnectionNPOver', {
		override: 'Ext.data.Connection',
		setOptions: function(opt, scope)
		{
			res = this.callParent(arguments);
			if(opt.rawData && (typeof(FormData) !== 'undefined') && (opt.rawData instanceof FormData))
				res.data = opt.rawData;
			return res;
		},
		setupHeaders: function(xhr, opt, data, params)
		{
			if(opt.rawData && (typeof(FormData) !== 'undefined') && (opt.rawData instanceof FormData))
				return {};
			res = this.callParent(arguments);
			return res;
		}
	});
	Ext.define('Ext.form.field.BaseErrors', {
		override: 'Ext.form.field.Base',
		getErrors: function(value)
		{
			var errs, i;

			errs = this.callParent(arguments);
			if(this.asyncErrors && this.asyncErrors.length)
				for(i in this.asyncErrors)
				{
					Ext.Array.push(errs, this.asyncErrors[i]);
				}
			return errs;
		}
	});

	Ext.define('NetProfile.data.IPAddress', {
		MAX_IPV4: 0xffffffff,
		value: null,
		getValue: function()
		{
			return this.value;
		}
	});

	Ext.define('NetProfile.data.IPv4Address', {
		extend: 'NetProfile.data.IPAddress',
		constructor: function(val)
		{
			if((val !== undefined) && (val !== null) && (val !== ''))
				this.setValue(val);
		},
		setValue: function(val)
		{
			if(Ext.isNumeric(val))
				val = parseInt(val);
			else
				val = this.parseTextual(val);
			this.value = val;
			return this;
		},
		setOctets: function(oct)
		{
			oct = this.parseOctets(oct);
			this.value = oct;
			return this;
		},
		parseOctets: function(oct)
		{
			var ip, i, ioct;

			if(oct.length !== 4)
			{
				throw 'Invalid IPv4 octets';
			}
			ip = 0;
			for(i = 0; i < oct.length; i++)
			{
				ioct = parseInt(oct[i]);
				if(isNaN(ioct) || (ioct < 0) || (ioct > 255) ||
						((oct[i].length > 1) && (oct[i].slice(0, 1) == '0')))
					throw 'Invalid octet ' + (i + 1) + ' in IPv4 address';
				ip = (ip | ioct) >>> 0;
				if(i < 3)
					ip = (ip << 8) >>> 0;
			}
			return ip;
		},
		parseTextual: function(val)
		{
			if(!val.match(/^[0-9.]*$/))
{'fraction_non_alphanumeric': 0.20125477894324087, 'fraction_numerical': 0.0073522203705519065, 'mean_word_length': 3.496253856324372, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6716094', 'n_tokens_mistral': 4383, 'n_tokens_neox': 3847, 'n_words': 674}