/*
* @license Proprietary
* @copyright Copyright (c) 2014 borkedLabs - All Rights Reserved
*/

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

siggy2.Activity.Thera = function(core)
{
	this.key = 'thera';
	this._updateTimeout = null;
	this.core = core;
	this.sigClocks = {};
	this.eolClocks = {};

	this.templateRow = Handlebars.compile( $("#template-thera-table-row").html() );

	this.table = $('#thera-exits-table tbody');


	var tableSorterHeaders = {
		0: {
			sortInitialOrder: 'asc'
		}
	};

	$('#thera-exits-table').tablesorter(
	{
		headers: tableSorterHeaders
	});

	$('#thera-exits-table').trigger("sorton", [ [[0,0]] ]);
}

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

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

siggy2.Activity.Thera.prototype.update = function()
{
	var $this = this;
	$.ajax({
				url: this.core.settings.baseUrl + 'thera/latest_exits',
				dataType: 'json',
				cache: false,
				async: true,
				method: 'get',
				success: function (data)
				{
					$this.updateTable(data);

					$this._updateTimeout = setTimeout(function(thisObj)
					{
						thisObj.update()
					}, 60000, $this);
				}
		});
}

siggy2.Activity.Thera.prototype.updateTable = function( exits )
{
	var $this = this;

	$('#thera-exits-table tbody tr').each(function()
	{
		var id = $(this).data('id');

		if( typeof exits[id] == 'undefined' )
		{
			$(this).children('td.wormhole-type').qtip('destroy');

			if( typeof $this.sigClocks[id] != 'undefined' )
			{
				$this.sigClocks[i].destroy();
				delete $this.sigClocks[i];
			}

			if( typeof $this.eolClocks[id] != 'undefined' )
			{
				$this.eolClocks[i].destroy();
				delete $this.eolClocks[i];
			}

			$(this).remove();
		}
		else
		{
			exits[id].row_already_exists = true;
		}
	});


	for( var i in exits )
	{
		var exit = exits[i];
		if( exit.row_already_exists )
			continue;

		var wh = siggy2.StaticData.getWormholeByID(exit.wormhole_type);

		if( wh != null )
		{
			desc_tooltip = siggy2.StaticData.templateWormholeInfoTooltip(wh);
			exit.wormhole_name = wh.name;
		}

		var row = this.templateRow( exit );


		this.table.append(row);


		this.sigClocks[exit.id] = new siggy2.Timer(exit.created_at * 1000, null, '#thera-sig-' + exit.id + ' td.age span.age-clock', "test");

		if( wh != null )
		{
			var endDate = parseInt(exit.created_at)+(3600*wh.lifetime);
			this.eolClocks[exit.id] = new siggy2.Timer(exit.created_at * 1000, endDate* 1000, '#thera-sig-' + exit.id + ' td.age p.eol-clock', "test");
		}

		$('#thera-sig-' + exit.id + ' td.wormhole-type').qtip({
			content: {
				text: desc_tooltip
			},
			position: {
				target: 'mouse',
				adjust: { x: 5, y: 5 },
				viewport: $(window)
			}
		});
	}

	$('#thera-exits-table').trigger('update');
}

@@ -171,16 +171,36 @@
 core)%0A%7B%0A
+%09var $this = this;%0A%0A
 %09this.ke
@@ -638,16 +638,737 @@
 ,0%5D%5D %5D);
+%0A%0A%09$('#activity-thera-import').click( function() %7B%0A%09%09$this.dialogImport();%0A%09%7D);%0A%0A%09this.setupDialogImport();%0A%7D%0A%0Asiggy2.Activity.Thera.prototype.setupDialogImport = function()%0A%7B%0A%09var $this = this;%0A%09$('#dialog-import-thera button%5Btype=submit%5D').click( function(e) %7B%0A%09%09e.stopPropagation();%0A%0A%09%09var data = %7B%0A%09%09%09'clean': $('#dialog-import-thera input%5Bname=clean%5D').val()%0A%09%09%7D;%0A%0A%09%09$.post($this.core.settings.baseUrl + 'thera/import_to_chainmap', data,%0A%09%09function (ret)%0A%09%09%7B%0A%09%09%09$.unblockUI();%0A%09%09%7D);%0A%0A%09%09return false;%0A%09%7D);%0A%0A%09$('#dialog-import-thera button%5Btype=reset%5D').click( function() %7B%0A%09%09$.unblockUI();%0A%09%09return false;%0A%09%7D);%0A%7D%0A%0Asiggy2.Activity.Thera.prototype.dialogImport = function()%0A%7B%0A%09this.core.openBox('#dialog-import-thera');
 %0A%7D%0A%0Asigg

Add import Thera to chain map dialog.