validate, places

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

View file

@ -1987,24 +1987,24 @@ 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();
}); }
});
}); });
function getItemPositionById(id) { function getItemPositionById(id) {
@ -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,42 +7290,62 @@ requires
geocoder: new google.maps.Geocoder(), geocoder: new google.maps.Geocoder(),
selected: -1 selected: -1
}); });
$.each(self.options.places, function(i, place) { if (Ox.isObject(self.options.places[0])) {
place.bounds = getBounds(), $.each(self.options.places, function(i, place) {
place.center = place.bounds.getCenter(); place.bounds = getBounds(),
$.extend(place, { place.center = place.bounds.getCenter();
marker: new Marker(place), $.extend(place, {
polygon: new Polygon(place) marker: new Marker(place),
polygon: new Polygon(place)
});
self.bounds = i == 0 ? getBounds() : self.bounds.union(place.bounds);
self.options.places[i] = place;
function getBounds() {
return new google.maps.LatLngBounds(
new google.maps.LatLng(place.points.southwest[0], place.points.southwest[1]),
new google.maps.LatLng(place.points.northeast[0], place.points.northeast[1])
);
}
});
loadMap();
} 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();
}
});
}); });
self.bounds = i == 0 ? getBounds() : self.bounds.union(place.bounds); }
self.options.places[i] = place;
function getBounds() { function loadMap() {
return new google.maps.LatLngBounds( self.center = self.bounds ? self.bounds.getCenter() : new google.maps.LatLng(0, 0);
new google.maps.LatLng(place.points.southwest[0], place.points.southwest[1]), self.zoom = 1;
new google.maps.LatLng(place.points.northeast[0], place.points.northeast[1]) $.extend(self, {
); map: new google.maps.Map(that.$element[0], {
center: self.center,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId[self.options.type.toUpperCase()],
zoom: self.zoom
})
});
if (self.bounds) {
self.map.fitBounds(self.bounds);
// self.center = self.map.getCenter();
self.zoom = self.map.getZoom();
} }
}); google.maps.event.addListener(self.map, 'click', click);
Ox.print('loadMap'); google.maps.event.addListener(self.map, 'zoom_changed', zoomChanged);
Ox.print(self.bounds) $.each(self.options.places, function(i, place) {
$.extend(self, { place.marker.add();
map: new google.maps.Map(that.$element[0], { });
center: self.bounds.getCenter(), resize();
disableDefaultUI: true, that.gainFocus();
mapTypeId: google.maps.MapTypeId[self.options.type.toUpperCase()], }
zoom: 0
})
});
self.map.fitBounds(self.bounds);
self.center = self.map.getCenter();
self.zoom = self.map.getZoom();
google.maps.event.addListener(self.map, 'click', click);
google.maps.event.addListener(self.map, 'zoom_changed', zoomChanged);
$.each(self.options.places, function(i, place) {
place.marker.add();
});
resize();
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);
}); });
}; };