some support for adding/removing places
This commit is contained in:
parent
6229b16a59
commit
ccc4a743d8
4 changed files with 76 additions and 44 deletions
|
@ -1,5 +1,7 @@
|
||||||
Ox.load('UI', {
|
Ox.load('UI', {
|
||||||
debug: true,
|
debug: true,
|
||||||
|
hideScreen: true,
|
||||||
|
showScreen: true,
|
||||||
theme: 'modern'
|
theme: 'modern'
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|
||||||
|
@ -135,9 +137,19 @@ Ox.load('Geo', function() {
|
||||||
width: window.innerWidth
|
width: window.innerWidth
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
|
addplace: function(data) {
|
||||||
|
Ox.print('addplace', data);
|
||||||
|
places.push(Ox.extend(data.place, {
|
||||||
|
geonameSort: getGeonameSort(data.place.geoname)
|
||||||
|
}));
|
||||||
|
},
|
||||||
geocode: function(event, data) {
|
geocode: function(event, data) {
|
||||||
Ox.print(event)
|
Ox.print(event)
|
||||||
Ox.print(JSON.stringify(data))
|
Ox.print(JSON.stringify(data))
|
||||||
|
},
|
||||||
|
removeplace: function(data) {
|
||||||
|
var i = Ox.getPositionById(places, data.id);
|
||||||
|
places.splice(i, 1);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.appendTo(Ox.UI.$body);
|
.appendTo(Ox.UI.$body);
|
||||||
|
|
|
@ -1213,6 +1213,7 @@ Ox.List = function(options, self) {
|
||||||
clear();
|
clear();
|
||||||
self.requests.push(self.options.items({}, function(result) {
|
self.requests.push(self.options.items({}, function(result) {
|
||||||
var keys = {};
|
var keys = {};
|
||||||
|
Ox.print('INIT!!!', result.data)
|
||||||
that.triggerEvent('init', result.data);
|
that.triggerEvent('init', result.data);
|
||||||
self.rowLength = getRowLength();
|
self.rowLength = getRowLength();
|
||||||
self.pageLength = self.options.orientation == 'both' ?
|
self.pageLength = self.options.orientation == 'both' ?
|
||||||
|
@ -1320,7 +1321,7 @@ Ox.List = function(options, self) {
|
||||||
addItems <f> add item to list
|
addItems <f> add item to list
|
||||||
(pos, items) -> <u> add items to list at position
|
(pos, items) -> <u> add items to list at position
|
||||||
pos <n> position to add items
|
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) {
|
that.addItems = function(pos, items) {
|
||||||
var $items = [],
|
var $items = [],
|
||||||
|
|
|
@ -201,10 +201,16 @@ Ox.TextList = function(options, self) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
edit: function(event, data) {
|
edit: function(data) {
|
||||||
that.editCell(data.id, data.key);
|
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;
|
self.options.selected = data.ids;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -702,8 +708,10 @@ Ox.TextList = function(options, self) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// fixme: doesn't work, doesn't return that
|
that.closePreview = function() {
|
||||||
that.closePreview = that.$body.closePreview;
|
that.$body.closePreview();
|
||||||
|
return that;
|
||||||
|
};
|
||||||
|
|
||||||
that.addItem = function(item) {
|
that.addItem = function(item) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -6,7 +6,6 @@ Ox.ListMap <f:Ox.Element> ListMap Object
|
||||||
(options) -> <f> ListMap Object
|
(options) -> <f> ListMap Object
|
||||||
(options, self) -> <f> ListMap Object
|
(options, self) -> <f> ListMap Object
|
||||||
options <o> Options object
|
options <o> Options object
|
||||||
addPlace <f|null>
|
|
||||||
height <n|256>
|
height <n|256>
|
||||||
labels <b|false>
|
labels <b|false>
|
||||||
places <f|null>
|
places <f|null>
|
||||||
|
@ -20,7 +19,6 @@ Ox.ListMap = function(options, self) {
|
||||||
var self = self || {},
|
var self = self || {},
|
||||||
that = Ox.Element({}, self)
|
that = Ox.Element({}, self)
|
||||||
.defaults({
|
.defaults({
|
||||||
addPlace: null,
|
|
||||||
height: 256,
|
height: 256,
|
||||||
labels: false,
|
labels: false,
|
||||||
pageLength: 100,
|
pageLength: 100,
|
||||||
|
@ -294,9 +292,11 @@ Ox.ListMap = function(options, self) {
|
||||||
zoombar: true
|
zoombar: true
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
|
/*
|
||||||
addplace: function(event, data) {
|
addplace: function(event, data) {
|
||||||
that.triggerEvent('addplace', data);
|
that.triggerEvent('addplace', data);
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
changeplace: function(event, data) {
|
changeplace: function(event, data) {
|
||||||
self.$placeForm.values(Ox.map(data, function(val, key) {
|
self.$placeForm.values(Ox.map(data, function(val, key) {
|
||||||
// fixme: no size key anymore
|
// fixme: no size key anymore
|
||||||
|
@ -437,35 +437,10 @@ Ox.ListMap = function(options, self) {
|
||||||
self.$map.newPlace();
|
self.$map.newPlace();
|
||||||
self.$placeButton.options({title: 'Add Place'})
|
self.$placeButton.options({title: 'Add Place'})
|
||||||
} else if (title == 'Add Place') {
|
} else if (title == 'Add Place') {
|
||||||
var place = self.$placeForm.values(),
|
addPlace();
|
||||||
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});
|
|
||||||
} else if (title == 'Remove Place') {
|
} else if (title == 'Remove Place') {
|
||||||
var index = Ox.getPositionById(self.options.places, self.selectedPlace);
|
removePlace();
|
||||||
//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});
|
|
||||||
}
|
}
|
||||||
Ox.print('PLACES.LENGTH', self.options.places.length)
|
|
||||||
Ox.print('ITEMS.LENGTH', self.$list.options('items').length)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.appendTo(self.$placeStatusbar);
|
.appendTo(self.$placeStatusbar);
|
||||||
|
@ -486,6 +461,7 @@ Ox.ListMap = function(options, self) {
|
||||||
];
|
];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
if (!self.isAsync) {
|
if (!self.isAsync) {
|
||||||
self.placesLength = self.options.places.length;
|
self.placesLength = self.options.places.length;
|
||||||
setStatus();
|
setStatus();
|
||||||
|
@ -495,6 +471,7 @@ Ox.ListMap = function(options, self) {
|
||||||
setStatus();
|
setStatus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
that.$element.replaceWith(
|
that.$element.replaceWith(
|
||||||
that.$element = Ox.SplitPanel({
|
that.$element = Ox.SplitPanel({
|
||||||
|
@ -559,8 +536,50 @@ Ox.ListMap = function(options, self) {
|
||||||
}).$element
|
}).$element
|
||||||
);
|
);
|
||||||
|
|
||||||
function initList(event, data) {
|
function addPlace() {
|
||||||
self.$status.html(data.items + ' place' + (data.items == 1 ? '' : 's'))
|
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) {
|
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) {
|
function toFixed(val) {
|
||||||
return Ox.isNumber(val) ? val.toFixed(8) : val; // fixme: why can a string be passed ??
|
return Ox.isNumber(val) ? val.toFixed(8) : val; // fixme: why can a string be passed ??
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue