2012-01-12 10:39:05 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.AnnotationFolder <f> AnnotationFolder Object
|
2012-07-04 11:29:18 +00:00
|
|
|
options <o> Options object
|
|
|
|
editable <b|false> If true, annotations can be added
|
|
|
|
id <s> id
|
|
|
|
items <a|[]> items
|
|
|
|
title <s> title
|
|
|
|
type <s|'text'> panel type
|
|
|
|
width <n|0>
|
|
|
|
self <o> Shared private variable
|
2012-05-31 10:32:54 +00:00
|
|
|
([options[, self]]) -> <o:Ox.CollapsePanel> AnnotationFolder Object
|
2012-06-17 22:38:26 +00:00
|
|
|
add <!> add
|
|
|
|
blur <!> blur
|
|
|
|
change <!> change
|
|
|
|
edit <!> edit
|
|
|
|
info <!> info
|
|
|
|
insert <!> insert
|
|
|
|
key_* <!> key_*
|
|
|
|
open <!> open
|
|
|
|
remove <!> remove
|
2013-05-08 16:53:33 +00:00
|
|
|
selectnext <!> selectnext
|
|
|
|
selectprevious <!> selectprevious
|
2012-06-17 22:38:26 +00:00
|
|
|
selectnone <!> selectnone
|
|
|
|
select <!> select
|
|
|
|
submit <!> submit
|
|
|
|
togglelayer <!> togglelayer
|
|
|
|
togglewidget <!> togglewidget
|
2012-01-12 10:39:05 +00:00
|
|
|
@*/
|
|
|
|
|
|
|
|
Ox.AnnotationFolder = function(options, self) {
|
|
|
|
|
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
|
|
|
.defaults({
|
2012-01-17 15:43:46 +00:00
|
|
|
clickLink: null,
|
2012-01-12 10:39:05 +00:00
|
|
|
collapsed: false,
|
|
|
|
editable: false,
|
2012-02-01 05:21:29 +00:00
|
|
|
highlight: '',
|
2012-01-12 10:39:05 +00:00
|
|
|
id: '',
|
|
|
|
'in': 0,
|
|
|
|
item: '',
|
|
|
|
items: [],
|
|
|
|
out: 0,
|
|
|
|
position: 0,
|
|
|
|
range: 'all',
|
|
|
|
selected: '',
|
2012-02-05 11:08:56 +00:00
|
|
|
showInfo: false,
|
2012-01-13 16:25:47 +00:00
|
|
|
showWidget: false,
|
2012-01-12 10:39:05 +00:00
|
|
|
sort: 'position',
|
|
|
|
title: '',
|
|
|
|
type: 'text',
|
|
|
|
users: 'all',
|
2012-01-13 16:25:47 +00:00
|
|
|
widgetSize: 256,
|
2012-01-12 10:39:05 +00:00
|
|
|
width: 0
|
|
|
|
})
|
2012-05-28 19:35:41 +00:00
|
|
|
.options(options || {})
|
|
|
|
.update(function(key, value) {
|
|
|
|
if (key == 'highlight') {
|
|
|
|
self.$annotations.options({highlight: value});
|
|
|
|
}
|
|
|
|
if (['in', 'out'].indexOf(key) > -1 && self.editing) {
|
|
|
|
var item = Ox.getObjectById(self.options.items, self.options.selected);
|
|
|
|
item[key] = value;
|
|
|
|
item.duration = self.options.out - self.options['in'];
|
|
|
|
self.points = getPoints();
|
|
|
|
}
|
|
|
|
if (key == 'in') {
|
|
|
|
//fixme: array editable should support item updates while editing
|
|
|
|
self.options.range == 'selection' && updateAnnotations();
|
|
|
|
} else if (key == 'out') {
|
|
|
|
self.options.range == 'selection' && updateAnnotations();
|
|
|
|
} else if (key == 'position') {
|
|
|
|
if (self.options.range == 'position') {
|
|
|
|
crossesPoint() && updateAnnotations();
|
|
|
|
self.position = self.options.position;
|
|
|
|
}
|
|
|
|
} else if (key == 'range') {
|
|
|
|
updateAnnotations();
|
2013-03-08 11:20:53 +00:00
|
|
|
self.$annotations.options({placeholder: getPlaceholder()});
|
2012-05-28 19:35:41 +00:00
|
|
|
} else if (key == 'selected') {
|
|
|
|
if (value === '') {
|
|
|
|
self.editing = false;
|
|
|
|
}
|
|
|
|
if (value && self.options.collapsed) {
|
|
|
|
self.$panel.options({animate: false});
|
|
|
|
self.$panel.options({collapsed: false});
|
|
|
|
self.$panel.options({animate: true});
|
|
|
|
}
|
|
|
|
self.$annotations.options({selected: value});
|
|
|
|
} else if (key == 'sort') {
|
|
|
|
self.sort = getSort();
|
|
|
|
self.$annotations.options({sort: self.sort});
|
|
|
|
showWarnings();
|
|
|
|
} else if (key == 'users') {
|
|
|
|
updateAnnotations();
|
|
|
|
} else if (key == 'width') {
|
|
|
|
if (self.widget) {
|
|
|
|
self.$outer.options({width: self.options.width});
|
|
|
|
self.$inner.options({width: self.options.width});
|
|
|
|
self.$widget.options({width: self.options.width});
|
|
|
|
}
|
|
|
|
self.$annotations.options({
|
|
|
|
width: self.options.type == 'text' ? self.options.width + 8 : self.options.width
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-01-12 10:39:05 +00:00
|
|
|
|
2012-02-19 10:49:52 +00:00
|
|
|
if (self.options.selected) {
|
|
|
|
self.options.collapsed = false;
|
|
|
|
}
|
|
|
|
|
2012-01-17 11:50:31 +00:00
|
|
|
self.annotations = getAnnotations();
|
2012-01-16 17:51:53 +00:00
|
|
|
self.points = getPoints();
|
|
|
|
self.position = self.options.position;
|
2012-01-12 10:39:05 +00:00
|
|
|
self.sort = getSort();
|
2012-01-13 16:25:47 +00:00
|
|
|
self.widget = self.options.type == 'event' ? 'Calendar'
|
|
|
|
: self.options.type == 'place' ? 'Map' : '';
|
2012-01-12 10:39:05 +00:00
|
|
|
|
2012-01-14 11:39:55 +00:00
|
|
|
self.$addButton = Ox.Button({
|
2012-01-27 14:29:11 +00:00
|
|
|
id: 'add',
|
|
|
|
style: 'symbol',
|
|
|
|
title: 'add',
|
2013-07-17 10:19:57 +00:00
|
|
|
tooltip: Ox._('Add {0}', [self.options.item]),
|
2012-01-27 14:29:11 +00:00
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
that.triggerEvent('add', {value: ''});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
self.$infoButton = Ox.Button({
|
|
|
|
style: 'symbol',
|
|
|
|
title: 'info',
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
that.triggerEvent('info');
|
|
|
|
}
|
|
|
|
});
|
2012-01-14 11:39:55 +00:00
|
|
|
|
2012-01-17 09:25:58 +00:00
|
|
|
self.$panel = Ox.CollapsePanel({
|
2012-01-12 10:39:05 +00:00
|
|
|
collapsed: self.options.collapsed,
|
2012-02-16 11:35:03 +00:00
|
|
|
extras: [self.options.editable ? self.$addButton : self.$infoButton],
|
2012-01-12 10:39:05 +00:00
|
|
|
size: 16,
|
|
|
|
title: self.options.title
|
|
|
|
})
|
|
|
|
.addClass('OxAnnotationFolder')
|
|
|
|
.bindEvent({
|
2012-01-14 11:39:55 +00:00
|
|
|
toggle: toggleLayer
|
2012-01-17 09:25:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
that.setElement(self.$panel);
|
2012-01-12 10:39:05 +00:00
|
|
|
that.$content = that.$element.$content;
|
|
|
|
|
2012-01-13 16:25:47 +00:00
|
|
|
if (self.widget) {
|
|
|
|
self.widgetSize = self.options.showWidget * self.options.widgetSize;
|
|
|
|
self.$outer = Ox.Element()
|
2012-01-12 19:04:32 +00:00
|
|
|
.css({
|
2012-01-13 16:25:47 +00:00
|
|
|
display: 'table-cell',
|
2012-01-14 11:39:55 +00:00
|
|
|
width: self.options.width + 'px'
|
2012-01-13 16:25:47 +00:00
|
|
|
})
|
|
|
|
.appendTo(that.$content);
|
|
|
|
self.$inner = Ox.Element()
|
2012-01-14 11:39:55 +00:00
|
|
|
.css({
|
|
|
|
height: self.widgetSize + 'px',
|
|
|
|
overflow: 'hidden'
|
2012-01-12 19:04:32 +00:00
|
|
|
})
|
2012-01-14 11:39:55 +00:00
|
|
|
.appendTo(self.$outer);
|
|
|
|
if (options.type == 'event') {
|
|
|
|
self.$widget = self.$calendar = Ox.Calendar({
|
|
|
|
events: getEvents(),
|
|
|
|
height: self.widgetSize,
|
|
|
|
showZoombar: true,
|
2012-01-27 14:29:11 +00:00
|
|
|
width: self.options.width,
|
|
|
|
zoomOnlyWhenFocused: true
|
2012-01-14 11:39:55 +00:00
|
|
|
})
|
|
|
|
.css({
|
|
|
|
width: self.options.width + 'px',
|
|
|
|
height: self.widgetSize + 'px'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
select: function(data) {
|
2012-02-02 02:32:41 +00:00
|
|
|
if (
|
|
|
|
!data.id && self.options.selected
|
|
|
|
&& isDefined(Ox.getObjectById(self.options.items, self.options.selected))
|
|
|
|
) {
|
2012-01-17 12:10:50 +00:00
|
|
|
// only deselect annotation if the event deselect was not
|
|
|
|
// caused by switching to an annotation without event
|
|
|
|
self.$annotations.options({selected: ''});
|
2012-02-02 02:32:41 +00:00
|
|
|
} else if (
|
|
|
|
data.annotationIds
|
|
|
|
&& data.annotationIds.indexOf(self.options.selected) == -1
|
|
|
|
) {
|
2012-01-17 12:10:50 +00:00
|
|
|
// only select a new annotation if the currently selected
|
|
|
|
// annotation does not match the selected event
|
|
|
|
self.$annotations.options({selected: data.annotationIds[0]});
|
2012-01-17 09:25:58 +00:00
|
|
|
}
|
2012-01-14 11:39:55 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$inner);
|
|
|
|
} else { // place
|
|
|
|
self.$widget = self.$map = Ox.Map({
|
|
|
|
places: getPlaces(),
|
2012-01-15 15:05:17 +00:00
|
|
|
showTypes: true,
|
2012-01-14 11:39:55 +00:00
|
|
|
// FIXME: should be showZoombar
|
2012-01-27 14:29:11 +00:00
|
|
|
zoombar: true,
|
|
|
|
zoomOnlyWhenFocused: true
|
2012-01-14 11:39:55 +00:00
|
|
|
// showLabels: true
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
width: self.options.width + 'px',
|
|
|
|
height: self.widgetSize + 'px'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
2012-06-30 14:59:52 +00:00
|
|
|
// FIXME: duplicated!
|
|
|
|
select: function(data) {
|
2012-02-02 02:32:41 +00:00
|
|
|
if (
|
|
|
|
!data.id && self.options.selected
|
|
|
|
&& isDefined(Ox.getObjectById(self.options.items, self.options.selected))
|
|
|
|
) {
|
2012-01-17 12:10:50 +00:00
|
|
|
// only deselect annotation if the place deselect was not
|
|
|
|
// caused by switching to an annotation without place
|
|
|
|
self.$annotations.options({selected: ''});
|
2012-02-02 02:32:41 +00:00
|
|
|
} else if (
|
|
|
|
data.annotationIds
|
|
|
|
&& data.annotationIds.indexOf(self.options.selected) == -1
|
|
|
|
) {
|
2012-01-17 12:10:50 +00:00
|
|
|
// only select a new annotation if the currently selected
|
|
|
|
// annotation does not match the selected place
|
|
|
|
self.$annotations.options({selected: data.annotationIds[0]});
|
2012-01-17 09:25:58 +00:00
|
|
|
}
|
2012-01-14 11:39:55 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$inner);
|
|
|
|
}
|
2012-01-13 16:25:47 +00:00
|
|
|
self.$resizebar = Ox.Element({
|
2013-05-09 13:03:33 +00:00
|
|
|
tooltip: Ox._('Drag to resize or click to toggle map') // fixme: update as w/ splitpanels
|
2012-01-13 16:25:47 +00:00
|
|
|
})
|
|
|
|
.addClass('OxResizebar OxHorizontal')
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2012-01-14 11:39:55 +00:00
|
|
|
top: self.widgetSize + 'px',
|
2012-01-13 16:25:47 +00:00
|
|
|
cursor: 'ns-resize'
|
2012-01-12 10:39:05 +00:00
|
|
|
})
|
2012-01-13 16:25:47 +00:00
|
|
|
.append($('<div>').addClass('OxSpace'))
|
|
|
|
.append($('<div>').addClass('OxLine'))
|
|
|
|
.append($('<div>').addClass('OxSpace'))
|
2012-01-12 10:39:05 +00:00
|
|
|
.bindEvent({
|
2012-01-13 16:25:47 +00:00
|
|
|
anyclick: toggleWidget,
|
|
|
|
dragstart: dragstart,
|
|
|
|
drag: drag,
|
|
|
|
dragend: dragend
|
|
|
|
})
|
|
|
|
.appendTo(self.$outer);
|
2012-01-12 10:39:05 +00:00
|
|
|
}
|
2012-01-13 16:25:47 +00:00
|
|
|
|
|
|
|
self.$annotations = Ox.ArrayEditable({
|
2012-01-17 15:43:46 +00:00
|
|
|
clickLink: self.options.clickLink,
|
2012-01-13 16:25:47 +00:00
|
|
|
editable: self.options.editable,
|
2012-03-20 09:34:50 +00:00
|
|
|
getSortValue: self.options.type == 'text'
|
|
|
|
? function(value) {
|
|
|
|
return Ox.stripTags(value);
|
|
|
|
}
|
|
|
|
: null,
|
2013-12-26 16:43:03 +00:00
|
|
|
globalAttributes: ['lang'],
|
2012-02-01 05:21:29 +00:00
|
|
|
highlight: self.options.highlight,
|
2012-01-17 11:50:31 +00:00
|
|
|
items: self.annotations,
|
2013-03-08 11:18:20 +00:00
|
|
|
placeholder: getPlaceholder(),
|
2012-01-13 16:25:47 +00:00
|
|
|
selected: self.options.selected,
|
2012-01-15 15:05:17 +00:00
|
|
|
separator: ';',
|
2012-01-13 16:25:47 +00:00
|
|
|
sort: self.sort,
|
|
|
|
submitOnBlur: false,
|
2012-02-22 10:14:25 +00:00
|
|
|
tooltipText: self.options.showInfo ? function(item) {
|
2012-06-16 16:17:28 +00:00
|
|
|
return Ox.encodeHTMLEntities(item.user) + ', '
|
|
|
|
+ Ox.formatDate(item.modified.slice(0, 10), '%B %e, %Y');
|
2012-02-22 10:14:25 +00:00
|
|
|
} : '',
|
2012-01-16 11:22:34 +00:00
|
|
|
width: self.options.width,
|
2012-01-21 14:58:32 +00:00
|
|
|
maxHeight: self.options.type == 'text' ? Infinity : void 0,
|
2012-01-13 16:25:47 +00:00
|
|
|
type: self.options.type == 'text' ? 'textarea' : 'input'
|
|
|
|
})
|
|
|
|
//.css({marginTop: '256px'})
|
|
|
|
.bindEvent({
|
|
|
|
add: function(data) {
|
2012-01-15 15:05:17 +00:00
|
|
|
if (self.editing) {
|
|
|
|
// FIXME: changed value will not be saved!
|
|
|
|
}
|
|
|
|
that.triggerEvent('add', {value: data.value || ''});
|
2012-01-13 16:25:47 +00:00
|
|
|
},
|
|
|
|
blur: function() {
|
2012-01-15 15:05:17 +00:00
|
|
|
// the video editor will, if it has not received focus,
|
|
|
|
// call blurItem
|
2012-01-13 16:25:47 +00:00
|
|
|
that.triggerEvent('blur');
|
|
|
|
},
|
2012-01-15 15:05:17 +00:00
|
|
|
change: changeAnnotation,
|
2012-01-17 11:50:31 +00:00
|
|
|
'delete': removeAnnotation,
|
2012-01-13 16:25:47 +00:00
|
|
|
edit: function() {
|
|
|
|
self.editing = true;
|
|
|
|
that.triggerEvent('edit');
|
|
|
|
},
|
2012-02-16 16:35:59 +00:00
|
|
|
insert: function(data) {
|
|
|
|
that.triggerEvent('insert', data);
|
|
|
|
},
|
2012-02-19 11:06:03 +00:00
|
|
|
open: function() {
|
|
|
|
that.triggerEvent('open');
|
|
|
|
},
|
2012-01-13 16:25:47 +00:00
|
|
|
select: selectAnnotation,
|
2013-05-08 16:53:33 +00:00
|
|
|
selectnext: function() {
|
|
|
|
that.triggerEvent('selectnext');
|
2012-02-01 19:33:10 +00:00
|
|
|
},
|
2013-05-08 16:53:33 +00:00
|
|
|
selectprevious: function() {
|
|
|
|
that.triggerEvent('selectprevious');
|
2012-02-01 19:33:10 +00:00
|
|
|
},
|
|
|
|
selectnone: function() {
|
|
|
|
that.triggerEvent('selectnone');
|
|
|
|
},
|
2012-02-15 22:20:19 +00:00
|
|
|
submit: submitAnnotation
|
2012-01-13 16:25:47 +00:00
|
|
|
})
|
|
|
|
.appendTo(
|
|
|
|
['event', 'place'].indexOf(self.options.type) > -1
|
|
|
|
? self.$outer : that.$content
|
|
|
|
);
|
|
|
|
|
2012-02-15 22:20:19 +00:00
|
|
|
[
|
2012-02-15 22:41:49 +00:00
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
2012-02-19 11:21:52 +00:00
|
|
|
'b', 'backslash', 'closebracket', 'comma', 'dot',
|
|
|
|
'equal', 'f', 'g', 'h', 'i', 'minus', 'n', 'o',
|
|
|
|
'openbracket', 'p', 'shift_0', 'shift_equal',
|
|
|
|
'shift_g', 'shift_i', 'shift_minus', 'shift_o',
|
|
|
|
'slash', 'space'
|
2012-02-15 22:20:19 +00:00
|
|
|
].forEach(function(key) {
|
|
|
|
key = 'key_' + key;
|
|
|
|
self.$annotations.bindEvent(key, function() {
|
|
|
|
that.triggerEvent(key);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
self.options.selected && setTimeout(function() {
|
2012-01-27 18:28:44 +00:00
|
|
|
// need timeout in order to trigger events
|
|
|
|
if (self.options.collapsed) {
|
|
|
|
self.$panel.options({collapsed: false});
|
|
|
|
}
|
2012-01-12 10:39:05 +00:00
|
|
|
selectAnnotation({id: self.options.selected});
|
|
|
|
}, 0);
|
|
|
|
|
2012-01-14 11:39:55 +00:00
|
|
|
showWarnings();
|
2012-01-13 16:25:47 +00:00
|
|
|
|
2012-01-15 15:05:17 +00:00
|
|
|
function changeAnnotation(data) {
|
|
|
|
var item = Ox.getObjectById(self.options.items, data.id);
|
|
|
|
item.value = data.value;
|
|
|
|
that.triggerEvent('change', item);
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:51:53 +00:00
|
|
|
function crossesPoint() {
|
2012-05-19 13:14:04 +00:00
|
|
|
var positions = [self.position, self.options.position].sort();
|
2012-01-16 17:51:53 +00:00
|
|
|
return self.points.some(function(point) {
|
2012-05-10 10:12:34 +00:00
|
|
|
return point >= positions[0] && point <= positions[1];
|
2012-01-16 17:51:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-01-13 16:25:47 +00:00
|
|
|
function dragstart() {
|
2012-01-14 11:39:55 +00:00
|
|
|
if (self.options.showWidget) {
|
2013-07-19 08:42:25 +00:00
|
|
|
Ox.$body.addClass('OxDragging');
|
2012-01-14 11:39:55 +00:00
|
|
|
self.drag = {
|
|
|
|
startSize: self.options.widgetSize
|
|
|
|
};
|
|
|
|
}
|
2012-01-13 16:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drag(e) {
|
2012-01-14 11:39:55 +00:00
|
|
|
if (self.options.showWidget) {
|
|
|
|
self.options.widgetSize = Ox.limit(
|
|
|
|
self.drag.startSize + e.clientDY, 128, 384
|
|
|
|
);
|
|
|
|
if (self.options.widgetSize >= 248 && self.options.widgetSize <= 264) {
|
|
|
|
self.options.widgetSize = 256;
|
|
|
|
}
|
|
|
|
self.$resizebar.css({top: self.options.widgetSize + 'px'});
|
|
|
|
self.$inner.css({height: self.options.widgetSize + 'px'});
|
2012-01-16 14:02:30 +00:00
|
|
|
self.$widget.options({height: self.options.widgetSize});
|
2012-01-14 11:39:55 +00:00
|
|
|
}
|
2012-01-13 16:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dragend(e) {
|
2012-01-14 11:39:55 +00:00
|
|
|
if (self.options.showWidget) {
|
2013-07-19 08:42:25 +00:00
|
|
|
Ox.$body.removeClass('OxDragging');
|
2012-01-30 22:11:05 +00:00
|
|
|
self.options.type == 'event'
|
|
|
|
? self.$calendar.resizeCalendar()
|
|
|
|
: self.$map.resizeMap();
|
2012-01-14 11:39:55 +00:00
|
|
|
that.triggerEvent('resizewidget', {size: self.options.widgetSize});
|
|
|
|
}
|
2012-01-13 16:25:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
function getAnnotations() {
|
2012-05-22 14:29:37 +00:00
|
|
|
return Ox.filter(self.options.items, function(item) {
|
2012-01-12 10:39:05 +00:00
|
|
|
return self.editing && item.id == self.options.selected || (
|
|
|
|
(
|
|
|
|
self.options.range == 'all' || (
|
|
|
|
self.options.range == 'selection'
|
2012-02-01 18:04:42 +00:00
|
|
|
&& item['in'] <= self.options.out
|
|
|
|
&& item.out >= self.options['in']
|
2012-01-12 10:39:05 +00:00
|
|
|
) || (
|
|
|
|
self.options.range == 'position'
|
|
|
|
&& item['in'] <= self.options.position
|
|
|
|
&& item.out >= self.options.position
|
|
|
|
)
|
|
|
|
) && (
|
|
|
|
self.options.users == 'all'
|
|
|
|
|| self.options.users.indexOf(item.user) > -1
|
|
|
|
)
|
2012-05-22 14:29:37 +00:00
|
|
|
);
|
2012-01-12 10:39:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-01-13 16:25:47 +00:00
|
|
|
function getEvents() {
|
|
|
|
var events = [];
|
2012-01-17 11:50:31 +00:00
|
|
|
self.annotations.filter(function(item) {
|
2012-02-02 02:32:41 +00:00
|
|
|
return isDefined(item);
|
2012-01-17 09:25:58 +00:00
|
|
|
}).forEach(function(item) {
|
|
|
|
var index = Ox.getIndexById(events, item.event.id);
|
|
|
|
if (index == -1) {
|
2012-01-13 16:25:47 +00:00
|
|
|
events.push(Ox.extend({
|
2012-01-17 09:25:58 +00:00
|
|
|
annotationIds: [item.id]
|
|
|
|
}, item.event))
|
|
|
|
} else {
|
|
|
|
events[index].annotationIds.push(item.id);
|
2012-01-13 16:25:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
2013-03-08 11:18:20 +00:00
|
|
|
function getPlaceholder() {
|
|
|
|
return 'No ' + self.options.title.toLowerCase() + (
|
|
|
|
self.options.range == 'position' ? ' at current position'
|
|
|
|
: self.options.range == 'selection' ? ' in current selection'
|
|
|
|
: ''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-01-12 19:04:32 +00:00
|
|
|
function getPlaces() {
|
|
|
|
var places = [];
|
2012-01-17 11:50:31 +00:00
|
|
|
self.annotations.filter(function(item) {
|
2012-02-02 02:32:41 +00:00
|
|
|
return isDefined(item);
|
2012-01-17 09:25:58 +00:00
|
|
|
}).forEach(function(item) {
|
|
|
|
var index = Ox.getIndexById(places, item.place.id);
|
|
|
|
if (index == -1) {
|
2012-01-12 19:04:32 +00:00
|
|
|
places.push(Ox.extend({
|
2012-01-17 09:25:58 +00:00
|
|
|
annotationIds: [item.id]
|
2012-01-24 09:59:29 +00:00
|
|
|
}, item.place));
|
2012-01-17 09:25:58 +00:00
|
|
|
} else {
|
|
|
|
places[index].annotationIds.push(item.id);
|
2012-01-12 19:04:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return places;
|
|
|
|
}
|
|
|
|
|
2012-02-01 18:04:42 +00:00
|
|
|
function getPoints() {
|
|
|
|
return Ox.unique(Ox.flatten(
|
|
|
|
self.options.items.map(function(item) {
|
|
|
|
return [item['in'], item.out];
|
|
|
|
})
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
function getSort() {
|
|
|
|
return ({
|
2012-09-18 19:26:53 +00:00
|
|
|
duration: ['-duration', '+in', self.options.type == 'text' ? '+created' : '+value'],
|
|
|
|
position: ['+in', '+duration', self.options.type == 'text' ? '+created' : '+value'],
|
2012-02-04 11:44:19 +00:00
|
|
|
text: ['+value', '+in', '+duration']
|
2012-01-12 10:39:05 +00:00
|
|
|
})[self.options.sort];
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:32:41 +00:00
|
|
|
function isDefined(item) {
|
2012-02-04 08:58:46 +00:00
|
|
|
return !!item[self.options.type]
|
|
|
|
&& !!item[self.options.type].type;
|
2012-02-02 02:32:41 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 11:50:31 +00:00
|
|
|
function removeAnnotation(data) {
|
|
|
|
var item;
|
|
|
|
self.editing = false;
|
|
|
|
if (self.widget) {
|
|
|
|
item = Ox.getObjectById(self.options.items, data.id);
|
2012-02-02 02:32:41 +00:00
|
|
|
if (isDefined(item)) {
|
2012-01-17 11:50:31 +00:00
|
|
|
if (self.options.type == 'event') {
|
2012-02-18 09:56:58 +00:00
|
|
|
self.$calendar.options({selected: ''})
|
|
|
|
.options({events: getEvents()});
|
2012-01-17 11:50:31 +00:00
|
|
|
} else {
|
2012-02-18 09:56:58 +00:00
|
|
|
self.$map.options({selected: ''})
|
|
|
|
.options({places: getPlaces()});
|
2012-01-17 11:50:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-18 09:56:58 +00:00
|
|
|
showWarnings();
|
2012-01-17 11:50:31 +00:00
|
|
|
that.triggerEvent('remove', {id: data.id});
|
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
function selectAnnotation(data) {
|
|
|
|
var item = Ox.getObjectById(self.options.items, data.id);
|
|
|
|
self.options.selected = item ? data.id : '';
|
2012-01-17 09:25:58 +00:00
|
|
|
if (self.widget) {
|
|
|
|
if (self.options.type == 'event') {
|
|
|
|
self.$calendar.options({
|
2012-02-02 02:32:41 +00:00
|
|
|
selected: item && isDefined(item) ? item.event.id : ''
|
2012-01-17 09:25:58 +00:00
|
|
|
})
|
|
|
|
.panToEvent();
|
|
|
|
} else {
|
|
|
|
self.$map.options({
|
2012-02-02 02:32:41 +00:00
|
|
|
selected: item && isDefined(item) ? item.place.id : ''
|
2012-01-17 09:25:58 +00:00
|
|
|
})
|
|
|
|
.panToPlace();
|
|
|
|
}
|
2012-01-13 16:25:47 +00:00
|
|
|
}
|
2012-01-12 10:39:05 +00:00
|
|
|
that.triggerEvent('select', Ox.extend(data, item ? {
|
|
|
|
'in': item['in'],
|
|
|
|
out: item.out,
|
|
|
|
layer: self.options.id
|
|
|
|
} : {}));
|
|
|
|
}
|
|
|
|
|
2012-01-14 11:39:55 +00:00
|
|
|
function showWarnings() {
|
2012-01-15 15:05:17 +00:00
|
|
|
if (self.widget && self.options.items.length) {
|
2012-01-17 11:50:31 +00:00
|
|
|
self.$annotations.find('.OxEditableElement').each(function() {
|
2012-01-14 11:39:55 +00:00
|
|
|
var $element = $(this);
|
2012-01-19 16:37:39 +00:00
|
|
|
// We don't want to catch an eventual placeholder,
|
|
|
|
// which is an EditableElement without .data('id')
|
|
|
|
if (
|
|
|
|
$element.data('id')
|
2012-02-02 02:32:41 +00:00
|
|
|
&& !isDefined(
|
|
|
|
Ox.getObjectById(self.options.items, $element.data('id'))
|
|
|
|
)
|
2012-01-19 16:37:39 +00:00
|
|
|
) {
|
2012-01-17 11:50:31 +00:00
|
|
|
$element.addClass('OxWarning');
|
2012-02-18 09:56:58 +00:00
|
|
|
} else {
|
|
|
|
$element.removeClass('OxWarning');
|
2012-01-17 11:50:31 +00:00
|
|
|
}
|
2012-01-14 11:39:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
function submitAnnotation(data) {
|
|
|
|
var item = Ox.getObjectById(self.options.items, data.id);
|
|
|
|
item.value = data.value;
|
|
|
|
self.editing = false;
|
|
|
|
self.options.sort == 'text' && self.$annotations.reloadItems();
|
|
|
|
that.triggerEvent('submit', item);
|
|
|
|
}
|
|
|
|
|
2012-01-14 11:39:55 +00:00
|
|
|
function toggleLayer() {
|
2012-01-12 10:39:05 +00:00
|
|
|
self.options.collapsed = !self.options.collapsed;
|
2012-01-30 22:11:05 +00:00
|
|
|
if (
|
|
|
|
!self.options.collapsed
|
|
|
|
&& self.options.type == 'place'
|
|
|
|
&& self.options.showWidget
|
|
|
|
) {
|
|
|
|
self.$map.resizeMap();
|
|
|
|
}
|
2012-01-27 18:28:44 +00:00
|
|
|
if (self.options.collapsed) {
|
|
|
|
self.editing && that.blurItem();
|
|
|
|
self.$annotations.loseFocus();
|
|
|
|
}
|
2012-01-14 11:39:55 +00:00
|
|
|
that.triggerEvent('togglelayer', {collapsed: self.options.collapsed});
|
2012-01-12 10:39:05 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 16:25:47 +00:00
|
|
|
function toggleWidget() {
|
|
|
|
self.options.showWidget = !self.options.showWidget;
|
|
|
|
self.widgetSize = self.options.showWidget * self.options.widgetSize;
|
|
|
|
self.$resizebar.animate({top: self.widgetSize + 'px'}, 250);
|
|
|
|
self.$inner.animate({height: self.widgetSize + 'px'}, 250);
|
2012-01-14 11:39:55 +00:00
|
|
|
self.$widget.animate({height: self.widgetSize + 'px'}, 250, function() {
|
|
|
|
self.$widget.options({height: self.widgetSize});
|
2012-01-13 16:25:47 +00:00
|
|
|
});
|
2012-01-14 11:39:55 +00:00
|
|
|
that.triggerEvent('togglewidget', {collapsed: !self.options.showWidget});
|
2012-01-13 16:25:47 +00:00
|
|
|
}
|
|
|
|
|
2012-01-15 15:05:17 +00:00
|
|
|
function updateAnnotations() {
|
2012-01-17 11:50:31 +00:00
|
|
|
self.annotations = getAnnotations();
|
|
|
|
self.$annotations.options({items: self.annotations});
|
2012-01-15 15:05:17 +00:00
|
|
|
showWarnings();
|
2012-01-17 11:50:31 +00:00
|
|
|
if (self.widget) {
|
|
|
|
self.options.type == 'event'
|
|
|
|
? self.$calendar.options({events: getEvents()})
|
|
|
|
: self.$map.options({places: getPlaces()});
|
|
|
|
}
|
2012-01-15 15:05:17 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
/*@
|
|
|
|
addItem <f> addItem
|
|
|
|
@*/
|
|
|
|
that.addItem = function(item) {
|
|
|
|
var pos = 0;
|
|
|
|
self.options.items.splice(pos, 0, item);
|
2012-01-27 18:28:44 +00:00
|
|
|
self.$panel.options({collapsed: false});
|
2012-01-15 15:05:17 +00:00
|
|
|
self.$annotations
|
|
|
|
.addItem(pos, item)
|
|
|
|
.options({selected: item.id})
|
|
|
|
.editItem();
|
2012-01-17 11:50:31 +00:00
|
|
|
showWarnings();
|
2012-02-15 22:31:37 +00:00
|
|
|
self.points = getPoints();
|
2012-01-15 15:05:17 +00:00
|
|
|
return that;
|
2012-01-12 10:39:05 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
blurItem <f> blur item
|
|
|
|
() -> <o> blur selected item
|
|
|
|
@*/
|
2012-01-12 10:39:05 +00:00
|
|
|
that.blurItem = function() {
|
2012-01-16 14:02:30 +00:00
|
|
|
self.editing = false;
|
2012-01-12 10:39:05 +00:00
|
|
|
self.$annotations.blurItem();
|
2012-01-15 15:05:17 +00:00
|
|
|
return that;
|
2012-01-12 10:39:05 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
editItem <f> edit item
|
|
|
|
() -> <o> edit selected item
|
|
|
|
@*/
|
2012-01-12 10:39:05 +00:00
|
|
|
that.editItem = function() {
|
2012-01-16 14:02:30 +00:00
|
|
|
self.editing = true;
|
2012-01-27 18:28:44 +00:00
|
|
|
self.$panel.options({collapsed: false});
|
2012-01-12 10:39:05 +00:00
|
|
|
self.$annotations.editItem();
|
2012-01-15 15:05:17 +00:00
|
|
|
return that;
|
2012-01-12 10:39:05 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
gainFocus <f> gain focus
|
|
|
|
() -> <o> gain focus
|
|
|
|
@*/
|
2012-02-16 12:32:52 +00:00
|
|
|
that.gainFocus = function() {
|
|
|
|
self.$annotations.gainFocus();
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
removeItem <f> remove item
|
|
|
|
() -> <o> remove selected item
|
|
|
|
@*/
|
2012-02-16 11:35:03 +00:00
|
|
|
that.removeItem = function() {
|
|
|
|
self.$annotations.removeItem();
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
selectItem <f> select item
|
|
|
|
(position) -> <o> select item at position
|
|
|
|
@*/
|
2012-02-01 19:33:10 +00:00
|
|
|
that.selectItem = function(position) {
|
|
|
|
// selects the first (0) or last (-1) visible annotation
|
|
|
|
if (self.annotations.length) {
|
|
|
|
that.options({selected: self.annotations[
|
|
|
|
position == 0 ? 0 : self.annotations.length - 1
|
|
|
|
].id});
|
|
|
|
self.$annotations.gainFocus();
|
|
|
|
} else {
|
|
|
|
that.triggerEvent(
|
2013-05-08 16:53:33 +00:00
|
|
|
position == 0 ? 'selectnext' : 'selectprevious'
|
2012-02-01 19:33:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
updateItem <f> update item
|
|
|
|
(id, data) -> <o> update item
|
|
|
|
@*/
|
2012-01-31 10:57:09 +00:00
|
|
|
that.updateItem = function(id, data) {
|
|
|
|
var item = Ox.getObjectById(self.options.items, id);
|
2012-01-24 09:59:29 +00:00
|
|
|
Ox.forEach(data, function(value, key) {
|
|
|
|
item[key] = value;
|
|
|
|
});
|
2012-02-18 09:56:58 +00:00
|
|
|
if (id != item.id) {
|
|
|
|
self.$annotations.find('.OxEditableElement').each(function() {
|
|
|
|
var $element = $(this);
|
|
|
|
if ($element.data('id') == self.options.selected) {
|
|
|
|
$element.data({id: item.id});
|
|
|
|
}
|
2012-02-15 16:13:09 +00:00
|
|
|
});
|
2012-02-18 09:56:58 +00:00
|
|
|
self.options.selected = item.id;
|
2012-01-17 11:50:31 +00:00
|
|
|
}
|
2012-02-18 09:56:58 +00:00
|
|
|
if (self.$widget) {
|
|
|
|
// update may have made the item match,
|
|
|
|
// or no longer match, an event or place
|
|
|
|
if (isDefined(item)) {
|
|
|
|
self.$widget.options(
|
|
|
|
self.options.type == 'event'
|
|
|
|
? {events: getEvents()}
|
|
|
|
: {places: getPlaces()}
|
|
|
|
)
|
|
|
|
.options({
|
|
|
|
selected: item[self.options.type].id
|
|
|
|
});
|
|
|
|
self.$widget[
|
|
|
|
self.options.type == 'event' ? 'panToEvent' : 'panToPlace'
|
|
|
|
]();
|
|
|
|
} else {
|
|
|
|
self.$widget.options({
|
|
|
|
selected: ''
|
|
|
|
})
|
|
|
|
.options(
|
|
|
|
self.options.type == 'event'
|
|
|
|
? {events: getEvents()}
|
|
|
|
: {places: getPlaces()}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (id != item.id) {
|
|
|
|
self.$annotations.options({selected: self.options.selected});
|
|
|
|
}
|
|
|
|
showWarnings();
|
2012-01-15 15:05:17 +00:00
|
|
|
return that;
|
2012-01-24 09:59:29 +00:00
|
|
|
};
|
2012-01-15 15:05:17 +00:00
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|