Package madrona :: Package bookmarks :: Module widgets
[hide private]

Source Code for Module madrona.bookmarks.widgets

 1  from django import forms 
 2  from django.utils.safestring import mark_safe 
 3  from django.forms.util import flatatt 
 4  from django.conf import settings 
 5  from django.contrib.gis.geos import fromstr 
 6   
 7   
8 -class BookmarkWidget(forms.TextInput):
9 - def __init__(self, title='Point', attrs=None):
10 super(BookmarkWidget, self).__init__(attrs) 11 self.title = title
12
13 - def render(self, name, value, attrs=None):
14 output = super(SimplePoint, self).render(name, value, attrs) 15 set_text = "Set" 16 new_text = "New" 17 if value: 18 geo = fromstr(value) 19 set_text = "Reset" 20 new_text = "Reset" 21 return mark_safe(""" 22 <div> 23 <a id="do_grabpoint" class="button" href="#"> 24 <span>Click to %s Starting Point</span> 25 </a> 26 <span style="display:none"> 27 %s 28 </span> 29 </div> 30 <br/><br/> 31 <script type="text/javascript"> 32 var shape; 33 34 madrona.beforeDestroy( function() { 35 if(shape && shape.getParentNode()){ 36 gex.dom.removeObject(shape); 37 } 38 }); 39 40 madrona.onShow( function() { 41 function shape_to_wkt(shape) { 42 var lat = shape.getGeometry().getLatitude(); 43 var lon = shape.getGeometry().getLongitude(); 44 var wkt = "SRID=4326;POINT(" + lon + " " + lat + ")"; 45 return wkt; 46 } 47 48 $('#do_grabpoint').click( function () { 49 if(!$(this).hasClass('disabled')){ 50 if(shape && shape.getParentNode()){ 51 gex.dom.removeObject(shape); 52 } 53 $(this).addClass('disabled'); 54 var button = $(this); 55 button.html('<span>Click map to set placemark</span>'); 56 57 var popts = { 58 visibility: true, 59 name: '%s %s', 60 style: { icon: { color: '#FF0' } } 61 } 62 popts['point'] = [0,0]; 63 shape = gex.dom.addPlacemark(popts); 64 gex.edit.place(shape, { 65 bounce: false, 66 dropCallback: function(){ 67 $('#id_%s').val(shape_to_wkt(shape)); 68 button.html('<span>Drag Placemark to Reset</span>'); 69 gex.edit.makeDraggable(shape, { 70 bounce: false, 71 dropCallback: function () { 72 $('#id_%s').val(shape_to_wkt(shape)); 73 } 74 }); 75 } 76 }); 77 } 78 }); 79 }); 80 </script> 81 """ % (set_text,output,new_text,self.title,name,name))
82