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);
|
||||
var key = data.start + ' - ' + data.end;
|
||||
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];
|
||||
},
|
||||
|
@ -230,7 +232,10 @@ Ox.ListCalendar = function(options, self) {
|
|||
|
||||
self.$calendar = Ox.Calendar({
|
||||
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,
|
||||
showControls: self.options.showControls,
|
||||
showToolbar: true,
|
||||
|
@ -488,6 +493,7 @@ Ox.ListCalendar = function(options, self) {
|
|||
selectEvent(event);
|
||||
self.$nameInput.focusInput(true);
|
||||
} else {
|
||||
// FIXME
|
||||
alert(result.status.text);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -141,11 +141,17 @@ Ox.AnnotationFolder = function(options, self) {
|
|||
})
|
||||
.bindEvent({
|
||||
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
|
||||
// caused by switching to an annotation without event
|
||||
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
|
||||
// annotation does not match the selected event
|
||||
self.$annotations.options({selected: data.annotationIds[0]});
|
||||
|
@ -169,11 +175,17 @@ Ox.AnnotationFolder = function(options, self) {
|
|||
.bindEvent({
|
||||
// FIXME: should be select, not selectplace
|
||||
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
|
||||
// caused by switching to an annotation without place
|
||||
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
|
||||
// annotation does not match the selected place
|
||||
self.$annotations.options({selected: data.annotationIds[0]});
|
||||
|
@ -336,7 +348,7 @@ Ox.AnnotationFolder = function(options, self) {
|
|||
function getEvents() {
|
||||
var events = [];
|
||||
self.annotations.filter(function(item) {
|
||||
return !!item.event.defined;
|
||||
return isDefined(item);
|
||||
}).forEach(function(item) {
|
||||
var index = Ox.getIndexById(events, item.event.id);
|
||||
if (index == -1) {
|
||||
|
@ -353,7 +365,7 @@ Ox.AnnotationFolder = function(options, self) {
|
|||
function getPlaces() {
|
||||
var places = [];
|
||||
self.annotations.filter(function(item) {
|
||||
return !!item.place.defined;
|
||||
return isDefined(item);
|
||||
}).forEach(function(item) {
|
||||
var index = Ox.getIndexById(places, item.place.id);
|
||||
if (index == -1) {
|
||||
|
@ -383,12 +395,18 @@ Ox.AnnotationFolder = function(options, self) {
|
|||
})[self.options.sort];
|
||||
}
|
||||
|
||||
function isDefined(item) {
|
||||
return self.options.type == 'event'
|
||||
? item.event.start !== ''
|
||||
: item.place.lat !== null;
|
||||
}
|
||||
|
||||
function removeAnnotation(data) {
|
||||
var item;
|
||||
self.editing = false;
|
||||
if (self.widget) {
|
||||
item = Ox.getObjectById(self.options.items, data.id);
|
||||
if (item[self.options.type].defined) {
|
||||
if (isDefined(item)) {
|
||||
if (self.options.type == 'event') {
|
||||
self.$calendar.removeEvent(data.id);
|
||||
} else {
|
||||
|
@ -407,12 +425,12 @@ Ox.AnnotationFolder = function(options, self) {
|
|||
if (self.widget) {
|
||||
if (self.options.type == 'event') {
|
||||
self.$calendar.options({
|
||||
selected: item && item.event.defined ? item.event.id : ''
|
||||
selected: item && isDefined(item) ? item.event.id : ''
|
||||
})
|
||||
.panToEvent();
|
||||
} else {
|
||||
self.$map.options({
|
||||
selected: item && item.place.defined ? item.place.id : ''
|
||||
selected: item && isDefined(item) ? item.place.id : ''
|
||||
})
|
||||
.panToPlace();
|
||||
}
|
||||
|
@ -432,9 +450,9 @@ Ox.AnnotationFolder = function(options, self) {
|
|||
// which is an EditableElement without .data('id')
|
||||
if (
|
||||
$element.data('id')
|
||||
&& !Ox.getObjectById(
|
||||
self.options.items, $element.data('id')
|
||||
)[self.options.type].defined
|
||||
&& !isDefined(
|
||||
Ox.getObjectById(self.options.items, $element.data('id'))
|
||||
)
|
||||
) {
|
||||
$element.addClass('OxWarning');
|
||||
}
|
||||
|
@ -601,7 +619,7 @@ Ox.AnnotationFolder = function(options, self) {
|
|||
});
|
||||
self.options.selected = item.id;
|
||||
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
|
||||
// an event or place, then select it
|
||||
self.$widget.options({selected: item[self.options.type].id});
|
||||
|
|
Loading…
Reference in a new issue