/**
 * @copyright SilverBiology
 * @author Michael Giddens
 * @website http://www.silverbiology.com
*/
Ext.ns('Config', 'Config.Default', 'Config.Default.Grid', 'Config.Default.Specimen', 'Config.Default.Checklist', 'Config.Default.Images', 'Config.Default.Image');

// This will prompt a confirm box when leaving the application
// 1 = Enabled; 0 = Disabled
Config.Unload = 1;  

Config.URL = "http://collection.silverbiology.com/ulm/herbarium/";

Config.recaptcha = { publickey: '6LdyhgIAAAAAAB_oZ5jT9RW4hjlWz99yIWRvHLZx' } // collection.silverbiology.com

Config.key = '48d73d487a0752b59d95788a818525c1'; // 'Localhost'


Config.Default.Images = {
		originals_location: 'http://collection.silverbiology.com/ulm/herbarium/image/'
	,	pageSize: 50
	,	view_tpl:	'<tpl for=".">' +
						'<div class="thumb-wrap" id="{id}">' +
						'<div class="thumb"><img onerror=\'this.src="images/no-image.gif"\'; src="http://collection.silverbiology.com/ulm/herbarium/image/non_specimen/{family}/{genus}/{species}/{filename}_s.{extension}" title="{family} {genus} {species}"></div>' +
						'<span class="x-editable">{family} {genus} {species}</span></div>' +
					'</tpl>' +
					'<div class="x-clear"></div>'
}

/*
* Hints
*/
Config.Hint = {
		show: false
	,	delay: 7000
	,	msgs: [
			{text: 'Double clicking on records opens up the details.'}
		,	{text: 'Right click gives you more options for certain things.'}
		]
}

Config.Default.Image = {
	image_tpl: '<img id="image_{file}" onerror="this.src=\'images/no-image.gif\'" title="{family} {genus} {species}" src="http://collection.silverbiology.com/ulm/herbarium/image/non_specimen/{family}/{genus}/{species}/{filename}/{file}_l.jpg" />'
}

Config.Default.Filter = {
	filters: [{
			xtype: 'xtwincombo'
		, fieldLabel: 'Family'
		, name: 'Family'
		,	queryParam: 'filter'		
		,	store: new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
				,	baseParams: {"type":"Family"}
				, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
			})
		,	displayField: 'name'
		,	typeAhead: false
		,	hideTrigger2: true
		,	minChars: 2
		,	value:''
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}
	}, {
			xtype: 'xtwincombo'
		, fieldLabel: 'Genus'
		, name: 'Genus'
		,	queryParam: 'filter'		
		,	store: new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
				,	baseParams: {"type":"Genus"}
				, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
			})
		,	displayField: 'name'
		,	typeAhead: false
		,	hideTrigger2: true
		,	minChars: 2
		,	value:''
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}		
	}, {
			xtype: 'xtwincombo'
		, fieldLabel: 'Species'
		, name: 'SpecificEpithet'
		,	queryParam: 'filter'		
		,	store: new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
				,	baseParams: {"type":"SpecificEpithet"}
				, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
			})
		,	displayField: 'name'
		,	typeAhead: false
		,	hideTrigger2: true
		,	minChars: 2
		,	value:''
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}		
	}, {
			xtype: 'xtwincombo'
		, fieldLabel: 'Parish'
		, name: 'County'
		,	queryParam: 'filter'		
		,	store: new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
				,	baseParams: {"type":"County"}
				, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
			})
		,	displayField: 'name'
		,	typeAhead: false
		,	hideTrigger2: true
		,	minChars: 2
		,	value:''
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}		
	}, {
			xtype: 'xtwincombo'
		, fieldLabel: 'Collection'
		, name: 'InstitutionCode'
		,	queryParam: 'filter'		
		,	store: new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
				,	baseParams: {"type":"InstitutionCode"}
				, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
			})
		,	displayField: 'name'
		,	typeAhead: false
		,	hideTrigger2: false
		, triggerAction: 'all'
		,	editable: false
		,	value:''
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}		
	}, {
			xtype: 'xtwincombo'
		, fieldLabel: 'Collector'
		, name: 'Collector'
		,	queryParam: 'filter'		
		,	store: new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
				,	baseParams: {"type":"Collector"}
				, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
			})
		,	displayField: 'name'
		,	typeAhead: false
		,	hideTrigger2: true
		,	minChars: 2
		,	value:''
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}		
	}, {
			xtype: 'xtwincombo'
		, fieldLabel: 'Collector #'
		, name: 'CollectorNumber'
		,	queryParam: 'filter'		
		,	store: new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
				,	baseParams: {"type":"CollectorNumber"}
				, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
			})
		,	displayField: 'name'
		,	typeAhead: false
		,	hideTrigger2: true
		,	minChars: 2
		,	value:''
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}					
	}, {
			xtype: 'xtwincombodate'
		, fieldLabel: 'Collected Start'
		, name: 'EarliestStartDate'
		,	readOnly: true
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}		
	}, {
			xtype: 'xtwincombodate'
		, fieldLabel: 'Collected End'
		, name: 'EarliestEndDate'
		,	readOnly: true
		, listeners: {
					'select': function() { this.ownerCt.grid.store.load(); }
				,	'clear': function() { this.ownerCt.grid.store.load(); }
			}		
	}]
}


