oxjs/source/Ox.UI/js/Video/Ox.AnnotationPanel.js

344 lines
12 KiB
JavaScript
Raw Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2011-05-16 08:24:46 +00:00
/*@
2012-01-12 10:39:05 +00:00
Ox.AnnotationPanel <f> Video Annotation Panel
2011-05-16 08:24:46 +00:00
@*/
2011-04-22 22:03:10 +00:00
Ox.AnnotationPanel = function(options, self) {
self = self || {};
var that = Ox.Element({}, self)
2012-01-02 14:05:14 +00:00
.defaults({
2012-01-13 16:25:47 +00:00
calendarSize: 256,
editable: false,
2012-01-12 10:39:05 +00:00
font: 'small',
layers: [],
2012-01-13 16:25:47 +00:00
mapSize: 256,
range: 'all',
selected: '',
2012-01-13 16:25:47 +00:00
showCalendar: false,
2012-01-12 10:39:05 +00:00
showFonts: false,
showLayers: {},
2012-01-13 16:25:47 +00:00
showMap: false,
2012-01-12 10:39:05 +00:00
showUsers: false,
sort: 'position',
2012-01-12 10:39:05 +00:00
width: 256
2012-01-02 14:05:14 +00:00
})
2012-01-12 10:39:05 +00:00
.options(options || {})
.addClass('OxAnnotationPanel');
2011-04-22 22:03:10 +00:00
2012-01-12 10:39:05 +00:00
if (self.options.showUsers) {
self.users = Ox.sort(Ox.unique(Ox.flatten(
self.options.layers.map(function(layer) {
return layer.items.map(function(item) {
return item.user;
});
})
)));
self.enabledUsers = 'all';
}
2011-04-22 22:03:10 +00:00
2012-01-12 10:39:05 +00:00
self.$menubar = Ox.Bar({
size: 16
2011-04-22 22:03:10 +00:00
})
2012-01-12 10:39:05 +00:00
.addClass('OxVideoPlayer');
self.$optionsMenuButton = Ox.MenuButton({
items: Ox.merge(
[
{id: 'showannotations', title: 'Show Annotations', disabled: true},
{group: 'range', min: 1, max: 1, items: [
{id: 'all', title: 'All', checked: self.options.range == 'all'},
{id: 'selection', title: 'In Current Selection', checked: self.options.range == 'selection'},
{id: 'position', title: 'At Current Position', checked: self.options.range == 'position'}
]},
{},
{id: 'sortannotations', title: 'Sort Annotations', disabled: true},
{group: 'sort', min: 1, max: 1, items: [
{id: 'position', title: 'By Position', checked: self.options.sort == 'position'},
{id: 'duration', title: 'By Duration', checked: self.options.sort == 'duration'},
{id: 'text', title: 'By Text', checked: self.options.sort == 'text'}
]}
],
self.options.showFonts ? [
{},
{id: 'fontsize', title: 'Font Size', disabled: true},
{group: 'font', min: 1, max: 1, items: [
{id: 'small', title: 'Small', checked: self.options.font == 'small'},
{id: 'medium', title: 'Medium', checked: self.options.font == 'medium'},
{id: 'large', title: 'Large', checked: self.options.font == 'large'}
]}
] : [],
self.options.showUsers ? [
{},
{id: 'users', title: 'Show Users', disabled: true},
{group: 'users', min: 1, max: -1, items: self.users.map(function(user) {
return {id: user, title: user, checked: true};
})}
] : []
),
style: 'square',
title: 'set',
tooltip: 'Actions and Settings',
type: 'image'
})
.css({float: 'left'})
2011-04-22 22:03:10 +00:00
.bindEvent({
2012-01-12 10:39:05 +00:00
change: function(data) {
var set = {};
if (data.id == 'users') {
self.enabledUsers = data.checked.length == self.users.length
? 'all'
: data.checked.map(function(checked) {
return checked.id;
});
self.$folder.forEach(function($folder) {
$folder.options({users: self.enabledUsers});
});
} else {
set[data.id] = data.checked[0].id;
self.$folder.forEach(function($folder) {
$folder.options(set);
});
that.triggerEvent('annotations' + data.id, set);
}
2012-01-12 19:04:32 +00:00
// FIXME: this does not work
self.options.selected && getFolder(self.options.selected).gainFocus();
2012-01-12 10:39:05 +00:00
}
})
2012-01-12 10:39:05 +00:00
.appendTo(self.$menubar);
if (self.options.editable) {
self.$editMenuButton = Ox.MenuButton({
items: [
{id: 'edit', title: 'Edit Annotation', disabled: !self.options.selected, keyboard: 'return'},
{id: 'delete', title: 'Delete Annotation', disabled: !self.options.selected, keyboard: 'delete'},
{id: 'deselect', title: 'Deselect Annotation', disabled: !self.options.selected, keyboard: 'escape'},
{},
{id: 'save', title: 'Save Changes', disabled: true, keyboard: 'shift return'},
2012-01-13 16:25:47 +00:00
{id: 'undo', title: 'Undo Changes', disabled: true, keyboard: 'escape'},
{},
{id: 'find', title: 'Find Annotation', disabled: true},
{id: 'manage', title: 'Edit Place/Event', disabled: true}
2012-01-12 10:39:05 +00:00
],
style: 'square',
title: 'edit',
tooltip: 'Editing Options',
type: 'image'
})
.css({float: 'right'})
.bindEvent({
click: function(data) {
if (data.id == 'delete') {
} else if (data.id == 'deselect') {
} else if (data.id == 'edit') {
}
}
})
2012-01-12 10:39:05 +00:00
.appendTo(self.$menubar);
}
self.$folders = Ox.Element().css({overflowY: 'auto'});
self.$folder = [];
self.options.layers.forEach(function(layer, i) {
var item = Ox.getObjectById(layer.items, self.options.selected),
selected = item ? item.id : '';
self.$folder[i] = Ox.AnnotationFolder(
Ox.extend({
collapsed: !self.options.showLayers[layer.id],
editable: self.options.editable,
font: self.options.font,
'in': self.options['in'],
out: self.options.out,
position: self.options.position,
range: self.options.range,
selected: selected,
sort: self.options.sort,
width: self.options.width - Ox.UI.SCROLLBAR_SIZE
2012-01-13 16:25:47 +00:00
}, layer, layer.type == 'event' ? {
showWidget: self.options.showCalendar,
widgetSize: self.options.calendarSize
} : layer.type == 'place' ? {
showWidget: self.options.showMap,
widgetSize: self.options.mapSize
} : {})
2012-01-12 10:39:05 +00:00
)
.bindEvent({
add: function(data) {
2012-01-12 10:39:05 +00:00
that.triggerEvent('add', Ox.extend({layer: layer.id}, data));
},
2012-01-09 20:25:38 +00:00
blur: function() {
that.triggerEvent('blur');
},
2012-01-15 15:05:17 +00:00
change: function(data) {
that.triggerEvent('change', Ox.extend({layer: layer.id}, data));
},
define: function(data) {
that.triggerEvent('define', data);
},
2012-01-09 20:25:38 +00:00
edit: function() {
2012-01-15 15:05:17 +00:00
that.triggerEvent('edit');
2012-01-12 10:39:05 +00:00
},
paused: function() {
that.triggerEvent('paused')
},
remove: function(data) {
2012-01-12 10:39:05 +00:00
that.triggerEvent('remove', Ox.extend({layer: layer.id}, data));
},
resizewidget: function(data) {
that.triggerEvent('resize' + (
layer.type == 'event' ? 'calendar' : 'map'
), data);
},
2012-01-12 10:39:05 +00:00
select: function(data) {
selectAnnotation(data, i);
},
submit: function(data) {
2012-01-15 15:05:17 +00:00
that.triggerEvent('submit', Ox.extend({layer: layer.id}, data));
},
togglelayer: function(data) {
2012-01-12 19:04:32 +00:00
that.triggerEvent('togglelayer', Ox.extend({layer: layer.id}, data));
},
togglewidget: function(data) {
that.triggerEvent('toggle' + (
layer.type == 'event' ? 'calendar' : 'map'
), data);
2012-01-12 10:39:05 +00:00
}
})
.appendTo(self.$folders);
});
that.setElement(
Ox.SplitPanel({
elements: [
{
element: self.$menubar,
size: 16
},
{
element: self.$folders
}
],
orientation: 'vertical'
})
);
function getFolder(annotationId) {
var found = false, folder;
Ox.forEach(self.options.layers, function(layer, i) {
Ox.forEach(layer.items, function(item) {
if (item.id == annotationId) {
folder = self.$folder[i];
found = true;
return false;
}
});
2012-01-12 10:39:05 +00:00
return !found;
});
2012-01-12 10:39:05 +00:00
return folder;
}
2012-01-17 09:25:58 +00:00
function scrollToSelected(type) {
var $item = that.find('.OxEditableElement.OxSelected'),
itemHeight = $item.height() + (type == 'text' ? 8 : 0),
itemTop = $item.offset().top,
itemBottom = itemTop + itemHeight,
height = self.$folders.height(),
scrollTop = self.$folders.scrollTop(),
top = self.$folders.offset().top;
if (itemTop < top || itemBottom > top + height) {
if (itemTop < top) {
scrollTop += itemTop - top;
} else {
scrollTop += itemBottom - top - height;
}
self.$folders.animate({
scrollTop: scrollTop + 'px'
}, 0);
}
}
2012-01-12 10:39:05 +00:00
function selectAnnotation(data, index) {
2012-01-17 09:25:58 +00:00
self.options.selected = data.id;
2012-01-12 10:39:05 +00:00
if (data.id) {
self.$folder.forEach(function($folder, i) {
i != index && $folder.options({selected: ''});
});
2012-01-17 09:25:58 +00:00
scrollToSelected(self.options.layers[index].type);
2012-01-12 10:39:05 +00:00
}
2012-01-17 09:25:58 +00:00
/*
2012-01-12 10:39:05 +00:00
if (data.top) {
2012-01-16 17:51:53 +00:00
data.bottom = data.top + data.height;
2012-01-12 10:39:05 +00:00
height = self.$folders.height();
2012-01-16 17:51:53 +00:00
top = self.$folders.offset().top;
2012-01-12 10:39:05 +00:00
scrollTop = self.$folders.scrollTop();
2012-01-16 17:51:53 +00:00
if (data.top < top || data.bottom > height) {
if (data.top < top) {
Ox.print('top scrollTop', data.top, scrollTop)
scrollTop += data.top - top;
} else {
scrollTop += data.bottom - top - height;
}
self.$folders.animate({
scrollTop: scrollTop + 'px'
}, 0);
}
2012-01-12 10:39:05 +00:00
}
2012-01-17 09:25:58 +00:00
*/
2012-01-12 10:39:05 +00:00
that.triggerEvent('select', data);
}
2012-01-12 10:39:05 +00:00
function updateEditMenu() {
var action = self.options.selected ? 'enableItem' : 'disableItem';
self.$editMenuButton[action]('edit');
self.$editMenuButton[action]('delete');
2011-04-22 22:03:10 +00:00
}
self.setOption = function(key, value) {
2012-01-12 10:39:05 +00:00
if (['in', 'out', 'position'].indexOf(key) > -1) {
self.$folder.forEach(function($folder) {
$folder.options(key, value);
});
2012-01-09 20:25:38 +00:00
} else if (key == 'selected') {
2012-01-12 10:39:05 +00:00
self.options.editable && updateEditMenu();
if (value) {
getFolder(value).options({selected: value});
} else {
self.$folder.forEach(function($folder) {
$folder.options({selected: ''});
2012-01-17 09:25:58 +00:00
});
2012-01-12 10:39:05 +00:00
}
2012-01-12 19:04:32 +00:00
} else if (key == 'width') {
self.$folder.forEach(function($folder) {
$folder.options({width: self.options.width - Ox.UI.SCROLLBAR_SIZE});
});
}
};
2012-01-12 10:39:05 +00:00
that.addItem = function(layer, item) {
2012-01-15 15:05:17 +00:00
Ox.print('ADD ITEM', layer, item);
2012-01-12 10:39:05 +00:00
var i = Ox.getIndexById(self.options.layers, layer);
self.$folder[i].addItem(item);
2011-06-15 14:36:01 +00:00
};
2011-04-22 22:03:10 +00:00
2012-01-09 20:25:38 +00:00
that.blurItem = function() {
2012-01-12 10:39:05 +00:00
getFolder(self.options.selected).blurItem();
2011-06-15 14:36:01 +00:00
};
2011-05-16 10:49:48 +00:00
2012-01-12 10:39:05 +00:00
that.editItem = function() {
getFolder(self.options.selected).editItem();
};
2011-05-19 10:18:39 +00:00
2012-01-15 15:05:17 +00:00
that.updateItem = function(item) {
Ox.print('UPDATE ITEM', item);
getFolder(item.id).updateItem(item);
2012-01-13 16:25:47 +00:00
};
2011-04-22 22:03:10 +00:00
return that;
2012-01-12 10:39:05 +00:00
2012-01-13 16:25:47 +00:00
};