make annotations sortable
This commit is contained in:
parent
11d9b63dba
commit
43d04f242d
2 changed files with 22 additions and 18 deletions
|
@ -16,6 +16,7 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
items: [],
|
items: [],
|
||||||
position: -1,
|
position: -1,
|
||||||
selected: '',
|
selected: '',
|
||||||
|
sort: [],
|
||||||
submitOnBlur: true,
|
submitOnBlur: true,
|
||||||
type: 'input',
|
type: 'input',
|
||||||
width: 256
|
width: 256
|
||||||
|
@ -106,7 +107,11 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
|
|
||||||
function renderItems() {
|
function renderItems() {
|
||||||
that.empty();
|
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'
|
i && self.options.type == 'input'
|
||||||
&& $('<span>')
|
&& $('<span>')
|
||||||
.html(', ')
|
.html(', ')
|
||||||
|
@ -216,6 +221,8 @@ Ox.ArrayEditable = function(options, self) {
|
||||||
renderItems();
|
renderItems();
|
||||||
} else if (key == 'selected') {
|
} else if (key == 'selected') {
|
||||||
selectItem(value);
|
selectItem(value);
|
||||||
|
} else if (key == 'sort') {
|
||||||
|
renderItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,19 +39,7 @@ Ox.AnnotationPanel = function(options, self) {
|
||||||
})
|
})
|
||||||
.options(options || {});
|
.options(options || {});
|
||||||
|
|
||||||
self.sort = self.options.sort == 'duration' ? [
|
self.sort = getSort();
|
||||||
{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: '-'}
|
|
||||||
];
|
|
||||||
|
|
||||||
that.setElement(
|
that.setElement(
|
||||||
Ox.CollapsePanel({
|
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) {
|
function selectAnnotation(data) {
|
||||||
var item = Ox.getObjectById(self.options.items, data.id);
|
var item = Ox.getObjectById(self.options.items, data.id);
|
||||||
self.options.selected = item ? data.id : '';
|
self.options.selected = item ? data.id : '';
|
||||||
|
@ -156,9 +152,9 @@ Ox.AnnotationPanel = function(options, self) {
|
||||||
|
|
||||||
self.setOption = function(key, value) {
|
self.setOption = function(key, value) {
|
||||||
if (['in', 'out'].indexOf(key) > -1 && self.editing) {
|
if (['in', 'out'].indexOf(key) > -1 && self.editing) {
|
||||||
var item = Ox.getObjectById(self.options.items, self.options.selected);
|
var index = Ox.getIndexById(self.options.items, self.options.selected);
|
||||||
items[key] = value;
|
self.options.items[index][key] = value;
|
||||||
items.duration = self.options.out - self.options['in'];
|
self.options.items[index].duration = self.options.out - self.options['in'];
|
||||||
}
|
}
|
||||||
if (key == 'in') {
|
if (key == 'in') {
|
||||||
//fixme: array editable should support item updates while editing
|
//fixme: array editable should support item updates while editing
|
||||||
|
@ -180,7 +176,8 @@ Ox.AnnotationPanel = function(options, self) {
|
||||||
} else if (key == 'selected') {
|
} else if (key == 'selected') {
|
||||||
self.$annotations.options('selected', value);
|
self.$annotations.options('selected', value);
|
||||||
} else if (key == 'sort') {
|
} else if (key == 'sort') {
|
||||||
self.$annotations.options('sort', value);
|
self.sort = getSort();
|
||||||
|
self.$annotations.options('sort', self.sort);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue