Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Feb 22, 2011
1 parent 745baae commit 7824bf0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
4 changes: 4 additions & 0 deletions gmapsfield/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class GoogleMaps(object):
size = None
zoom = None
markers = None
frozen = None

def __str__(self):
return simplejson.dumps(filter_object(self))
Expand Down Expand Up @@ -56,6 +57,9 @@ def to_python(self, value):
# Markers
if mapdata.get('markers'):
googlemap.markers = mapdata.get('markers')
# Frozen
if mapdata.get('frozen'):
googlemap.frozen = mapdata.get('frozen')

except:
googlemap = ''
Expand Down
55 changes: 36 additions & 19 deletions gmapsfield/templates/admin/admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// {{settings.GMAP_DEFAULT}}
~function(window, document) {
var jQ = jQuery || (django && django.jQuery);

Expand All @@ -13,7 +12,8 @@
size: ["500px", "350px"],
coordinates: {{settings.GMAP_DEFAULT}},
zoom: 8,
markers: []
markers: [],
frozen: false
};

// Replace map with clone
Expand Down Expand Up @@ -79,6 +79,40 @@
clone.val( JSON.stringify(data) );
}

// Used to attach a map to the instance
$(".add-map").bind("click", function() {
var that = $(this),
widget = $("<input class='google-map' type='text' name='"+ that.attr("data-name") +"' value='"+ that.attr("data-value") +"' type='text' />");

that.replaceWith(widget);
widget.trigger("initialize-map");
return false;
});

// Used to remove a map from the instance
$(".remove-map").bind("click", function() {
var that = $(this);
$(".google-map").attr("value", "");

return false;
});

// Used to remove a map from the instance
$(".freeze-map").toggle(
function() {
$(this).text("Unfreeze");
data.frozen = true;

return false;
},
function() {
$(this).text("Freeze");
data.frozen = false;

return false;
}
);

// Center map on marker drop
google.maps.event.addListener(center, "mouseup", update);
// When zoom changed
Expand All @@ -90,23 +124,6 @@
$(this).trigger("initialize-map");
});

// Used to attach a map to the instance
$(".add-map").bind("click", function() {
var that = $(this),
widget = $("<input class='google-map' type='text' name='"+ that.attr("data-name") +"' value='"+ that.attr("data-value") +"' type='text' />");

that.replaceWith(widget);
widget.trigger("initialize-map");
return false;
});

// Used to remove a map from the instance
$(".remove-map").bind("click", function() {
var that = $(this);
$(".google-map").attr("value", "");

return false;
});

});
}(this, this.document);
5 changes: 3 additions & 2 deletions gmapsfield/templates/includes.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
zoom: 8,
size: ["500px", "350px"],
coordinates: [-34.397, 150.644],
markers: []
markers: [],
frozen: false
},
// Merge the loaded values over the defaults
data = $.extend({}, defaults, $.parseJSON(map.attr("data-value")));
Expand All @@ -47,7 +48,7 @@
var center = new google.maps.Marker({
position: coordinates,
map: gmap,
draggable: true,
draggable: data.frozen,
title: "Centered Here"
});
});
Expand Down

0 comments on commit 7824bf0

Please sign in to comment.