﻿Ext.namespace('Vt.Templates');

Vt.Templates.rlListModel =
'	<div class=\'vt-list-tipologia-comuni\'>{1} {[values.{3} ? "<a href=\'{4}?comuneID=" + values.ID + "\' ><img src=\'/Content/Images/add.gif\'></a>": ""]}</div>' +
'<tpl for="{0}">' +
'	<hr style=\"color:lightgray\" />' +
'	{2}' +
'	<br  style="clear:both;" />' +
'</tpl>'
;

Vt.Templates.rlRistorante =
'{[ values.Latitude !== 0 || values.Longitude !== 0 ? "<a href=\'#map-panel\' ><img src=\'/Content/Images/mappa_toscana30.jpg\' style=\'float:left;\' title=\'Lat: " + values.Latitude + " Long: " + values.Longitude + "\' /></a>" : ""]}' +
'<div style="float:left;margin-left: 1em;">' +
'	<div id="item-{ID}" class="item-selector" ><a href="/Ristoranti/Details/{ID}">{Denominazione}</a></div>' +
'	<div class="">{[values.Indirizzo || ""]} - {[values.CAP || ""]}' +
'		{[values.Localita ? ", Loc. " + values.Localita: ""]}' +
'		{[values.Telefono ? ", Tel. " + values.Telefono: ""]}' +
'		{[values.Fax ? ", Tel. " + values.Fax: ""]}' +
'		{[values.IsConfirmed ? "" : "<img src=\'/Content/MapIcons/balls/red.png\'>"]}' +
'	</div>' +
'	<tpl if="this.exists(Email)">' +
'		<div><a href="mailto:{Email}">{Email}</a></div>' +
'	</tpl>' +
'	<tpl if="this.exists(Web)">' +
'		<div><a href="http://{Web}" target="_blank">{Web}</a></div>' +
'	</tpl>' +
'</div>';

Vt.Templates.rlBottega =
'{[ values.Latitude !== 0 || values.Longitude !== 0 ? "<a href=\'#map-panel\' ><img src=\'/Content/Images/mappa_toscana30.jpg\' style=\'float:left;\' title=\'Lat: " + values.Latitude + " Long: " + values.Longitude + "\' /></a>" : ""]}' +
'<div style="float:left;margin-left: 1em;">' +
'	<div id="item-{ID}" class="item-selector" ><a href="/Botteghe/Details/{ID}">{Denominazione}</a></div>' +
'	<div class="">{[values.Indirizzo || ""]} - {[values.CAP || ""]}' +
'		{[values.Localita ? ", Loc. " + values.Localita: ""]}' +
'		{[values.Telefono ? ", Tel. " + values.Telefono: ""]}' +
'		{[values.Fax ? ", Tel. " + values.Fax: ""]}' +
'		{[values.IsConfirmed ? "" : "<img src=\'/Content/MapIcons/balls/red.png\'>"]}' +
'	</div>' +
'	<tpl if="this.exists(Email)">' +
'		<div><a href="mailto:{Email}">{Email}</a></div>' +
'	</tpl>' +
'	<tpl if="this.exists(Web)">' +
'		<div><a href="http://{Web}" target="_blank">{Web}</a></div>' +
'	</tpl>' +
'</div>';

Vt.Templates.rlSagra =
'{[ values.Latitude !== 0 || values.Longitude !== 0 ? "<a href=\'#map-panel\' ><img src=\'/Content/Images/mappa_toscana30.jpg\' style=\'float:left;\' title=\'Lat: " + values.Latitude + " Long: " + values.Longitude + "\' /></a>" : ""]}' +
'<div style="float:left;margin-left: 1em;">' +
'	<div style="font-weight:bold;color: #950E28;" class="vt-date" >{[this.dateInterval(values)]}</div>' +
'	<div id="item-{ID}" class="vt-denominazione" ><a href="/Sagre/Details/{ID}">{Denominazione}</a></div>' +
'	<div class="vt-indirizzo">{[values.Indirizzo || ""]} - {[values.CAP || ""]}' +
'		{[values.Localita ? ", Loc. " + values.Localita: ""]}' +
'		{[values.Telefono ? ", Tel. " + values.Telefono: ""]}' +
'		{[values.Fax ? ", Tel. " + values.Fax: ""]}' +
'	</div>' +
'	<tpl if="this.exists(Email)">' +
'		<div><a href="mailto:{Email}">{Email}</a></div>' +
'	</tpl>' +
'	<tpl if="this.exists(Web)">' +
'		<div><a href="http://{Web}" target="_blank">{Web}</a></div>' +
'	</tpl>' +
'</div>';

