Development

/plugins/swToolboxPlugin/sf1.2/trunk/lib/widgets/swWidgetFormGMapAddress.class.php

You must first sign up to be able to contribute.

root/plugins/swToolboxPlugin/sf1.2/trunk/lib/widgets/swWidgetFormGMapAddress.class.php

Revision 15932, 4.1 kB (checked in by rande, 2 years ago)

add swWidgetFormGMapAddress

Line 
1 <?php
2 /*
3  *  $Id$
4  *
5  * (c) 2009 Thomas Rabaix <thomas.rabaix@soleoweb.com>
6  *
7  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
8  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
10  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
15  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
16  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
17  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18  *
19  * This software consists of voluntary contributions made by many individuals
20  * and is licensed under the LGPL. For more information, see
21  * <http://www.soleoweb.com>.
22  */
23
24 /**
25  * swWidgetFormGMapAddress represents a gmap address widget
26  *
27  * @package    swToolboxPlugin
28  * @subpackage widget
29  * @author    Thomas Rabaix <thomas.rabaix@soleoweb.com>
30  * @version    SVN: $Id$
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     // generate field id
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     // get the inner form formatter
63     $subFormatter = new swFormatterGMapAddress($this);
64     
65     // render address field
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     // render lng field
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     // render lat field
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     // render the javascript code for the widget
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     // render the html code for the widget
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 }
Note: See TracBrowser for help on using the browser.

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.