<commit_before>/*
* @license Proprietary
* @copyright Copyright (c) 2015 borkedLabs - All Rights Reserved
*/

siggy2.Activity = siggy2.Activity || {};


siggy2.Activity.Notifications = function(core)
{
	var $this = this;

	this.key = 'notifications';
	this._updateTimeout = null;
	this._updateTimeoutNotifiers = null;
	this.core = core;
	this.updateRate = 60000;


	this.notifierFormState = 'none';
	this.notifierID = 0;
	this.notifierType = '';
	this.notificationHistoryPage = 1;


	this.historyTable = $('#notifications-history-table tbody');
	this.notifierTable = $('#notifications-notifier-table tbody');

	$('.notifications-history-pagination').pagination({
		pages: 2,
		cssStyle: 'dark-theme',
		onPageClick: function(pageNumber, event)
		{
			$this.notificationHistoryPage = pageNumber;
			$this.update();
		}
	});


	this.templateHistoryRow = Handlebars.compile( $("#template-notification-history-table-row").html() );
	this.templateNotifierRow = Handlebars.compile( $("#template-notification-notifier-table-row").html() )
	this.notifierFormSystemMapped = Handlebars.compile( $("#template-notification-mapped-system").html() );
	this.notifierFormResidentFound = Handlebars.compile( $("#template-notification-system-resident-found").html() );
	this.notifierFormSiteFound = Handlebars.compile( $("#template-notification-site-found").html() );

	var typeOptions = [
		{
			selector: '#notifier_add_system_mapped',
			key: 'system_mapped'
		},
		{
			selector: '#notifier_add_system_resident_found',
			key: 'system_resident_found'
		},
		{
			selector: '#notifier_add_site_found',
			key: 'site_found'
		}
	]

	for(var i in typeOptions)
	{
		(function(t){
			$(t.selector).click( function()
			{
				$this.notifierFormState = 'add';
				$this.openNotifierForm(t.key);
			} );
		})(typeOptions[i]);
	}


	$('#notifier-form form').on('submit', function(e)
	{
		e.preventDefault();
		$this.notifierSubmit();
	});


	$('#notifications-notifier-table').on('click','.notifier-delete', function(e) {
		//$(this).data('id')
		$this.notifierDelete($(this).data('id'));
	});
}

siggy2.Activity.Notifications.prototype.start = function()
{
	$('#activity-' + this.key).show();
	this.update();
	this.updateNotifiers();
}

siggy2.Activity.Notifications.prototype.stop = function()
{
	clearTimeout(this._updateTimeout);
	clearTimeout(this._updateTimeoutNotifiers);
	$('#activity-' + this.key).hide();
}

siggy2.Activity.Notifications.prototype.notifierSubmit = function()
{
	var $this = this;
	var data = $('#notifier-form form').serializeObject();

	var url = '';
	if( this.notifierFormState == 'add' )
	{
		url = this.core.settings.baseUrl + 'notifications/notifiers_add';
	}
	else if( this.notifierFormState == 'edit' )
	{
		url = this.core.settings.baseUrl + 'notifications/notifiers_edit';

		data.id = 0;
	}
	else
	{
		return;
	}

	$.post(url, data,
	function (ret)
	{
		$this.updateNotifiers();
		$.unblockUI();
	});
}

siggy2.Activity.Notifications.prototype.notifierDelete = function(id)
{
	var $this = this;
	var data = {
		id: id
	}

	$.post(this.core.settings.baseUrl + 'notifications/notifiers_delete', data,
	function (ret)
	{
		$this.updateNotifiers();
	});
}

siggy2.Activity.Notifications.prototype.getNotifierTitle = function(notifier)
{
	switch( notifier )
	{
		case 'system_mapped':
			return 'System Mapped';
		case 'system_resident_found':
			return 'Resident Found';
		case 'site_found':
			return 'Site found';
	}
}

siggy2.Activity.Notifications.prototype.getNotifierTemplate = function(notifier)
{
	switch( notifier )
	{
		case 'system_mapped':
			return this.notifierFormSystemMapped;
		case 'system_resident_found':
			return this.notifierFormResidentFound;
		case 'site_found':
			return this.notifierFormSiteFound;
	}
}


