listmap bugfixes

This commit is contained in:
rolux 2011-05-24 18:08:52 +02:00
parent 314fcc7b0a
commit 9967d31396
2 changed files with 21 additions and 10 deletions

View file

@ -1080,6 +1080,7 @@ Ox.List = function(options, self) {
function setSelected(ids) { function setSelected(ids) {
// fixme: can't use selectNone here, // fixme: can't use selectNone here,
// since it'd trigger a select event // since it'd trigger a select event
Ox.print('setSelected', ids)
self.$items.forEach(function($item, pos) { self.$items.forEach(function($item, pos) {
if (isSelected(pos)) { if (isSelected(pos)) {
self.selected.splice(self.selected.indexOf(pos), 1); self.selected.splice(self.selected.indexOf(pos), 1);
@ -1089,6 +1090,7 @@ Ox.List = function(options, self) {
}); });
ids.forEach(function(id, i) { ids.forEach(function(id, i) {
var pos = getPositionById(id); var pos = getPositionById(id);
Ox.print('pushing', pos, 'onto self.selected')
self.selected.push(pos); self.selected.push(pos);
!Ox.isUndefined(self.$items[pos]) && !Ox.isUndefined(self.$items[pos]) &&
self.$items[pos].addClass('OxSelected'); self.$items[pos].addClass('OxSelected');
@ -1217,6 +1219,7 @@ Ox.List = function(options, self) {
} }
function updateSelected() { function updateSelected() {
Ox.print('updateSelected')
var oldSelectedIds = getSelectedIds(), var oldSelectedIds = getSelectedIds(),
newSelectedIds = []; newSelectedIds = [];
Ox.forEach(self.options.items, function(item) { Ox.forEach(self.options.items, function(item) {

View file

@ -38,8 +38,10 @@ Ox.ListMap = function(options, self) {
{ {
addable: false, // fixme: implement addable: false, // fixme: implement
id: 'id', id: 'id',
title: 'Id',
unique: true, unique: true,
visible: false visible: false,
width: 64
}, },
{ {
format: function(value) { format: function(value) {
@ -301,8 +303,9 @@ Ox.ListMap = function(options, self) {
width: 240 width: 240
}).bindEvent({ }).bindEvent({
change: function(data) { change: function(data) {
var isResult = self.selectedPlace[0] == '_';
Ox.getObjectById(self.options.places, self.selectedPlace).name = data.value; Ox.getObjectById(self.options.places, self.selectedPlace).name = data.value;
self.$list.value(self.selectedPlace, 'name', data.value); !isResult && self.$list.value(self.selectedPlace, 'name', data.value);
self.$map.value(self.selectedPlace, 'name', data.value); self.$map.value(self.selectedPlace, 'name', data.value);
} }
}), }),
@ -313,12 +316,17 @@ Ox.ListMap = function(options, self) {
width: 240 width: 240
}).bindEvent({ }).bindEvent({
change: function(data) { change: function(data) {
Ox.getObjectById(self.options.places, self.selectedPlace).geoname = data.value; var geoname = data.value,
self.$list.value(self.selectedPlace, 'geoname', data.value); country = Ox.getCountryByGeoname(geoname),
self.$map.value(self.selectedPlace, 'geoname', data.value); countryCode = country ? country.code : 'NTHH',
self.$placeTitleName.options({ isResult = self.selectedPlace[0] == '_';
title: data.value //Ox.getObjectById(self.options.places, self.selectedPlace).geoname = geoname;
!isResult && self.$list.value(self.selectedPlace, 'geoname', geoname);
//self.$map.value(self.selectedPlace, 'geoname', geoname);
self.$placeTitleFlag.attr({
src: Ox.PATH + 'Ox.Geo/png/icons/16/' + countryCode + '.png'
}); });
self.$placeTitleName.options({title: geoname});
} }
}), }),
Ox.ArrayInput({ Ox.ArrayInput({
@ -384,6 +392,7 @@ Ox.ListMap = function(options, self) {
.bindEvent({ .bindEvent({
click: function() { click: function() {
var title = self.$placeButton.options('title'); var title = self.$placeButton.options('title');
// fixme: these should be separate functions
if (title == 'New Place') { if (title == 'New Place') {
self.$map.newPlace(); self.$map.newPlace();
self.$placeButton.options({title: 'Add Place'}) self.$placeButton.options({title: 'Add Place'})
@ -393,11 +402,10 @@ Ox.ListMap = function(options, self) {
place.countryCode = country ? country.code : ''; place.countryCode = country ? country.code : '';
place.id = self.selectedPlace.substr(1); // fixme: safe? place.id = self.selectedPlace.substr(1); // fixme: safe?
self.options.places.push(place); self.options.places.push(place);
//self.options.places[Ox.getPositionById(self.options.places, self.selectedPlace)] = place;
self.$map.addPlace(place); self.$map.addPlace(place);
//self.$placeButton.options({title: 'Please Wait...'})
self.$list.options({items: Ox.clone(self.options.places)}); self.$list.options({items: Ox.clone(self.options.places)});
self.$list.options({selected: [place.id]}); self.$list.options({selected: [place.id]});
//self.$list.addItem(place);
self.$placeButton.options({title: 'Remove Place'}) self.$placeButton.options({title: 'Remove Place'})
} else if (title == 'Remove Place') { } else if (title == 'Remove Place') {
var index = Ox.getPositionById(self.options.places, self.selectedPlace); var index = Ox.getPositionById(self.options.places, self.selectedPlace);
@ -567,6 +575,7 @@ Ox.ListMap = function(options, self) {
code = country ? country.code : 'NTHH'; code = country ? country.code : 'NTHH';
if (place.id) { if (place.id) {
isResult = place.id[0] == '_'; isResult = place.id[0] == '_';
//isResult && self.options.places.push(place);
self.selectedPlace = place.id; self.selectedPlace = place.id;
place.id[0] != '_' && self.$list.options({ place.id[0] != '_' && self.$list.options({
selected: place.id ? [place.id] : [] selected: place.id ? [place.id] : []
@ -576,7 +585,6 @@ Ox.ListMap = function(options, self) {
}); });
self.$placeTitleName.options({title: place.geoname || ''}); self.$placeTitleName.options({title: place.geoname || ''});
self.$placeTitle.show(); self.$placeTitle.show();
Ox.print('>>>>', place)
self.$placeForm.values(Ox.map(place, function(val, key) { self.$placeForm.values(Ox.map(place, function(val, key) {
return key == 'size' ? Ox.formatArea(val) : val; return key == 'size' ? Ox.formatArea(val) : val;
})).show(); })).show();