| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
class swWidgetFormGMapAddress extends sfWidgetFormSchema |
|---|
| 33 |
{ |
|---|
| 34 |
public function __construct($fields = null, $options = array(), $attributes = array(), $labels = array(), $helps = array()) |
|---|
| 35 |
{ |
|---|
| 36 |
$fields = array( |
|---|
| 37 |
'address' => new sfWidgetFormInput(array(), array('style' => 'width: 300px;')), |
|---|
| 38 |
'lat' => new sfWidgetFormInput(array(), array('readonly' => true)), |
|---|
| 39 |
'lng' => new sfWidgetFormInput(array(), array('readonly' => true)), |
|---|
| 40 |
); |
|---|
| 41 |
|
|---|
| 42 |
parent::__construct($fields, $options, $attributes, $labels, $helps); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
public function getJavascripts() |
|---|
| 46 |
{ |
|---|
| 47 |
return array( |
|---|
| 48 |
'/swToolboxPlugin/js/swGmapWidget.js' |
|---|
| 49 |
); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
public function render($name, $value = null, $attributes = array(), $errors = array()) |
|---|
| 53 |
{ |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
$lat_id = $this->generateId($name.'[lat]'); |
|---|
| 57 |
$lng_id = $this->generateId($name.'[lng]'); |
|---|
| 58 |
$address_id = $this->generateId($name.'[address]'); |
|---|
| 59 |
$map_id = $this->generateId($name.'[map]'); |
|---|
| 60 |
$lookup_id = $this->generateId($name.'[lookup]'); |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
$subFormatter = new swFormatterGMapAddress($this); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
$address_field = $subFormatter->formatRow( |
|---|
| 67 |
$subFormatter->generateLabel('address'), |
|---|
| 68 |
$this->renderField('address', $value['address'], $attributes, array()), |
|---|
| 69 |
isset($errors['address']) ? $errors['address'] : array(), |
|---|
| 70 |
$this->getHelp($name) |
|---|
| 71 |
); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
$lng_field = $subFormatter->formatRow( |
|---|
| 75 |
$subFormatter->generateLabel('lng'), |
|---|
| 76 |
$this->renderField('lng', $value['lng'], $attributes, array()), |
|---|
| 77 |
isset($errors['lng']) ? $errors['lng'] : array(), |
|---|
| 78 |
$this->getHelp($name) |
|---|
| 79 |
); |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
$lat_field = $subFormatter->formatRow( |
|---|
| 83 |
$subFormatter->generateLabel('lat'), |
|---|
| 84 |
$this->renderField('lat', $value['lat'], $attributes, array()), |
|---|
| 85 |
isset($errors['lat']) ? $errors['lat'] : array(), |
|---|
| 86 |
$this->getHelp($name) |
|---|
| 87 |
); |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
$javascript = sprintf( |
|---|
| 91 |
' |
|---|
| 92 |
<script> |
|---|
| 93 |
jQuery(window).bind("load", function() { |
|---|
| 94 |
new swGmapWidget({ |
|---|
| 95 |
lng: "%s", |
|---|
| 96 |
lat: "%s", |
|---|
| 97 |
address: "%s", |
|---|
| 98 |
lookup: "%s", |
|---|
| 99 |
map: "%s" |
|---|
| 100 |
}); |
|---|
| 101 |
}) |
|---|
| 102 |
</script> |
|---|
| 103 |
', |
|---|
| 104 |
$lng_id, |
|---|
| 105 |
$lat_id, |
|---|
| 106 |
$address_id, |
|---|
| 107 |
$lookup_id, |
|---|
| 108 |
$map_id |
|---|
| 109 |
); |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
$html = sprintf(' |
|---|
| 113 |
<div id="%s" class="sw-gmap-widget"> |
|---|
| 114 |
%s <input type="submit" value="lookup address" id="%s" /> <br /> |
|---|
| 115 |
%s - %s <br /> |
|---|
| 116 |
<div id="%s" style="width: 500px; height: 300px"></div> |
|---|
| 117 |
</div>', |
|---|
| 118 |
$this->generateId($name), |
|---|
| 119 |
$address_field, |
|---|
| 120 |
$lookup_id, |
|---|
| 121 |
$lat_field, |
|---|
| 122 |
$lng_field, |
|---|
| 123 |
$map_id |
|---|
| 124 |
); |
|---|
| 125 |
|
|---|
| 126 |
return $html.$javascript; |
|---|
| 127 |
|
|---|
| 128 |
} |
|---|
| 129 |
} |
|---|