//================================================================================
/*
Config.Default.Checklist.Grid = {	
		extensions: [ 
				SilverCollection.plugins.Download
			,	SilverCollection.plugins.Email
		]		
}
*/
Config.Default.Checklist = {	

		Grid: {
			extensions: [ 
					SilverCollection.plugins.Download
				,	SilverCollection.plugins.Email
			]		
		}
		
		// required. Note: empty setting would be "cm: []"
	,	cm: [{
						 header: "State",
						 dataIndex: 'StateProvince',
						 sortable: true,
						 width: 80
					},{
						 header: "Parish",
						 dataIndex: 'County',
						 sortable: true,
						 width: 90
					},{
						 header: "Family",
						 dataIndex: 'Family',
						 sortable: true,
						 width: 90
					}	,{
						 header: "Genus",
						 dataIndex: 'Genus',
						 sortable: true,
						 width: 80
					}	,{
						 header: "Species",
						 dataIndex: 'SpecificEpithet',
						 sortable: true,
						 width: 160
					}	,{
						 header: "Specimens",
						 dataIndex: 'specimen_count',
						 width: 80,
						 sortable: false
			}]

		// required. Note: empty setting would be ", recordType: []"
	,	recordType: [
				{name: 'StateProvince'}
			,	{name: 'County'}
			,	{name: 'Family'}
			,	{name: 'Genus'}
			,	{name: 'SpecificEpithet'}
			,	{name: 'specimen_count'}						
		]

	,	sortInfo: {
				field: 'Family'
			, direction: 'ASC'
		}

	,	groupField: 'Family'
	
	, Filter: {
			filters: [{
					xtype: 'xtwincombo'
				, fieldLabel: 'Family'
				, name: 'Family'
				,	queryParam: 'filter'		
				,	store: new Ext.data.Store({
							proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
						,	baseParams: {"type":"Family"}
						, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
					})
				,	displayField: 'name'
				,	typeAhead: false
				,	hideTrigger2: true
				,	minChars: 2
				,	value:''
				, listeners: {
							'select': function() { this.ownerCt.grid.store.load(); }
						,	'clear': function() { this.ownerCt.grid.store.load(); }
					}
			}, {
					xtype: 'xtwincombo'
				, fieldLabel: 'Genus'
				, name: 'Genus'
				,	queryParam: 'filter'		
				,	store: new Ext.data.Store({
							proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
						,	baseParams: {"type":"Genus"}
						, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
					})
				,	displayField: 'name'
				,	typeAhead: false
				,	hideTrigger2: true
				,	minChars: 2
				,	value:''
				, listeners: {
							'select': function() { this.ownerCt.grid.store.load(); }
						,	'clear': function() { this.ownerCt.grid.store.load(); }
					}		
			}, {
					xtype: 'xtwincombo'
				, fieldLabel: 'Species'
				, name: 'Species'
				,	queryParam: 'filter'		
				,	store: new Ext.data.Store({
							proxy: new Ext.data.HttpProxy({url: 'server/form_lists.php'})
						,	baseParams: {"type":"Species"}
						, reader: new Ext.data.JsonReader({root: 'nodes',	id: 'name'}, [ {name: 'name', mapping: 'name'} ])
					})
				,	displayField: 'name'
				,	typeAhead: false
				,	hideTrigger2: true
				,	minChars: 2
				,	value:''
				, listeners: {
							'select': function() { this.ownerCt.grid.store.load(); }
						,	'clear': function() { this.ownerCt.grid.store.load(); }
					}		
			}]
		}


	,	biodiversity_cm: [{
				header: "Family"
			,	dataIndex: 'Family'
			,	sortable: true
			,	width: 95
		}, {
				header: "Genus"
			,	dataIndex: 'Genus'
			,	sortable: true
			,	width: 90
		}, {
				header: "Species"
			,	dataIndex: 'SpecificEpithet'
			,	sortable: true
			,	width: 80
		}]

	,	biodiversity_recordType: [
				{name: 'Phylum'}
			,	{name: 'Family'}
			,	{name: 'Genus'}
			,	{name: 'SpecificEpithet'}
			,	{name: 'R0'}
			,	{name: 'R1'}
			,	{name: 'R2'}
			,	{name: 'R3'}
			,	{name: 'R4'}
			,	{name: 'R5'}
			,	{name: 'R6'}
			,	{name: 'R7'}
			,	{name: 'R8'}
			,	{name: 'R9'}
			,	{name: 'R10'}
			,	{name: 'R11'}
			,	{name: 'R12'}
			,	{name: 'R13'}
			,	{name: 'R14'}
			,	{name: 'R15'}
			,	{name: 'R16'}
			,	{name: 'R17'}
			,	{name: 'R18'}
			,	{name: 'R19'}
			,	{name: 'R20'}
		]
}

