1
0
Fork 0
forked from 0x2620/oxjs

some support for adding/removing places

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

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 ??
}