fix bugs related to selection of place/event annotations
This commit is contained in:
parent
bec434a353
commit
25f7c2a285
2 changed files with 39 additions and 15 deletions
|
@ -86,7 +86,9 @@ Ox.ListCalendar = function(options, self) {
|
||||||
// return Ox.formatDateRangeDuration(data.start, data.end, true);
|
// return Ox.formatDateRangeDuration(data.start, data.end, true);
|
||||||
var key = data.start + ' - ' + data.end;
|
var key = data.start + ' - ' + data.end;
|
||||||
if (!self.durationCache[key]) {
|
if (!self.durationCache[key]) {
|
||||||
self.durationCache[key] = Ox.formatDateRangeDuration(data.start, data.end, true);
|
self.durationCache[key] = data.start
|
||||||
|
? Ox.formatDateRangeDuration(data.start, data.end, true)
|
||||||
|
: '';
|
||||||
}
|
}
|
||||||
return self.durationCache[key];
|
return self.durationCache[key];
|
||||||
},
|
},
|
||||||
|
@ -230,7 +232,10 @@ Ox.ListCalendar = function(options, self) {
|
||||||
|
|
||||||
self.$calendar = Ox.Calendar({
|
self.$calendar = Ox.Calendar({
|
||||||
date: new Date(0),
|
date: new Date(0),
|
||||||
events: Ox.clone(self.options.events, true),
|
//events: Ox.clone(self.options.events, true),
|
||||||
|
events: self.options.events.filter(function(event) {
|
||||||
|
return !!event.start;
|
||||||
|
}),
|
||||||
height: self.options.height,
|
height: self.options.height,
|
||||||
showControls: self.options.showControls,
|
showControls: self.options.showControls,
|
||||||
showToolbar: true,
|
showToolbar: true,
|
||||||
|
@ -488,6 +493,7 @@ Ox.ListCalendar = function(options, self) {
|
||||||
selectEvent(event);
|
selectEvent(event);
|
||||||
self.$nameInput.focusInput(true);
|
self.$nameInput.focusInput(true);
|
||||||
} else {
|
} else {
|
||||||
|
// FIXME
|
||||||
alert(result.status.text);
|
alert(result.status.text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -141,11 +141,17 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
select: function(data) {
|
select: function(data) {
|
||||||
if (!data.id && self.options.selected && Ox.getObjectById(self.options.items, self.options.selected).event) {
|
if (
|
||||||
|
!data.id && self.options.selected
|
||||||
|
&& isDefined(Ox.getObjectById(self.options.items, self.options.selected))
|
||||||
|
) {
|
||||||
// only deselect annotation if the event deselect was not
|
// only deselect annotation if the event deselect was not
|
||||||
// caused by switching to an annotation without event
|
// caused by switching to an annotation without event
|
||||||
self.$annotations.options({selected: ''});
|
self.$annotations.options({selected: ''});
|
||||||
} else if (data.annotationIds.indexOf(self.options.selected) == -1) {
|
} else if (
|
||||||
|
data.annotationIds
|
||||||
|
&& data.annotationIds.indexOf(self.options.selected) == -1
|
||||||
|
) {
|
||||||
// only select a new annotation if the currently selected
|
// only select a new annotation if the currently selected
|
||||||
// annotation does not match the selected event
|
// annotation does not match the selected event
|
||||||
self.$annotations.options({selected: data.annotationIds[0]});
|
self.$annotations.options({selected: data.annotationIds[0]});
|
||||||
|
@ -169,11 +175,17 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
// FIXME: should be select, not selectplace
|
// FIXME: should be select, not selectplace
|
||||||
selectplace: function(data) {
|
selectplace: function(data) {
|
||||||
if (!data.id && self.options.selected && Ox.getObjectById(self.options.items, self.options.selected).place) {
|
if (
|
||||||
|
!data.id && self.options.selected
|
||||||
|
&& isDefined(Ox.getObjectById(self.options.items, self.options.selected))
|
||||||
|
) {
|
||||||
// only deselect annotation if the place deselect was not
|
// only deselect annotation if the place deselect was not
|
||||||
// caused by switching to an annotation without place
|
// caused by switching to an annotation without place
|
||||||
self.$annotations.options({selected: ''});
|
self.$annotations.options({selected: ''});
|
||||||
} else if (data.annotationIds && data.annotationIds.indexOf(self.options.selected) == -1) {
|
} else if (
|
||||||
|
data.annotationIds
|
||||||
|
&& data.annotationIds.indexOf(self.options.selected) == -1
|
||||||
|
) {
|
||||||
// only select a new annotation if the currently selected
|
// only select a new annotation if the currently selected
|
||||||
// annotation does not match the selected place
|
// annotation does not match the selected place
|
||||||
self.$annotations.options({selected: data.annotationIds[0]});
|
self.$annotations.options({selected: data.annotationIds[0]});
|
||||||
|
@ -336,7 +348,7 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
function getEvents() {
|
function getEvents() {
|
||||||
var events = [];
|
var events = [];
|
||||||
self.annotations.filter(function(item) {
|
self.annotations.filter(function(item) {
|
||||||
return !!item.event.defined;
|
return isDefined(item);
|
||||||
}).forEach(function(item) {
|
}).forEach(function(item) {
|
||||||
var index = Ox.getIndexById(events, item.event.id);
|
var index = Ox.getIndexById(events, item.event.id);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
|
@ -353,7 +365,7 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
function getPlaces() {
|
function getPlaces() {
|
||||||
var places = [];
|
var places = [];
|
||||||
self.annotations.filter(function(item) {
|
self.annotations.filter(function(item) {
|
||||||
return !!item.place.defined;
|
return isDefined(item);
|
||||||
}).forEach(function(item) {
|
}).forEach(function(item) {
|
||||||
var index = Ox.getIndexById(places, item.place.id);
|
var index = Ox.getIndexById(places, item.place.id);
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
|
@ -383,12 +395,18 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
})[self.options.sort];
|
})[self.options.sort];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDefined(item) {
|
||||||
|
return self.options.type == 'event'
|
||||||
|
? item.event.start !== ''
|
||||||
|
: item.place.lat !== null;
|
||||||
|
}
|
||||||
|
|
||||||
function removeAnnotation(data) {
|
function removeAnnotation(data) {
|
||||||
var item;
|
var item;
|
||||||
self.editing = false;
|
self.editing = false;
|
||||||
if (self.widget) {
|
if (self.widget) {
|
||||||
item = Ox.getObjectById(self.options.items, data.id);
|
item = Ox.getObjectById(self.options.items, data.id);
|
||||||
if (item[self.options.type].defined) {
|
if (isDefined(item)) {
|
||||||
if (self.options.type == 'event') {
|
if (self.options.type == 'event') {
|
||||||
self.$calendar.removeEvent(data.id);
|
self.$calendar.removeEvent(data.id);
|
||||||
} else {
|
} else {
|
||||||
|
@ -407,12 +425,12 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
if (self.widget) {
|
if (self.widget) {
|
||||||
if (self.options.type == 'event') {
|
if (self.options.type == 'event') {
|
||||||
self.$calendar.options({
|
self.$calendar.options({
|
||||||
selected: item && item.event.defined ? item.event.id : ''
|
selected: item && isDefined(item) ? item.event.id : ''
|
||||||
})
|
})
|
||||||
.panToEvent();
|
.panToEvent();
|
||||||
} else {
|
} else {
|
||||||
self.$map.options({
|
self.$map.options({
|
||||||
selected: item && item.place.defined ? item.place.id : ''
|
selected: item && isDefined(item) ? item.place.id : ''
|
||||||
})
|
})
|
||||||
.panToPlace();
|
.panToPlace();
|
||||||
}
|
}
|
||||||
|
@ -432,9 +450,9 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
// which is an EditableElement without .data('id')
|
// which is an EditableElement without .data('id')
|
||||||
if (
|
if (
|
||||||
$element.data('id')
|
$element.data('id')
|
||||||
&& !Ox.getObjectById(
|
&& !isDefined(
|
||||||
self.options.items, $element.data('id')
|
Ox.getObjectById(self.options.items, $element.data('id'))
|
||||||
)[self.options.type].defined
|
)
|
||||||
) {
|
) {
|
||||||
$element.addClass('OxWarning');
|
$element.addClass('OxWarning');
|
||||||
}
|
}
|
||||||
|
@ -601,7 +619,7 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
});
|
});
|
||||||
self.options.selected = item.id;
|
self.options.selected = item.id;
|
||||||
self.$annotations.options({selected: self.options.selected});
|
self.$annotations.options({selected: self.options.selected});
|
||||||
if (self.widget && item[self.options.type].defined) {
|
if (self.widget && isDefined(item)) {
|
||||||
// if updating has made the item match
|
// if updating has made the item match
|
||||||
// an event or place, then select it
|
// an event or place, then select it
|
||||||
self.$widget.options({selected: item[self.options.type].id});
|
self.$widget.options({selected: item[self.options.type].id});
|
||||||
|
|
Loading…
Add table
Reference in a new issue