//================================================================================

Config.Default.Modules = [{
			module: SilverCollection.Browse
	}, {
			module: SilverCollection.Search
	}, {
	  	module: SilverCollection.Checklist
	}, {
	  	module: SilverCollection.Images
/*			
	}, {
	  	module: SilverCollection.ExternalLink
		, config: {
					text: 'FactSheets'
				,	iconCls: 'icon_factsheets'
				,	link: 'http://www.herbarium.lsu.edu/factsheets'
			}
*/			
	}
]

Config.Default.Grid.Specimens = {	

		// required. Note: empty setting would be "cm: []"
		cm: [{
/*				 
					sortable: false
				, dataIndex: 'specimen_sheet_image'
				, renderer: this.renderImageAvail
				, width: 26
				,	menuDisabled: true
				, resizable: false
				,	tooltip: 'Specimen Sheet Available'
			}, {
					sortable: false
				,	dataIndex: 'llAvail'
				, renderer: this.renderllAvail
				, width: 26
				,	menuDisabled: true
				, resizable: false
				,	tooltip: 'Coordinates Available'				
			}, {
*/				
					header: Lang.Get('Core','grid_specimens','CatalogNumber')
				,	dataIndex: 'CatalogNumber'
				,	width: 62
			}, {
				 	header: Lang.Get('Core','grid_specimens','Family')
				,	dataIndex: 'Family'
				,	width: 80
			}, {
					header: Lang.Get('Core','grid_specimens','Genus')
				,	dataIndex: 'Genus'
				,	width: 70
			}, {
					header: Lang.Get('Core','grid_specimens','Epithet')
				,	dataIndex: 'SpecificEpithet'
				,	width: 120
				,	renderer: function(value, p, r) {
						return String.format('{0} {1} {2}', value, r.data.InfraspecificRank, r.data.InfraspecificEpithet);
					}
			},{
					header: Lang.Get('Core','grid_specimens','StateProvince')
				,	dataIndex: 'StateProvince'
				,	width: 75
			},{
					header: Lang.Get('Core','grid_specimens','County')
				,	dataIndex: 'County'
				,	width: 120
/*				
			},{
					header: Lang.Get('Core','grid_specimens','Locality')
				,	dataIndex: 'Locality'
				,	width: 120
*/				
			}	,{
					header: "Collection"
				,	dataIndex: 'InstitutionCode'
				,	width: 80
			}	,{
					header: "Collector"
				,	dataIndex: 'Collector'
				,	width: 120
			}	,{
					header: "Locality"
				,	dataIndex: 'text_2'
				,	width: 100
			}]

		// required. Note: empty setting would be ", recordType: []"
	,	recordType: [
				{name: 'specimen_sheet_image'}
			,	{name: 'llAvail'}
			, {name: 'iucn_redlist_type'}
			,	{name: 'CatalogNumber'}
			,	{name: 'Family'}
			,	{name: 'Genus'}
			,	{name: 'SpecificEpithet'}
			,	{name: 'StateProvince'}
			,	{name: 'County'}
			,	{name: 'Locality'}
			,	{name: 'InstitutionCode'}
			,	{name: 'text_2'}
			,	{name: 'InfraspecificRank'}
			,	{name: 'InfraspecificEpithet'}
			,	{name: 'Collector', mapping: 'Collector'}
//			,	{name: 'collected', mapping: 'collected', type: 'date', dateFormat: 'timestamp'}
		]

	,	sortInfo: {
				field: 'Family'
			, direction: 'ASC'
		}

	,	groupField: 'Family'
	
	,	extensions: [ 
				SilverCollection.plugins.Download
			,	SilverCollection.plugins.Email
//			,	SilverCollection.plugins.Distribution
		]		
}

