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

213 lines
6.2 KiB
JavaScript
Raw Normal View History

2011-07-29 18:48:43 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-05-16 08:24:46 +00:00
2011-11-05 16:46:53 +00:00
'use strict';
2011-05-16 08:24:46 +00:00
/*@
Ox.AnnotationPanel <f:Ox.Element> AnnotationPanel Object
() -> <f> AnnotationPanel Object
(options) -> <f> AnnotationPanel Object
(options, self) -> <f> AnnotationPanel Object
options <o> Options object
editable <b|false> If true, annotations can be added
2011-05-16 10:49:48 +00:00
id <s> id
items <a|[]> items
2011-05-19 10:18:39 +00:00
title <s> title
type <s|'text'> panel type
2011-05-16 10:49:48 +00:00
width <n|0>
2011-05-16 08:24:46 +00:00
self <o> shared private variable
@*/
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({
editable: false,
2012-01-02 14:05:14 +00:00
id: '',
items: [],
range: 'all',
2012-01-02 14:05:14 +00:00
title: '',
type: 'text',
width: 0
})
.options(options || {});
2011-04-22 22:03:10 +00:00
self.selected = -1;
that.setElement(
Ox.CollapsePanel({
2011-04-22 22:03:10 +00:00
collapsed: false,
2011-05-19 12:37:19 +00:00
extras: self.options.editable ? [
Ox.Button({
2011-04-22 22:03:10 +00:00
id: 'add',
style: 'symbol',
2011-05-19 10:18:39 +00:00
title: 'add',
tooltip: 'Add',
2011-04-22 22:03:10 +00:00
type: 'image'
}).bindEvent({
click: function(data) {
2011-04-22 22:03:10 +00:00
that.triggerEvent('add', {value: ''});
}
})
2011-05-19 12:37:19 +00:00
] : [],
2011-04-22 22:03:10 +00:00
size: 16,
title: self.options.title
})
.addClass('OxAnnotationPanel')
.bindEvent({
toggle: togglePanel
})
);
2011-04-22 22:03:10 +00:00
that.$content = that.$element.$content;
self.$annotations = Ox.List({
2011-04-22 22:03:10 +00:00
construct: function(data) {
2011-10-27 13:13:28 +00:00
var $item = Ox.Element()
2012-01-02 14:05:14 +00:00
.addClass('OxAnnotation OxTarget')
.css({padding: '4px 4px 0 4px'})
2011-10-27 13:13:28 +00:00
.append(
Ox.Editable({
type: 'textarea',
width: self.options.width - 8,
value: data.value
})
.bindEvent({
edit: function() {
$item.removeClass('OxTarget');
},
2012-01-03 10:26:15 +00:00
submit: function(newData) {
$item.addClass('OxTarget');
updateAnnotation({
id: data.id,
value: newData.value
});
2011-10-27 13:13:28 +00:00
}
})
)
2012-01-02 14:05:14 +00:00
.append($('<div>').css({height: '4px'}));
2011-10-27 13:13:28 +00:00
return $item;
2011-04-22 22:03:10 +00:00
},
items: getAnnotations(),
2011-10-27 13:13:28 +00:00
max: 1,
min: 0,
sort: [{key: 'in', operator: '+'}],
type: 'none', // fixme
2011-04-22 22:03:10 +00:00
unique: 'id'
})
.bindEvent({
2011-06-15 14:36:01 +00:00
cancel: function(item) {
//reset in/out points
selectAnnotation({}, {ids: [item.id]});
2011-05-19 10:18:39 +00:00
},
open: function(data) {
2011-10-27 13:13:28 +00:00
return;
2011-04-22 22:03:10 +00:00
if (data.ids.length == 1) {
var pos = Ox.getPositionById(self.$annotations.options('items'), data.ids[0]);
self.$annotations.editItem(pos);
}
},
2012-01-03 10:26:15 +00:00
'delete': function(data) {
that.triggerEvent('remove', {id: data.ids[0]});
2011-04-22 22:03:10 +00:00
},
select: selectAnnotation,
submit: updateAnnotation
})
.appendTo(that.$content);
/*
self.$annotations = Ox.Element()
2011-04-22 22:03:10 +00:00
.appendTo(that.$content);
self.$annotation = [];
self.options.items.forEach(function(item, i) {
self.$annotation[i] = Ox.Element()
2011-04-22 22:03:10 +00:00
.addClass('OxAnnotation')
.html(item.value.replace(/\n/g, '<br/>'))
.click(function() {
clickAnnotation(i);
})
.appendTo(self.$annotations);
});
*/
function getAnnotations() {
return self.options.items.filter(function(item) {
return self.options.range == 'all' || (
self.options.range == 'selection'
&& item['in'] < self.options.out
&& item.out > self.options['in']
) || (
self.options.range == 'position'
&& item['in'] <= self.options.position
&& item.out > self.options.position
);
});
}
function selectAnnotation(data) {
2011-04-22 22:03:10 +00:00
var item = Ox.getObjectById(self.options.items, data.ids[0]);
2011-06-15 14:36:01 +00:00
item && that.triggerEvent('select', {
2011-04-22 22:03:10 +00:00
'in': item['in'],
'out': item.out,
'layer': self.options.id
});
}
function updateAnnotation(data) {
2012-01-03 10:26:15 +00:00
Ox.print('updateAnnotation', data);
2011-04-22 22:03:10 +00:00
var item = Ox.getObjectById(self.options.items, data.id);
item.value = data.value;
that.triggerEvent('submit', item);
}
function togglePanel() {
}
self.setOption = function(key, value) {
if (key == 'in') {
self.options.range == 'selection' && self.$annotations.options({
items: getAnnotations()
});
} else if (key == 'out') {
self.options.range == 'selection' && self.$annotations.options({
items: getAnnotations()
});
} else if (key == 'position') {
self.options.range == 'position' && self.$annotations.options({
items: getAnnotations()
});
} else if (key == 'range') {
self.$annotations.options({
items: getAnnotations()
});
}
};
2011-05-16 10:49:48 +00:00
/*@
addItem <f> addItem
@*/
2011-04-22 22:03:10 +00:00
that.addItem = function(item) {
var pos = 0;
self.options.items.splice(pos, 0, item);
self.$annotations.addItems(pos, [item]);
self.$annotations.editItem(pos);
2011-06-15 14:36:01 +00:00
};
2011-04-22 22:03:10 +00:00
2011-05-16 10:49:48 +00:00
/*@
2012-01-03 10:26:15 +00:00
deselectItems <f> deselectItems
2011-05-16 10:49:48 +00:00
@*/
2012-01-03 10:26:15 +00:00
that.deselectItems = function() {
self.$annotations.options('selected', []);
2011-06-15 14:36:01 +00:00
};
2011-05-16 10:49:48 +00:00
/*@
2012-01-03 10:26:15 +00:00
removeItems <f> removeItems
2011-05-16 10:49:48 +00:00
@*/
2012-01-03 10:26:15 +00:00
that.removeItem = function(id) {
self.$annotations.removeItems([id]);
};
2011-05-19 10:18:39 +00:00
2011-04-22 22:03:10 +00:00
return that;
};