in MapEditor, update number of matches when editing name and alternative names of result places (fixes #824)

This commit is contained in:
rlx 2012-06-10 09:06:02 +00:00
parent 806cbd1557
commit 4625b4ac36

View file

@ -561,15 +561,19 @@ Ox.MapEditor = function(options, self) {
Ox.getObjectById( Ox.getObjectById(
self.options.places, self.selectedPlace self.options.places, self.selectedPlace
).name = name; ).name = name;
} else if (isResult) {
getMatches(this.values());
} else { } else {
!isResult && editPlace(['name']); editPlace(['name']);
} }
self.$map.value(self.selectedPlace, 'name', name); self.$map.value(self.selectedPlace, 'name', name);
} else if (data.id == 'alternativeNames') { } else if (data.id == 'alternativeNames') {
if (!self.isAsync) { if (!self.isAsync) {
// ... // ...
} else if (isResult) {
getMatches(this.values());
} else { } else {
!isResult && editPlace(['alternativeNames']) editPlace(['alternativeNames']);
} }
self.$map.value(self.selectedPlace, 'alternativeNames', data.data.value); self.$map.value(self.selectedPlace, 'alternativeNames', data.data.value);
} else if (data.id == 'geoname') { } else if (data.id == 'geoname') {
@ -604,7 +608,7 @@ Ox.MapEditor = function(options, self) {
!isResult && editPlace([data.id]); !isResult && editPlace([data.id]);
} }
self.$map.value(self.selectedPlace, data.id, parseFloat(data.data.value)); self.$map.value(self.selectedPlace, data.id, parseFloat(data.data.value));
} }
} }
}) })
.appendTo(self.$placeData); .appendTo(self.$placeData);
@ -932,6 +936,18 @@ Ox.MapEditor = function(options, self) {
self.$areaKmInput.hide(); self.$areaKmInput.hide();
} }
function getMatches(place) {
var names;
if (self.options.hasMatches) {
names = Ox.filter([place.name].concat(place.alternativeNames), function(name) {
return name !== '';
});
self.options.getMatches(names, function(matches) {
self.$matchesInput.value(matches);
});
}
}
function initList(data) { function initList(data) {
self.$status.html( self.$status.html(
Ox.formatNumber(data.items) + ' Place' + ( Ox.formatNumber(data.items) + ' Place' + (
@ -1025,8 +1041,7 @@ Ox.MapEditor = function(options, self) {
Ox.Log('Map', 'selectPlace', place) Ox.Log('Map', 'selectPlace', place)
var isResult = !!place.id && place.id[0] == '_', var isResult = !!place.id && place.id[0] == '_',
isUndefined = !!self.options.selected isUndefined = !!self.options.selected
&& !self.$list.value(self.options.selected, 'type'), && !self.$list.value(self.options.selected, 'type');
names;
self.selectedPlace = place.id || ''; self.selectedPlace = place.id || '';
if (isResult && isUndefined) { if (isResult && isUndefined) {
// define undefined place // define undefined place
@ -1055,12 +1070,7 @@ Ox.MapEditor = function(options, self) {
showForm(place); showForm(place);
if (self.options.hasMatches) { if (self.options.hasMatches) {
self.$matchesInput.value('').show(); self.$matchesInput.value('').show();
names = Ox.filter([place.name].concat(place.alternativeNames), function(name) { getMatches(place);
return name !== '';
});
self.options.getMatches(names, function(matches) {
self.$matchesInput.value(matches);
});
} }
self.options.mode == 'define' && self.$definePlaceButton.hide(); self.options.mode == 'define' && self.$definePlaceButton.hide();
self.$addPlaceButton.options({disabled: false, title: 'Add Place'}).show(); self.$addPlaceButton.options({disabled: false, title: 'Add Place'}).show();