make annotations sortable

This commit is contained in:
rlx 2012-01-11 16:41:13 +05:30
parent 11d9b63dba
commit 43d04f242d
2 changed files with 22 additions and 18 deletions

View file

@ -16,6 +16,7 @@ Ox.ArrayEditable = function(options, self) {
items: [],
position: -1,
selected: '',
sort: [],
submitOnBlur: true,
type: 'input',
width: 256
@ -106,7 +107,11 @@ Ox.ArrayEditable = function(options, self) {
function renderItems() {
that.empty();
self.options.items.forEach(function(item, i) {
(
Ox.isEmpty(self.options.sort)
? self.options.items
: Ox.sortBy(self.options.items, self.options.sort)
).forEach(function(item, i) {
i && self.options.type == 'input'
&& $('<span>')
.html(', ')
@ -216,6 +221,8 @@ Ox.ArrayEditable = function(options, self) {
renderItems();
} else if (key == 'selected') {
selectItem(value);
} else if (key == 'sort') {
renderItems();
}
}

View file

@ -39,19 +39,7 @@ Ox.AnnotationPanel = function(options, self) {
})
.options(options || {});
self.sort = self.options.sort == 'duration' ? [
{key: 'duration', operator: '-'},
{key: 'position', operator: '+'},
{key: 'value', operator: '+'}
] : self.options.sort == 'position' ? [
{key: 'position', operator: '+'},
{key: 'duration', operator: '-'},
{key: 'value', operator: '+'}
] : [ // 'text'
{key: 'value', operator: '+'},
{key: 'position', operator: '+'},
{key: 'duration', operator: '-'}
];
self.sort = getSort();
that.setElement(
Ox.CollapsePanel({
@ -132,6 +120,14 @@ Ox.AnnotationPanel = function(options, self) {
});
}
function getSort() {
return ({
duration: ['-duration', '+in', '+value'],
position: ['+in', '-duration', '+value'],
text: ['+value', '+in', '-duration']
})[self.options.sort];
}
function selectAnnotation(data) {
var item = Ox.getObjectById(self.options.items, data.id);
self.options.selected = item ? data.id : '';
@ -156,9 +152,9 @@ Ox.AnnotationPanel = function(options, self) {
self.setOption = function(key, value) {
if (['in', 'out'].indexOf(key) > -1 && self.editing) {
var item = Ox.getObjectById(self.options.items, self.options.selected);
items[key] = value;
items.duration = self.options.out - self.options['in'];
var index = Ox.getIndexById(self.options.items, self.options.selected);
self.options.items[index][key] = value;
self.options.items[index].duration = self.options.out - self.options['in'];
}
if (key == 'in') {
//fixme: array editable should support item updates while editing
@ -180,7 +176,8 @@ Ox.AnnotationPanel = function(options, self) {
} else if (key == 'selected') {
self.$annotations.options('selected', value);
} else if (key == 'sort') {
self.$annotations.options('sort', value);
self.sort = getSort();
self.$annotations.options('sort', self.sort);
}
};