Vt.Templates.rlManifestazione =
'<div style="float:left;width:32px" >{[ values.Latitude !== 0 || values.Longitude !== 0 ? "<a href=\'#map-panel\' ><img src=\'/Content/Images/mappa_toscana30.jpg\' title=\'Lat: " + values.Latitude + " Long: " + values.Longitude + "\' /></a>" : ""]}</div>' +
'<div style="float:left;margin-left: 1em;">' +
'	<div style="font-weight:bold;color: #950E28;" class="item-selector" >{[this.dateInterval(values)]}</div>' +
'	<div id="item-{ID}" class="item-selector" ><a href="/Manifestazioni/Details/{ID}">{Denominazione}</a></div>' +
'	<div class="">{[values.Indirizzo || ""]} - {[values.CAP || ""]}' +
'		{[values.Localita ? ", Loc. " + values.Localita: ""]}' +
'		{[values.Telefono ? ", Tel. " + values.Telefono: ""]}' +
'		{[values.Fax ? ", Tel. " + values.Fax: ""]}' +
'	</div>' +
'	<tpl if="this.exists(Email)">' +
'		<div><a href="mailto:{Email}">{Email}</a></div>' +
'	</tpl>' +
'	<tpl if="this.exists(Web)">' +
'		<div><a href="http://{Web}" target="_blank">{Web}</a></div>' +
'	</tpl>' +
'</div>';

Vt.Templates.rlAmbulante =
'{[ values.Latitude !== 0 || values.Longitude !== 0 ? "<a href=\'#map-panel\' ><img src=\'/Content/Images/mappa_toscana30.jpg\' style=\'float:left;\' title=\'Lat: " + values.Latitude + " Long: " + values.Longitude + "\' /></a>" : ""]}' +
'<div style="float:left;margin-left: 1em;">' +
'	<div id="item-{ID}" class="item-selector" ><a href="/Ambulanti/Details/{ID}">{Denominazione}</a></div>' +
'	<div class="">{[values.Indirizzo || ""]} - {[values.CAP || ""]}' +
'		{[values.Localita ? ", Loc. " + values.Localita: ""]}' +
'		{[values.Telefono ? ", Tel. " + values.Telefono: ""]}' +
'		{[values.Fax ? ", Tel. " + values.Fax: ""]}' +
'	</div>' +
'	<tpl if="this.exists(Email)">' +
'		<div><a href="mailto:{Email}">{Email}</a></div>' +
'	</tpl>' +
'	<tpl if="this.exists(Web)">' +
'		<div><a href="http://{Web}" target="_blank">{Web}</a></div>' +
'	</tpl>' +
'</div>';

Vt.Templates.rlStorico =
'{[ values.Latitude !== 0 || values.Longitude !== 0 ? "<a href=\'#map-panel\' ><img src=\'/Content/Images/mappa_toscana30.jpg\' style=\'float:left;\' title=\'Lat: " + values.Latitude + " Long: " + values.Longitude + "\' /></a>" : ""]}' +
'<div style="float:left;margin-left: 1em;">' +
'	<div id="item-{ID}" class="item-selector" ><a href="/Storici/Details/{ID}">{Localita}</a></div>' +
'	<tpl if="this.exists(Email)">' +
'		<div><a href="mailto:{Email}">{Email}</a></div>' +
'	</tpl>' +
'	<tpl if="this.exists(Web)">' +
'		<div><a href="http://{Web}" target="_blank">{Web}</a></div>' +
'	</tpl>' +
'</div>';

Vt.Templates.ResultList = new Ext.XTemplate('<div class="vt-result-list">' +
'<tpl for=".">' +
'	<tpl for="Comuni">' +
'		<div class="vt-list-comune"></div>' +
String.format(Vt.Templates.rlListModel, 'Sagre', 'Sagre e Fiere', Vt.Templates.rlSagra, 'CanAddSagra', '/Sagre/Create') +
String.format(Vt.Templates.rlListModel, 'Manifestazioni', 'Manifestazioni Fieristiche', Vt.Templates.rlManifestazione, 'CanAddManifestazione', '/Manifestazioni/Create') +
String.format(Vt.Templates.rlListModel, 'Ambulanti', 'Mercati Ambulanti', Vt.Templates.rlAmbulante, 'CanAddAmbulante', '/Ambulanti/Create') +
String.format(Vt.Templates.rlListModel, 'Storici', 'Commercio Storico', Vt.Templates.rlStorico, 'CanAddStorico', '/Storici/Create') +
String.format(Vt.Templates.rlListModel, 'Ristoranti', 'Ristoranti', Vt.Templates.rlRistorante, 'CanAddRistorante', '/Ristoranti/Create') +
String.format(Vt.Templates.rlListModel, 'Botteghe', 'Botteghe', Vt.Templates.rlBottega, 'CanAddBottega', '/Botteghe/Create') +
'		<br />' +
'	</tpl>' +
'	<br />' +
'</tpl>' +
'</div>', {
	exists: function(o){
		return typeof o != 'undefined' && o != null && o != '';
	},
	dateInterval: function(values){
		if (values.StartDate.valueOf() === values.EndDate.valueOf()){
			return values.StartDate.format('d/m/Y');
		}
		else{
			return values.StartDate.format('d/m/Y') + '<span class="vt-date-end"> &gt; ' + values.EndDate.format('d/m/Y') + '</span>';
		}
	}
}
).compile();


