/**
 * @class Roo.gui.AuthenticInfoPanel
 * @extends Ext.Panel
 *
 * The AuthenticInfoPanel shows per part of a plan the details about authenticity.
 *
 * @author ssmeman
 * @version 1.0
 */

/**
 * @constructor
 * @param {Object} config Configuration options
 */
Roo.gui.AuthenticInfoPanel = Ext.extend(Ext.Panel, {
	titleText: messages.signatureWindow.authenticiteitPanel.title()

	,id: 'authenticInfoPanel'

	,constructor: function(config) {
		this.onderdelen = [];

		this.plan = config.plan;

		for(prop in this.plan.onderdelen) {
			if(this.plan.onderdelen[prop].constructor == Object) {
				this.onderdelen[this.onderdelen.length] = this.plan.onderdelen[prop];
			}
		}

		Roo.gui.AuthenticInfoPanel.superclass.constructor.apply(this, arguments);
	}

	,initComponent:function() {
		var config = {
			title: this.titleText
			,items: [{
				xtype: 'grid'
				,menuDisabled: true
				,height: 410
				,width: 560
				,defaultSortable: false
				,disableSelection: true
				,enableHdMenu: false
				,store: new Ext.data.Store({
					reader: new Ext.data.JsonReader({}, Ext.data.Record.create([
						{name: 'type'}
						,{name: 'naam'}
						,{name: 'digestValid'}
						,{name: 'signatureValid'}
						,{name: 'invalidReason'}
					]))
					,data: this.onderdelen
				})
				,columns: [
					{id:'name', header:'Planonderdeel', width:260, dataIndex:'naam'  }
					,{id:'type', header:'Type', width:100, dataIndex:'type', renderer: Ext.util.Format.capitalize }
					,{id:'digest', header:'&nbsp;', width:20, dataIndex:'digestValid', tooltip:'Checksum', renderer: this.formatDigest, align: 'center' }
					,{id:'signature', header:'&nbsp;', width:20, dataIndex:'signatureValid', tooltip:'Handtekening', renderer: this.formatSignature, align: 'center' }
				]
				,viewConfig: {
			        forceFit: true
			    }
			}]
		};

		Ext.apply(this, config);
		Ext.apply(this.initialConfig, config);

		// call parent initComponent
		Roo.gui.AuthenticInfoPanel.superclass.initComponent.apply(this, arguments);

		this.grid = this.items.itemAt(0);

	} // e/o function initComponent

	,formatDigest: function(value, p, record) {
		if(record.json.digestValid) {
			p.attr = 'title="De checksum is valide"';
		}
		else if (record.json.invalidReason) {
			p.attr = 'title="' + record.json.invalidReason + '"';
		}
		else {
			p.attr = 'title="De checksum is niet valide"';
		}

		var tmpl = new Ext.XTemplate(
			'<tpl if="this.isAuthentic(digestValid)">',
				'<img src="./extjs/resources/images/default/s.gif" class="x-icon-tick">',
			'</tpl>',
			'<tpl if="!this.isAuthentic(digestValid)">',
				'<img src="./extjs/resources/images/default/s.gif" class="x-icon-cross">',
			'</tpl>',
			{
				isAuthentic: function(authentic) {
					return authentic;
				}
			}
		);

		return tmpl.apply(record.json);
	}
	,formatSignature: function(value, p, record) {
		if((record.json.type == 'GELEIDEFORMULIER')) {
			if(record.json.signatureValid) {
				p.attr = 'title="De handtekening is valide"';
			}
			else if(record.json.invalidReason) {
				p.attr = 'title="' + record.json.invalidReason + '"';
			}
			else {
				p.attr = 'title="De handtekening is niet valide"';
			}
		}
		var tmpl = new Ext.XTemplate(
			'<tpl if="this.isGeleideFormulier(type)">',
				'<tpl if="this.isAuthentic(signatureValid)">',
					'<img src="./extjs/resources/images/default/s.gif" class="x-icon-tick">',
				'</tpl>',
				'<tpl if="!this.isAuthentic(signatureValid)">',
					'<img src="./extjs/resources/images/default/s.gif" class="x-icon-cross">',
				'</tpl>',
			'</tpl>',
			{
				isAuthentic: function(authentic) {
					return authentic;
				}
				,isGeleideFormulier: function(type) {
					return (type == 'GELEIDEFORMULIER');
				}
			}
		);

		return tmpl.apply(record.json);
	}

});	// e/o extend

// register xtype
Ext.reg('authenticInfoPanel', Roo.gui.AuthenticInfoPanel);
// }}}