Map Editor: correctly set self.options.selected when adding or removing a place (fixes #990)

This commit is contained in:
rlx 2012-09-21 09:53:05 +00:00
parent a392cad0bc
commit 609d1355fe

View file

@ -789,9 +789,11 @@ Ox.MapEditor = function(options, self) {
if (!self.isAsync) { if (!self.isAsync) {
place.id = self.selectedPlace.slice(1); // fixme: safe? place.id = self.selectedPlace.slice(1); // fixme: safe?
self.selectedPlace = place.id; self.selectedPlace = place.id;
self.options.selected = place.id;
self.options.places.push(place); self.options.places.push(place);
self.$list.options({ self.$list.options({
items: Ox.clone(self.options.places), items: Ox.clone(self.options.places)
}).options({
selected: [place.id] selected: [place.id]
}); });
self.$map.addPlace(place); self.$map.addPlace(place);
@ -802,6 +804,7 @@ Ox.MapEditor = function(options, self) {
self.options.addPlace(encodeValues(place), function(result) { self.options.addPlace(encodeValues(place), function(result) {
if (result.status.code == 200) { if (result.status.code == 200) {
place.id = result.data.id; place.id = result.data.id;
self.options.selected = place.id;
self.selectedPlace = place.id; self.selectedPlace = place.id;
self.$list.reloadList().options({selected: [place.id]}); self.$list.reloadList().options({selected: [place.id]});
self.$map.addPlace(place); self.$map.addPlace(place);
@ -973,6 +976,7 @@ Ox.MapEditor = function(options, self) {
if (!self.isAsync) { if (!self.isAsync) {
// fixme: doesn't call self.options.removePlace! // fixme: doesn't call self.options.removePlace!
index = Ox.getIndexById(self.options.places, self.selectedPlace); index = Ox.getIndexById(self.options.places, self.selectedPlace);
self.options.selected = '';
self.options.places.splice(index, 1); self.options.places.splice(index, 1);
self.$list.options({items: Ox.clone(self.options.places)}); self.$list.options({items: Ox.clone(self.options.places)});
self.$addPlaceButton.options({title: 'Add Place'}); self.$addPlaceButton.options({title: 'Add Place'});
@ -982,6 +986,7 @@ Ox.MapEditor = function(options, self) {
if (self.isAsync) { if (self.isAsync) {
self.$addPlaceButton.options({disabled: true, title: 'Removing...'}) self.$addPlaceButton.options({disabled: true, title: 'Removing...'})
self.options.removePlace({id: self.selectedPlace}, function() { self.options.removePlace({id: self.selectedPlace}, function() {
self.options.selected = '';
self.$list.options({selected: []}).reloadList(true); self.$list.options({selected: []}).reloadList(true);
self.options.hasMatches && self.$matchesInput.hide(); self.options.hasMatches && self.$matchesInput.hide();
self.options.mode == 'define' && self.$definePlaceButton.options({ self.options.mode == 'define' && self.$definePlaceButton.options({
@ -1042,6 +1047,7 @@ Ox.MapEditor = function(options, self) {
&& !self.$list.value(self.options.selected, 'type'); && !self.$list.value(self.options.selected, 'type');
self.selectedPlace = place.id || ''; self.selectedPlace = place.id || '';
if (isResult && isUndefined) { if (isResult && isUndefined) {
Ox.print('place.id', place.id, 'self.options.selected', self.options.selected, 'type', self.$list.value(self.options.selected));
// define undefined place // define undefined place
self.selectedPlace = self.options.selected; self.selectedPlace = self.options.selected;
place.name = self.$list.value(self.options.selected, 'name'); place.name = self.$list.value(self.options.selected, 'name');