
<!--// renderTo element //-->
<div class="mapstv-outer-div">
<!--// mapstv-panel: main mapstv div //-->
<div class=" mapstv-panel">
<!--// mapstv-column-container //-->
<div class=" mapstv-column-container x-column-layout-ct">
<div class="x-column-inner">
<!--// mapstv-column column:left //-->
<div class=" mapstv-column mapstv-column-left x-form-label-top x-column">
<div class="x-form-item ">
<label class="x-form-item-label">Street</label>
<div class="x-form-element">
<input type="text" name="street" msgtarget="under" autocomplete="on" size="20" class="x-form-text x-form-field"/>
</div>
<div class="x-form-clear-left"/></div>
</div>
<div class="x-form-item ">
<label class="x-form-item-label">Zipcode</label>
<div class="x-form-element">
<input type="text" name="zipcode" msgtarget="under" autocomplete="on" size="20" class="x-form-text x-form-field"/>
</div>
<div class="x-form-clear-left"/></div>
</div>
<div class="x-form-item ">
<label class="x-form-item-label">State</label>
<div class="x-form-element">
<input type="text" name="state" msgtarget="under" autocomplete="on" size="20" class="x-form-text x-form-field"/>
</div>
<div class="x-form-clear-left"/></div>
</div>
</div>
<!--// mapstv-column column:right //-->
<div class=" mapstv-column mapstv-column-right x-form-label-top x-column">
<div class="x-form-item ">
<label class="x-form-item-label">Housenumber</label>
<div class="x-form-element">
<input type="text" name="housenumber" msgtarget="under" autocomplete="on" size="20" class="x-form-text x-form-field"/>
</div>
<div class="x-form-clear-left"/></div>
</div>
<div class="x-form-item ">
<label class="x-form-item-label">City</label>
<div class="x-form-element">
<input type="text" name="city" msgtarget="under" autocomplete="on" size="20" class="x-form-text x-form-field"/>
</div>
<div class="x-form-clear-left"/></div>
</div>
<div class="x-form-item ">
<label class="x-form-item-label">Country</label>
<div class="x-form-element">
<input type="text" name="country" msgtarget="under" autocomplete="on" size="20" class="x-form-text x-form-field"/>
</div>
<div class="x-form-clear-left"/></div>
</div>
</div>
<div class="x-clear"/></div>
</div>
</div>
<!--// button //-->
<table cellspacing="0" class="x-btn mapstv-button x-btn-noicon">
<tbody class="x-btn-small x-btn-icon-small-left">
<tr>
<td class="x-btn-tl"><i> </i></td>
<td class="x-btn-tc"/></td>
<td class="x-btn-tr"><i> </i></td>
</tr>
<tr>
<td class="x-btn-ml"><i> </i></td>
<td class="x-btn-mc"><em unselectable="on" class="">
<button type="button" class=" x-btn-text">Generate latitude & longitude and set te marker on the map</button>
</em></td>
<td class="x-btn-mr"><i> </i></td>
</tr>
<tr>
<td class="x-btn-bl"><i> </i></td>
<td class="x-btn-bc"/></td>
<td class="x-btn-br"><i> </i></td>
</tr>
</tbody>
</table>
<!--// gmap panel //-->
<div class=" x-panel mapstv-gmap x-panel-noborder">
<div class="x-panel-bwrap">
<div class="x-panel-body x-panel-body-noheader x-panel-body-noborder"/></div>
</div>
</div>
<!--// mapstv-column-container //-->
<div class=" mapstv-column-container x-column-layout-ct">
<div class="x-column-inner">
<!--// mapstv-column column:left //-->
<div class=" mapstv-column mapstv-column-left x-form-label-top x-column">
<div class="x-form-item ">
<label class="x-form-item-label">Latitude</label>
<div class="x-form-element">
<input type="text" name="latitude" msgtarget="under" autocomplete="on" size="20" class="x-form-text x-form-field"/>
</div>
<div class="x-form-clear-left"/></div>
</div>
</div>
<!--// mapstv-column column:right //-->
<div class=" mapstv-column mapstv-column-right x-form-label-top x-column">
<div class="x-form-item ">
<label class="x-form-item-label">Longitude</label>
<div class="x-form-element">
<input type="text" name="longitude" msgtarget="under" autocomplete="on" size="20" class="x-form-text x-form-field"/>
</div>
<div class="x-form-clear-left"/></div>
</div>
</div>
<div class="x-clear"/></div>
</div>
</div>
</div>
</div>
mapsTv.panel = function(config) {
config = config || {};
//testing code to see the width of parents container
var par = Ext.get(config.renderTo);
var parentWidth = par.getWidth();
alert('ID:'+par.dom.id + ' || CLS:'+par.dom.className +' || WIDHT:'+ parentWidth);
while (parentWidth < 300) {
par = par.parent();
parentWidth = par.getWidth();
alert('ID:'+par.dom.id + ' || CLS:'+par.dom.className +' || WIDHT:'+ parentWidth);
}
//end of testing code
//...
}
if (typeof google === 'undefined') {
document.write('<script src="http://maps.google.com/maps/api/js?sensor=false"><\/script>');
}
mapsTv = {};
mapsTv.panel = function(config) {
config = config || {};
Ext.apply(config,{
border:false
,width: '100%'
,listeners: {}
,items:[{
xtype: 'container'
,border: false
,layout: 'anchor'
,width:'98%'
,anchorSize: {width:'98%', height:'auto'}
,items: [{
xtype: 'container'
,border: false
,layout: 'form'
,labelAlign: 'top'
,labelSeparator: ''
,width: '48%'
,anchor: 'left auto'
,style: 'float:left;'
,items: [{
xtype: 'textfield'
,name: 'street'
,id: 'mapstv'+config.tvId+'-street'
,fieldLabel: _('mapstv.street')
,maxLength: 255
,width:'99%'
,value: config.record.street
,listeners: {
'change': function(){
MODx.fireResourceFormChange();
config.record.street = this.getValue();
Ext.get('tv'+config.tvId).dom.value = JSON.stringify(config.record);
}
}
},{
xtype: 'textfield'
,name: 'zipcode'
,id: 'mapstv'+config.tvId+'-zipcode'
,fieldLabel: _('mapstv.zipcode')
,maxLength: 25
,width:'99%'
,value: config.record.zipcode
,listeners: {
'change': function(){
MODx.fireResourceFormChange();
config.record.zipcode = this.getValue();
Ext.get('tv'+config.tvId).dom.value = JSON.stringify(config.record);
}
}
},{
xtype: 'textfield'
,name: 'state'
,id: 'mapstv'+config.tvId+'-state'
,fieldLabel: _('mapstv.state')
,maxLength: 255
,width:'99%'
,value: config.record.state
,listeners: {
'change': function(){
MODx.fireResourceFormChange();
config.record.state = this.getValue();
Ext.get('tv'+config.tvId).dom.value = JSON.stringify(config.record);
}
}
}]
},{
xtype: 'container'
,border: false
,layout: 'form'
,labelAlign: 'top'
,labelSeparator: ''
,width: '48%'
,anchor: 'right auto'
,style: 'float:right; '
,items: [{
xtype: 'textfield'
,name: 'housenumber'
,id: 'mapstv'+config.tvId+'-housenumber'
,fieldLabel: _('mapstv.housenumber')
,maxLength: 255
,width:'99%'
,value: config.record.housenumber
,listeners: {
'change': function(){
MODx.fireResourceFormChange();
config.record.housenumber = this.getValue();
Ext.get('tv'+config.tvId).dom.value = JSON.stringify(config.record);
}
}
},{
xtype: 'textfield'
,name: 'city'
,id: 'mapstv'+config.tvId+'-city'
,fieldLabel: _('mapstv.city')
,maxLength: 255
,width:'99%'
,value: config.record.city
,listeners: {
'change': function(){
MODx.fireResourceFormChange();
config.record.city = this.getValue();
Ext.get('tv'+config.tvId).dom.value = JSON.stringify(config.record);
}
}
},{
xtype: 'textfield'
,name: 'country'
,id: 'mapstv'+config.tvId+'-country'
,fieldLabel: _('mapstv.country')
,maxLength: 255
,width:'99%'
,value: config.record.country
,listeners: {
'change': function(){
MODx.fireResourceFormChange();
config.record.country = this.getValue();
Ext.get('tv'+config.tvId).dom.value = JSON.stringify(config.record);
}
}
}]
}]
},{
xtype: 'container'
,style: 'clear:both;'
},{
xtype: 'button'
,text: _('mapstv.generate')
,style: 'margin: 10px 0'
,tv: config.tvId
,handler: this.generate
,width:'100%'
},{
xtype: 'gmappanel'
,id: 'tv'+config.tvId+'-gmappanel'
,height: 250
,anchor:'100%'
,width:'100%'
,gmapType: 'map'
,zoomLevel: 14
,mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom']
,mapControls: ['GSmallMapControl','GMapTypeControl']
,bodyStyle: 'padding: 5px;'
,listeners: {
beforeRender: function(){
//Check if laltude and lonitude are set
if(config.record.latitude != 0 && config.record.longitude != 0){
//Add marker with latitude and longitude
var point = new google.maps.LatLng(config.record.latitude, config.record.longitude);
this.setCenter = {
lat: config.record.latitude
,lng: config.record.longitude
,marker: {
title: config.record.street +' '+ config.record.housenumber
,draggable: true
}
,listeners:{
drag: function(e){
var LatLng = e.latLng;
Ext.getCmp('mapstv'+config.tvId+'-latitude').setValue(LatLng.$a);
Ext.getCmp('mapstv'+config.tvId+'-longitude').setValue(LatLng.ab);
Ext.getCmp('mapstv'+config.tvId+'-latitude').fireEvent('change');
Ext.getCmp('mapstv'+config.tvId+'-longitude').fireEvent('change');
}
}
};
}else{
//Check if address is set
if(config.record.street && config.record.housenumber && config.record.zipcode && config.record.city && config.record.state && config.record.country){
//Add marker with address
this.setCenter = {
geoCodeAddr: config.record.street +' '+ config.record.housenumber +' '+ config.record.zipcode +' '+ config.record.city +' '+ config.record.state +' '+ config.record.country
,marker: {
title: config.record.street +' '+ config.record.housenumber
,draggable: true
}
,listeners:{
drag: function(e){
var LatLng = e.latLng;
Ext.getCmp('mapstv'+config.tvId+'-latitude').setValue(LatLng.$a);
Ext.getCmp('mapstv'+config.tvId+'-longitude').setValue(LatLng.ab);
Ext.getCmp('mapstv'+config.tvId+'-latitude').fireEvent('change');
Ext.getCmp('mapstv'+config.tvId+'-longitude').fireEvent('change');
}
}
};
}else{
//Nothing isset hide Google Map, latitude and longitude
}
}
}
}
},{
xtype: 'container'
,border: false
,layout: 'anchor'
,width:'98%'
,anchorSize: {width:'98%', height:'auto'}
,items: [{
xtype: 'container'
,border: false
,layout: 'form'
,labelAlign: 'top'
,labelSeparator: ''
,width: '48%'
,anchor: 'left auto'
,style: 'float:left;'
,items: [{
xtype: 'textfield'
,name: 'latitude'
,id: 'mapstv'+config.tvId+'-latitude'
,fieldLabel: _('mapstv.latitude')
,maxLength: 255
,width:'99%'
,value: config.record.latitude
,listeners: {
'change': function(){
MODx.fireResourceFormChange();
config.record.latitude = this.getValue();
Ext.get('tv'+config.tvId).dom.value = JSON.stringify(config.record);
}
}
}]
},{
xtype: 'container'
,border: false
,layout: 'form'
,labelAlign: 'top'
,labelSeparator: ''
,width: '48%'
,anchor: 'right auto'
,style: 'float:right;'
,items: [{
xtype: 'textfield'
,name: 'longitude'
,id: 'mapstv'+config.tvId+'-longitude'
,fieldLabel: _('mapstv.longitude')
,maxLength: 255
,width:'99%'
,value: config.record.longitude
,listeners: {
'change': function(){
MODx.fireResourceFormChange();
config.record.longitude = this.getValue();
Ext.get('tv'+config.tvId).dom.value = JSON.stringify(config.record);
}
}
}]
}]
},{
xtype: 'container'
,style: 'clear:both;'
}]
});
mapsTv.panel.superclass.constructor.call(this,config);
};
//Ext.extend(mapsTv.panel,MODx.Panel,{
Ext.extend(mapsTv.panel,Ext.Container,{
generate: function(){
var tvId = this.ownerCt.tvId
var address = Ext.getCmp('mapstv'+tvId+'-street').getValue() +' '+ Ext.getCmp('mapstv'+tvId+'-housenumber').getValue() +' '+ Ext.getCmp('mapstv'+tvId+'-zipcode').getValue() +' '+ Ext.getCmp('mapstv'+tvId+'-city').getValue() +' '+ Ext.getCmp('mapstv'+tvId+'-state').getValue() +' '+ Ext.getCmp('mapstv'+tvId+'-country').getValue();
Ext.getCmp('tv'+tvId+'-gmappanel').geoCodeLookup(address, {title: Ext.getCmp('mapstv'+tvId+'-street').getValue() +' '+ Ext.getCmp('mapstv'+tvId+'-housenumber').getValue(), draggable: true}, true, true, {
drag: function(e){
var LatLng = e.latLng;
Ext.getCmp('mapstv'+tvId+'-latitude').setValue(LatLng.$a);
Ext.getCmp('mapstv'+tvId+'-longitude').setValue(LatLng.ab);
Ext.getCmp('mapstv'+tvId+'-latitude').fireEvent('change');
Ext.getCmp('mapstv'+tvId+'-longitude').fireEvent('change');
}
});
}
});
Ext.reg('mapstv-panel',mapsTv.panel);