/*
	Copyright (C) 2008 - Juan Ferrer Toribio

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this program; if not, write to the Free
	Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
	02111-1307 USA.
*/

var VnLinks = new Class
({
	Extends: VnModule,

	activate: function ()
	{
		var n;
		var rendImg;
		var renderer;
		var rendLink;
		var tv;
		var stmt;
		var model;
		var db = this.db;
		
		rendLink = new HtkCellRendererLink ();
		renderer = new HtkCellRendererText ();
		rendImg = new HtkCellRendererImage ();
		rendImg.url = 'link';

		n = -1;
		tv = new HtkTreeView ();
		tv.tr.style.height = '37px';
		tv.appendColumn (++n, rendImg, '');
		tv.appendColumnWithFunc (this.linkRenderer, rendLink, TEXT_Link);
		tv.appendColumn (++n, renderer, TEXT_Description);
		this.setChild (tv);
		
		model = new DbModel (db);
		tv.setModel (model);	
		
		stmt = new SqlString ('SELECT image, description, name, link  FROM link ORDER BY name');
		model.setStmt (stmt);	
	},
	
	linkRenderer: function (renderer, row)
	{
		renderer.text = row[2];
		renderer.href = row[3];
	}
});

var HtkCellRendererLink = new Class
({
	Extends: HtkCellRenderer,
	
	initialize: function ()
	{
		this.parent ();
		this.style.textAlign = 'left';
		this.href = null;
		this.text = '';
	},

	subRender: function (tr)
	{
		var link = document.createElement ('a');;
		link.href = this.href;
		link.target = '_blank';
		link.appendChild (document.createTextNode (this.text));
		return link;
	}
});