siggy2.Activity.Notifications.prototype.openNotifierForm = function(notifier)
{
	$('.notifier-system-typeahead').typeahead('destroy');
	$('#notifier-form div.form-content').empty();

	var $this = this;
	var data = {
		errors: {},
		scopes: [
			{
				value: 'personal',
				text: 'Personal'
			},
			{
				value: 'group',
				text: 'Group'
			}
		],
		notifier: {
			type: notifier,
			num_jumps: '0'
		}
	};

	if( notifier == 'site_found' )<commit_msg>Fix defaults for system and resident notifiers<commit_after>/*
* @license Proprietary
* @copyright Copyright (c) 2015 borkedLabs - All Rights Reserved
*/

siggy2.Activity = siggy2.Activity || {};


siggy2.Activity.Notifications = function(core)
{
	var $this = this;

	this.key = 'notifications';
	this._updateTimeout = null;
	this._updateTimeoutNotifiers = null;
	this.core = core;
	this.updateRate = 60000;


	this.notifierFormState = 'none';
	this.notifierID = 0;
	this.notifierType = '';
	this.notificationHistoryPage = 1;


	this.historyTable = $('#notifications-history-table tbody');
	this.notifierTable = $('#notifications-notifier-table tbody');

	$('.notifications-history-pagination').pagination({
		pages: 2,
		cssStyle: 'dark-theme',
		onPageClick: function(pageNumber, event)
		{
			$this.notificationHistoryPage = pageNumber;
			$this.update();
		}
	});


	this.templateHistoryRow = Handlebars.compile( $("#template-notification-history-table-row").html() );
	this.templateNotifierRow = Handlebars.compile( $("#template-notification-notifier-table-row").html() )
	this.notifierFormSystemMapped = Handlebars.compile( $("#template-notification-mapped-system").html() );
	this.notifierFormResidentFound = Handlebars.compile( $("#template-notification-system-resident-found").html() );
	this.notifierFormSiteFound = Handlebars.compile( $("#template-notification-site-found").html() );

	var typeOptions = [
		{
			selector: '#notifier_add_system_mapped',
			key: 'system_mapped'
		},
		{
			selector: '#notifier_add_system_resident_found',
			key: 'system_resident_found'
		},
		{
			selector: '#notifier_add_site_found',
			key: 'site_found'
		}
	]

	for(var i in typeOptions)
	{
		(function(t){
			$(t.selector).click( function()
			{
				$this.notifierFormState = 'add';
				$this.openNotifierForm(t.key);
			} );
		})(typeOptions[i]);
	}


	$('#notifier-form form').on('submit', function(e)
	{
		e.preventDefault();
		$this.notifierSubmit();
	});


	$('#notifications-notifier-table').on('click','.notifier-delete', function(e) {
		//$(this).data('id')
		$this.notifierDelete($(this).data('id'));
	});
}

siggy2.Activity.Notifications.prototype.start = function()
{
	$('#activity-' + this.key).show();
	this.update();
	this.updateNotifiers();
}

siggy2.Activity.Notifications.prototype.stop = function()
{
	clearTimeout(this._updateTimeout);
	clearTimeout(this._updateTimeoutNotifiers);
	$('#activity-' + this.key).hide();
}

siggy2.Activity.Notifications.prototype.notifierSubmit = function()
{
	var $this = this;
	var data = $('#notifier-form form').serializeObject();

	var url = '';
	if( this.notifierFormState == 'add' )
	{
		url = this.core.settings.baseUrl + 'notifications/notifiers_add';
	}
	else if( this.notifierFormState == 'edit' )
	{
		url = this.core.settings.baseUrl + 'notifications/notifiers_edit';

		data.id = 0;
	}
	else
	{
		return;
	}

	$.post(url, data,
	function (ret)
	{
		$this.updateNotifiers();
		$.unblockUI();
	});
}

siggy2.Activity.Notifications.prototype.notifierDelete = function(id)
{
	var $this = this;
	var data = {
		id: id
	}

	$.post(this.core.settings.baseUrl + 'notifications/notifiers_delete', data,
	function (ret)
	{
		$this.updateNotifiers();
	});
}

siggy2.Activity.Notifications.prototype.getNotifierTitle = function(notifier)
{
	switch( notifier )
	{
		case 'system_mapped':
			return 'System Mapped';
		case 'system_resident_found':
			return 'Resident Found';
		case 'site_found':
			return 'Site found';
	}
}

siggy2.Activity.Notifications.prototype.getNotifierTemplate = function(notifier)
{
	switch( notifier )
	{
		case 'system_mapped':
			return this.notifierFormSystemMapped;
		case 'system_resident_found':
			return this.notifierFormResidentFound;
		case 'site_found':
			return this.notifierFormSiteFound;
	}
}


siggy2.Activity.Notifications.prototype.openNotifierForm = function(notifier)
{
	$('.notifier-system-typeahead').typeahead('destroy');
	$('#notifier-form div.form-content').empty();

	var $this = this;
	var data = {
		errors: {},
		scopes: [
			{
				value: 'personal',
				text: 'Personal'
			},
			{
				value: 'group',
				text: 'Group'
			}
		],
		notifier: {
			type: notifier,
			num_jumps: '0',
			resident_name: '',
			system_name: ''
		}
	};

	if( notifier == 'site_found' )
{'fraction_non_alphanumeric': 0.16511160977914255, 'fraction_numerical': 0.0056690681469233496, 'mean_word_length': 4.445659163987139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4099516', 'n_tokens_mistral': 3197, 'n_tokens_neox': 2913, 'n_words': 458}