some support for adding/removing places

This commit is contained in:
rolux 2011-05-29 17:09:42 +02:00
parent 6229b16a59
commit ccc4a743d8
4 changed files with 76 additions and 44 deletions

View file

@ -1,5 +1,7 @@
Ox.load('UI', {
debug: true,
hideScreen: true,
showScreen: true,
theme: 'modern'
}, function() {
@ -135,9 +137,19 @@ Ox.load('Geo', function() {
width: window.innerWidth
})
.bindEvent({
addplace: function(data) {
Ox.print('addplace', data);
places.push(Ox.extend(data.place, {
geonameSort: getGeonameSort(data.place.geoname)
}));
},
geocode: function(event, data) {
Ox.print(event)
Ox.print(JSON.stringify(data))
},
removeplace: function(data) {
var i = Ox.getPositionById(places, data.id);
places.splice(i, 1);
}
})
.appendTo(Ox.UI.$body);

View file

@ -1213,6 +1213,7 @@ Ox.List = function(options, self) {
clear();
self.requests.push(self.options.items({}, function(result) {
var keys = {};
Ox.print('INIT!!!', result.data)
that.triggerEvent('init', result.data);
self.rowLength = getRowLength();
self.pageLength = self.options.orientation == 'both' ?
@ -1320,7 +1321,7 @@ Ox.List = function(options, self) {
addItems <f> add item to list
(pos, items) -> <u> add items to list at position
pos <n> position to add items
items <a> array of items ot add
items <a> array of items to add
@*/
that.addItems = function(pos, items) {
var $items = [],

View file

@ -201,10 +201,16 @@ Ox.TextList = function(options, self) {
}
})
.bindEvent({
edit: function(event, data) {
edit: function(data) {
that.editCell(data.id, data.key);
},
select: function(event, data) {
init: function(data) {
// fixme: why does this never reach?
//Ox.print('INIT????')
//that.triggerEvent('init', data);
},
select: function(data) {
Ox.print('SELECT????')
self.options.selected = data.ids;
}
})
@ -702,8 +708,10 @@ Ox.TextList = function(options, self) {
}
};
// fixme: doesn't work, doesn't return that
that.closePreview = that.$body.closePreview;
that.closePreview = function() {
that.$body.closePreview();
return that;
};
that.addItem = function(item) {
/*

View file

@ -6,7 +6,6 @@ Ox.ListMap <f:Ox.Element> ListMap Object
(options) -> <f> ListMap Object
(options, self) -> <f> ListMap Object
options <o> Options object
addPlace <f|null>
height <n|256>
labels <b|false>
places <f|null>
@ -20,7 +19,6 @@ Ox.ListMap = function(options, self) {
var self = self || {},
that = Ox.Element({}, self)
.defaults({
addPlace: null,
height: 256,
labels: false,
pageLength: 100,
@ -294,9 +292,11 @@ Ox.ListMap = function(options, self) {
zoombar: true
})
.bindEvent({
/*
addplace: function(event, data) {
that.triggerEvent('addplace', data);
},
*/
changeplace: function(event, data) {
self.$placeForm.values(Ox.map(data, function(val, key) {
// fixme: no size key anymore
@ -437,35 +437,10 @@ Ox.ListMap = function(options, self) {
self.$map.newPlace();
self.$placeButton.options({title: 'Add Place'})
} else if (title == 'Add Place') {
var place = self.$placeForm.values(),
country = Ox.getCountryByGeoname(place.geoname);
place.countryCode = country ? country.code : '';
self.selectedPlace = self.selectedPlace.substr(1); // fixme: safe?
place.id = self.selectedPlace;
//if (Ox.isArray(self.options.places)) {
self.options.places.push(place);
self.$list.options({
items: Ox.clone(self.options.places),
selected: [place.id]
});
setStatus();
//}
self.$map.addPlace(place);
self.$placeButton.options({title: 'Remove Place'});
that.triggerEvent('addplace', {place: place});
addPlace();
} else if (title == 'Remove Place') {
var index = Ox.getPositionById(self.options.places, self.selectedPlace);
//if (Ox.isArray(self.options.places)) {
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});
removePlace();
}
Ox.print('PLACES.LENGTH', self.options.places.length)
Ox.print('ITEMS.LENGTH', self.$list.options('items').length)
}
})
.appendTo(self.$placeStatusbar);
@ -486,6 +461,7 @@ Ox.ListMap = function(options, self) {
];
*/
/*
if (!self.isAsync) {
self.placesLength = self.options.places.length;
setStatus();
@ -495,6 +471,7 @@ Ox.ListMap = function(options, self) {
setStatus();
});
}
*/
that.$element.replaceWith(
that.$element = Ox.SplitPanel({
@ -559,8 +536,50 @@ Ox.ListMap = function(options, self) {
}).$element
);
function initList(event, data) {
self.$status.html(data.items + ' place' + (data.items == 1 ? '' : 's'))
function addPlace() {
var place = self.$placeForm.values(),
country = Ox.getCountryByGeoname(place.geoname);
place.countryCode = country ? country.code : '';
self.selectedPlace = self.selectedPlace.substr(1); // fixme: safe?
place.id = self.selectedPlace;
if (!self.isAsync) {
self.options.places.push(place);
self.$list.options({
items: Ox.clone(self.options.places),
selected: [place.id]
});
//setStatus();
}
self.$map.addPlace(place);
self.$placeButton.options({title: 'Remove Place'});
that.triggerEvent('addplace', {place: place});
if (self.isAsync) {
self.$list.reloadList().options({selected: [place.id]});
}
}
function removePlace() {
var index = Ox.getPositionById(self.options.places, self.selectedPlace);
if (!self.isAsync) {
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', {id: self.selectedPlace});
if (self.isAsync) {
self.$list.options({selected: []}).reloadList();
}
}
function initList(data) {
self.$status.html(
Ox.formatNumber(data.items) + ' Place' + (
data.items == 1 ? '' : 's'
)
);
}
function openItem(event, data) {
@ -608,14 +627,6 @@ Ox.ListMap = function(options, self) {
}
}
function setStatus() {
self.$status.html(
Ox.formatNumber(self.placesLength) + ' Place' + (
self.placesLength == 1 ? '' : 's'
)
);
}
function toFixed(val) {
return Ox.isNumber(val) ? val.toFixed(8) : val; // fixme: why can a string be passed ??
}