Config.Default.Specimen.Window = {
		title: Lang.Get('Core', 'specimen', 'title')
	,	width: 700
	, height: 400
	, extensions: [{ 
			module: SilverCollection.plugins.SpecimenInfo	// Record Information
//		}, {
//			module: SilverCollection.plugins.SpecimenSheet	// Specimen Sheet Module
//		}, {
//			module: SilverCollection.plugins.SpecimenClimate	// Specimen Sheet Module
//		}, {
//			module: SilverCollection.plugins.Coordinates	// Specimen Sheet Module			
		}, {
			module: SilverCollection.plugins.SpecimenAnnotation	// Annotations
		}]
};

Config.Default.Specimen.Info = {
		title: 'Specimen Record'
	,	width: 500
	, height: 300
};

Config.Default.Specimen.SpecimenSheet_tpl = new Ext.XTemplate(
	'<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="{specimen_sheet_width}" HEIGHT="{specimen_sheet_height}">' +
		'<PARAM NAME="FlashVars" VALUE="zoomifyImagePath=' + Config.URL + '{specimen_sheet_path}/">' +
		'<PARAM NAME="MENU" VALUE="FALSE">' +
		'<PARAM NAME="SRC" VALUE="zoomifyViewer.swf">' +
		'<EMBED FlashVars="zoomifyImagePath=' + Config.URL + '{specimen_sheet_path}/" SRC="zoomifyViewer.swf\" MENU="false" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"  WIDTH="{specimen_sheet_width}" HEIGHT="{specimen_sheet_height}"></EMBED>' + 
	'</OBJECT>'
);

Config.Default.Specimen.Info_tpl = new Ext.XTemplate(
	'<div class="specimen-detail">',

		'<div class="taxontree">',
			'<div class="taxontree-header"></div>',
			'<span class="taxontree-label">Classification :: Taxonomy</span>',
			'<ul style="padding-top:10px;">',
					'<p><label>{ScientificName}</label></p>',
					'<li>{Family}</li>',
							'<ul>',			
							'<li>{Genus}</li>',
								'<ul>',			
								'<li>{SpecificEpithet}</li>',
									'<ul>',			
									'<li>{InfraspecificRank} {InfraspecificEpithet}</li>',
									'</ul>',
								'</ul>',
							'</ul>',
			'</ul>',
			'<p><label>USDA Plants Symbol:</label> <a href="http://plants.usda.gov/java/profile?symbol={usda_plants_symbol}" target="_blank">{usda_plants_symbol}</a></p>',
		'</div>',

		'<div class="taxontree">',
			'<div class="taxontree-header"></div>',
			'<span class="taxontree-label">Locality</span>',
			'<ul style="padding-top:10px;">',
			'<li><label>State:</label> {StateProvince}</li>',
				'<ul>',
				'<li><label>Parish:</label> {County}</li>',
					'<ul>',
					'<li><label>Locality:</label> {text_2}</li>',
					'</ul>',
				'</ul>',
			'</ul>',
			'<p>&nbsp;</p>',
			'<p><label>Collector Name:</label> {Collector}</p>',		
			'<p><label>Collector Number:</label> {CollectorNumber}</p>',		
			'<p><label>Collection Date:</label> {EarliestDateCollected}</p>',		
		'</div>',

		'<div class="taxontree">',
			'<div class="taxontree-header"></div>',
			'<span class="taxontree-label">Record Info</span>',
			'<p style="padding-top:10px;"><label>Global Unique Id:</label> {GlobalUniqueIdentifier}</p>',
			'<p><label>Date Last Modified:</label> {DateLastModified}</p>',
			'<p><label>Basis of Record:</label> {BasisOfRecord}</p>',
			'<p><label>Institution Code:</label> {InstitutionCode}</p>',
			'<p><label>Collection Code:</label> {CollectionCode}</p>',
			'<p><label>Catalog Number:</label> {CatalogNumber}</p>',						
		'</div>',

	'</div>', {
		convLatLon: function(dec) {
			var signlat = 1;
			if(dec < 0) { signlat = -1; }
			latAbs = Math.abs( Math.round(dec * 1000000.));
			return ((Math.floor(latAbs / 1000000) * signlat) + '&deg; ' + Math.floor( ((latAbs/1000000) - Math.floor(latAbs/1000000)) * 60) + '\' ' + ( Math.floor(((((latAbs/1000000) - Math.floor(latAbs/1000000)) * 60) - Math.floor(((latAbs/1000000) - Math.floor(latAbs/1000000)) * 60)) * 100000) *60/100000 ) + '&quot;');
		}						
	}
);
