validate, places

This commit is contained in:
j 2010-12-06 17:42:05 +00:00
parent 9c34b74621
commit 5d7864e517

View file

@ -1987,23 +1987,23 @@ requires
}); });
$.each(self.options.items, function(i, item) { $.each(self.options.items, function(i, item) {
var id = item.element.options('id');
that.append(self.$items[i] = new Ox.FormItem(item)) that.append(self.$items[i] = new Ox.FormItem(item))
.append(self.$messages[i] = new Ox.Element().addClass('OxFormMessage')); .append(self.$messages[i] = new Ox.Element().addClass('OxFormMessage'));
// fixme: use widget.bindEvent() item.element.bindEvent({
Ox.Event.bind(id, 'validate', function(event, data) { validate: function(event, data) {
validate(i, data.valid); validate(i, data.valid);
}); },
Ox.Event.bind(id, 'blur', function(event, data) { blur: function(event, data) {
validate(i, data.valid); validate(i, data.valid);
if (data.valid) { if (data.valid) {
self.$messages[i].html('').hide(); self.$messages[i].html('').hide();
} else { } else {
self.$messages[i].html(data.message).show(); self.$messages[i].html(data.message).show();
} }
}); },
Ox.Event.bind(id, 'submit', function(event, data) { submit: function(event, data) {
self.formIsValid && that.submit(); self.formIsValid && that.submit();
}
}); });
}); });
@ -4666,15 +4666,13 @@ requires
function findPlace(event, data) { function findPlace(event, data) {
Ox.print('findPlace', data); Ox.print('findPlace', data);
self.$map.find(data.value, function(location) { self.$map.find(data.value, function(place) {
if (location) { place && that.$label.html(place.geoname);
that.$label.html(location.name.formatted);
}
}) })
} }
function onSelect(event, data) { function onSelect(event, data) {
that.$label.html(data.name.formatted); that.$label.html(data.geoname);
} }
function onZoom(event, data) { function onZoom(event, data) {
@ -7292,6 +7290,7 @@ requires
geocoder: new google.maps.Geocoder(), geocoder: new google.maps.Geocoder(),
selected: -1 selected: -1
}); });
if (Ox.isObject(self.options.places[0])) {
$.each(self.options.places, function(i, place) { $.each(self.options.places, function(i, place) {
place.bounds = getBounds(), place.bounds = getBounds(),
place.center = place.bounds.getCenter(); place.center = place.bounds.getCenter();
@ -7308,19 +7307,36 @@ requires
); );
} }
}); });
Ox.print('loadMap'); loadMap();
Ox.print(self.bounds) } else {
self.counter = 0;
$.each(self.options.places, function(i, place) {
getLocationByName(place, function(place) {
Ox.print(self.counter, i, place);
self.options.places[i] = place;
if (self.counter++ == self.options.places.length - 1) {
loadMap();
}
});
});
}
function loadMap() {
self.center = self.bounds ? self.bounds.getCenter() : new google.maps.LatLng(0, 0);
self.zoom = 1;
$.extend(self, { $.extend(self, {
map: new google.maps.Map(that.$element[0], { map: new google.maps.Map(that.$element[0], {
center: self.bounds.getCenter(), center: self.center,
disableDefaultUI: true, disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId[self.options.type.toUpperCase()], mapTypeId: google.maps.MapTypeId[self.options.type.toUpperCase()],
zoom: 0 zoom: self.zoom
}) })
}); });
if (self.bounds) {
self.map.fitBounds(self.bounds); self.map.fitBounds(self.bounds);
self.center = self.map.getCenter(); // self.center = self.map.getCenter();
self.zoom = self.map.getZoom(); self.zoom = self.map.getZoom();
}
google.maps.event.addListener(self.map, 'click', click); google.maps.event.addListener(self.map, 'click', click);
google.maps.event.addListener(self.map, 'zoom_changed', zoomChanged); google.maps.event.addListener(self.map, 'zoom_changed', zoomChanged);
$.each(self.options.places, function(i, place) { $.each(self.options.places, function(i, place) {
@ -7328,6 +7344,8 @@ requires
}); });
resize(); resize();
that.gainFocus(); that.gainFocus();
}
function canContain(outerBounds, innerBounds) { function canContain(outerBounds, innerBounds) {
var outerSpan = outerBounds.toSpan(), var outerSpan = outerBounds.toSpan(),
@ -7602,7 +7620,7 @@ requires
}; };
} }
function Rectangle(area) { function Rectangle(area) { // fixme: not used
var latlng = { var latlng = {
sw: new google.maps.LatLng(area[0][0], area[0][1]), sw: new google.maps.LatLng(area[0][0], area[0][1]),
ne: new google.maps.LatLng(area[1][0], area[1][1]) ne: new google.maps.LatLng(area[1][0], area[1][1])
@ -7648,15 +7666,15 @@ requires
}; };
that.find = function(name, callback) { that.find = function(name, callback) {
getLocationByName(name, function(location) { getLocationByName(name, function(place) {
if (location) { if (place) {
//self.marker = location.marker.add(); //self.marker = location.marker.add();
self.polygon && self.polygon.remove(); self.polygon && self.polygon.remove();
self.polygon = location.polygon.add(); self.polygon = place.polygon.add();
self.bounds = location.bounds; self.bounds = place.bounds;
self.map.fitBounds(self.bounds); self.map.fitBounds(self.bounds);
} }
callback(location); callback(place);
}); });
}; };