From 96b597d324aabb93b2cde8ca1566b383bd362d12 Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 28 May 2011 10:15:50 +0200 Subject: [PATCH] make listmap trigger add/remove place events --- source/Ox.UI/js/Map/Ox.ListMap.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/source/Ox.UI/js/Map/Ox.ListMap.js b/source/Ox.UI/js/Map/Ox.ListMap.js index ba575e06..dbc1287f 100644 --- a/source/Ox.UI/js/Map/Ox.ListMap.js +++ b/source/Ox.UI/js/Map/Ox.ListMap.js @@ -407,20 +407,27 @@ Ox.ListMap = function(options, self) { place.countryCode = country ? country.code : ''; self.selectedPlace = self.selectedPlace.substr(1); // fixme: safe? place.id = self.selectedPlace; - self.options.places.push(place); - //self.options.places[Ox.getPositionById(self.options.places, self.selectedPlace)] = place; + if (Ox.isArray(self.options.place)) { + self.options.places.push(place); + self.$list.options({ + items: Ox.clone(self.options.places), + selected: [place.id] + }); + setStatus(); + } self.$map.addPlace(place); - self.$list.options({items: Ox.clone(self.options.places)}); - self.$list.options({selected: [place.id]}); - setStatus(); - self.$placeButton.options({title: 'Remove Place'}) + self.$placeButton.options({title: 'Remove Place'}); + that.triggerEvent('addplace', {place: place}); } else if (title == 'Remove Place') { var index = Ox.getPositionById(self.options.places, self.selectedPlace); - self.options.places.splice(index, 1); - self.$list.options({items: Ox.clone(self.options.places)}); - setStatus(); + if (Ox.isArray(self.options.place)) { + self.options.places.splice(index, 1); + self.$list.options({items: Ox.clone(self.options.places)}); + setStatus(); + } self.$map.removePlace(); self.$placeButton.options({title: 'Add Place'}); + that.triggerEvent('removeplace', {place: place}); } Ox.print('PLACES.LENGTH', self.options.places.length) Ox.print('ITEMS.LENGTH', self.$list.options('items').length)