/*
 * insert license here
 */
LLMAP.UI.SearchPanel=Ext.extend(Ext.Panel,{border:false,initComponent:function(){Ext.apply(this,{layout:"column",items:[{layout:"fit",padding:"0 5 0 0",border:false,width:515,height:450,items:{xtype:"fieldset",layout:"anchor",title:"By Region",margins:"0 10 0 0",buttonAlign:"center",items:[new LLMAP.UI.MapPanel({ref:"../../mapPanel",border:true,anchor:"100%",height:325,srs:"EPSG:3857",zoom:0,lat:5287403,lon:78271,basemap:new LLMAP.BaseMaps.Vector({overlayStyles:["search-admin0-boundary","search-admin1-boundary"]}),overlay:new LLMAP.BaseMaps.DefaultOverlay({defaultVisibility:[true,true,false]}),use_zoom_bar:false}),{border:false,height:40,anchor:"100%",html:'<div class="info" style="text-align: center;"><p>Zoom to the desired region on the map and click Search Visible Region below. To zoom in, use left double click or hold shift and draw a square. To zoom out, use right double click.</p></div>'}],buttons:[{text:"Search Region",scope:this,handler:function(a){var d=this.mapPanel.olmap;var c=d.getExtent().transform(d.getProjectionObject(),d.displayProjection);document.location.href="/search.html?maxx="+c.right+"&minx="+c.left+"&maxy="+c.top+"&miny="+c.bottom}}]}},{layout:"fit",border:false,padding:"0 0 0 5",height:400,width:425,items:{layout:"vbox",border:false,items:[{xtype:"fieldset",title:"By Country",margins:"0 0 18 0",width:395,items:{xtype:"form",border:false,buttonAlign:"center",labelAlign:"right",labelWidth:75,labelPadding:5,anchor:"100%",items:[new LLMAP.CountrySelector({xtype:"countryselector",hiddenName:"country",fieldLabel:"Country",anchor:"100%"})],buttons:[{text:"Search",scope:this,handler:function(a){var c=a.ownerCt.ownerCt.getForm();document.location.href="/search.html?"+Ext.urlEncode(c.getFieldValues())}},{text:"Reset",scope:this,handler:function(a){a.ownerCt.ownerCt.getForm().reset()}}]}},{xtype:"fieldset",title:"By Creator or Source",margins:"0 0 17 0",width:395,items:[{xtype:"form",border:false,buttonAlign:"center",labelAlign:"right",labelWidth:75,labelPadding:5,buttons:[{text:"Search",scope:this,handler:function(a){var c=a.ownerCt.ownerCt.getForm();document.location.href="/search.html?"+Ext.urlEncode(c.getFieldValues())}},{text:"Reset",scope:this,handler:function(a){a.ownerCt.ownerCt.getForm().reset()}}],items:[{xtype:"textfield",name:"authorfn",anchor:"100%",fieldLabel:"First Name",submitValue:false,emptyText:"Enter the first few characters of the name"},{xtype:"textfield",name:"authorln",anchor:"100%",fieldLabel:"Last Name",submitValue:false,emptyText:"Enter the first few characters of the name"},{xtype:"textfield",name:"title",anchor:"100%",fieldLabel:"Title",submitValue:false,emptyText:"Enter at least one word from the publication title"}]}]},{xtype:"fieldset",title:"By Language",margins:0,width:395,items:[{xtype:"form",border:false,buttonAlign:"center",labelAlign:"right",labelWidth:75,labelPadding:5,buttons:[{text:"Search",scope:this,handler:function(a){var d=a.ownerCt.ownerCt.getForm();var e=d.findField("language").getValue();var c;if(e!==""){document.location.href="/languages/"+e+".html"}else{if(c!==""){document.location.href="/languages/"+c+".html"}}}},{text:"Reset",scope:this,handler:function(a){a.ownerCt.ownerCt.getForm().reset()}}],items:[new LLMAP.CodeSelector({codeType:"language",hiddenName:"language",anchor:"100%",fieldLabel:"Language",emptyText:"Enter at least two letters of the language name"})]}]}]}}]});LLMAP.UI.SearchPanel.superclass.initComponent.call(this)},setInitialSelection:function(){var h=["sw-resize","s-resize","se-resize","e-resize","ne-resize","n-resize","nw-resize","w-resize"];var g=function(k){var j=OpenLayers.Util.indexOf(this.transformControl.handles,k);if(j==-1){return"inherit"}else{j=(j+8+Math.round(this.transformControl.rotation/90)*2)%8;return h[j]}};var c={getCursor:g.createDelegate(this)};var f=new OpenLayers.Style({cursor:"${getCursor}",pointRadius:5,fillColor:"white",fillOpacity:1,strokeColor:"black"},{context:c});this.selectionLayer=new OpenLayers.Layer.Vector("Simple Geometry",{styleMap:new OpenLayers.StyleMap({transform:f})});this.transformControl=new OpenLayers.Control.TransformFeature(this.selectionLayer,{rotate:false,renderIntent:"transform"});this.mapPanel.olmap.addLayer(this.selectionLayer);this.mapPanel.olmap.addControl(this.transformControl);var e=this.mapPanel.olmap.getExtent();var a=e.getCenterLonLat();var b=e.getWidth()*0.25;var d=new OpenLayers.Bounds(a.lon-b,a.lat-b,a.lon+b,a.lat+b);this.geometry=d.toGeometry();this.feature=new OpenLayers.Feature.Vector(this.geometry);this.selectionLayer.addFeatures([this.feature]);this.transformControl.setFeature(this.feature)}});LLMAP.UI.SearchResults=Ext.extend(Ext.Panel,{pageSize:20,initComponent:function(){var a={};Ext.apply(a,this.searchParams);this.ds=new Ext.data.Store({baseParams:a,proxy:new Ext.data.HttpProxy({url:"/search.json",method:"GET"}),reader:new Ext.data.JsonReader({idProperty:"id",root:"data",totalProperty:"total",fields:["id","url","name","author_fn","author_ln","publication"]})});Ext.apply(this,{layout:"fit",border:true,autoScroll:true,items:{xtype:"dataview",border:false,emptyText:'<p class="search-results-empty">No results matched your search.</p>',itemSelector:"div.search-result",overClass:"search-result-over",store:this.ds,tpl:new Ext.XTemplate('<tpl for=".">','<div class="search-result" id="entity{id}">','<div class="search-result-preview-container">','<img class="search-result-preview" alt="Preview" src="{url}/preview.png" />',"</div>",'<div class="search-result-description">','<h1 class="search-result-title">{name}</h1>','<tpl if="author_ln !== null">','<div class="search-result-author">Created by {author_fn} {author_ln}</div>',"</tpl>",'<tpl if="publication !== null">','<div class="search-result-publication"><span style="font-style: italic;">Source:</span> {publication}</div>',"</tpl>","</div>","</div>",'<div class="x-clear"></div>',"</tpl>"),listeners:{scope:this,click:function(b,c,d,f){LLMAP.openMapViewer(this.ds.getAt(c).get("id"))}}},bbar:new Ext.PagingToolbar({store:this.ds,pageSize:this.pageSize,displayInfo:true,displayMsg:"Results {0} - {1} of {2}",emptyMsg:"No matches"})});LLMAP.UI.SearchResults.superclass.initComponent.call(this);this.ds.load({params:{start:0,limit:this.pageSize}})}});
