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

331 lines
9.9 KiB
JavaScript
Raw Normal View History

2013-07-13 23:07:25 +00:00
'use strict';
Ox.ClipPanel = function(options, self) {
self = self || {};
var that = Ox.Element({}, self)
.defaults({
clips: [],
2013-07-14 18:58:31 +00:00
duration: 0,
2013-07-13 23:07:25 +00:00
editable: false,
'in': 0,
out: 0,
position: 0,
selected: '',
sort: [],
sortOptions: [],
view: 'list',
width: 0
})
.options(options || {})
.update({
clips: function() {
2013-07-14 14:56:41 +00:00
self.$list.options({
items: Ox.clone(self.options.clips),
sort: self.options.sort,
sortable: isSortable()
});
2013-07-14 18:58:31 +00:00
updateStatus();
2013-07-14 14:56:41 +00:00
},
2013-07-14 18:58:31 +00:00
duration: updateStatus,
2013-07-14 14:56:41 +00:00
sort: function() {
updateSortElement();
self.$list.options({
sort: self.options.sort,
sortable: isSortable(),
});
2013-07-13 23:07:25 +00:00
}
});
self.$menubar = Ox.Bar({
size: 24
})
.bindEvent({
doubleclick: function(e) {
if ($(e.target).is('.OxBar')) {
self.$list.animate({scrollTop: 0}, 250);
}
}
});
2013-07-14 10:24:38 +00:00
self.$menu = Ox.MenuButton({
items: [
{group: 'view', min: 1, max: 1, items: [
{id: 'list', title: Ox._('View as List'), checked: self.options.view == 'list'},
{id: 'grid', title: Ox._('View as Grid'), checked: self.options.view == 'grid'},
]},
{},
{id: 'split', title: 'Split Clip(s) at Cuts', disabled: true},
{id: 'join', title: 'Join Clip(s) at Cuts', disabled: true},
{id: 'dereference', title: 'Make Clip(s) Static', disabled: true}
2013-07-13 23:07:25 +00:00
],
2013-07-14 10:24:38 +00:00
title: 'set',
tooltip: Ox._('Options'),
type: 'image'
2013-07-13 23:07:25 +00:00
})
.css({
float: 'left',
margin: '4px 2px 4px 4px'
})
.bindEvent({
change: function(data) {
2013-07-14 10:24:38 +00:00
if (data.id == 'view') {
2013-07-14 11:39:20 +00:00
self.options.view = data.checked[0].id;
self.$panel.replaceElement(1, self.$list = getList());
self.$panel.triggerEvent('view', {view: self.options.view});
2013-07-14 10:24:38 +00:00
}
},
click: function(data) {
2013-07-13 23:07:25 +00:00
}
})
2013-07-14 10:24:38 +00:00
.appendTo(self.$menubar),
2013-07-13 23:07:25 +00:00
self.$sortSelect = Ox.Select({
items: self.options.sortOptions,
value: self.options.sort[0].key,
2013-07-14 10:24:38 +00:00
width: 100 + Ox.UI.SCROLLBAR_SIZE
2013-07-13 23:07:25 +00:00
})
.bindEvent({
change: function(data) {
2013-07-14 14:56:41 +00:00
self.options.sort = [{
2013-07-13 23:07:25 +00:00
key: data.value,
operator: Ox.getObjectById(
self.options.sortOptions, data.value
).operator
2013-07-14 14:56:41 +00:00
}];
updateSortElement();
that.triggerEvent('sort', self.options.sort);
2013-07-13 23:07:25 +00:00
}
});
self.$orderButton = Ox.Button({
overlap: 'left',
title: getButtonTitle(),
tooltip: getButtonTooltip(),
type: 'image'
})
.bindEvent({
click: function() {
2013-07-14 14:56:41 +00:00
self.options.sort = [{
2013-07-13 23:07:25 +00:00
key: self.options.sort[0].key,
operator: self.options.sort[0].operator == '+' ? '-' : '+'
2013-07-14 14:56:41 +00:00
}];
updateSortElement();
that.triggerEvent('sort', self.options.sort);
2013-07-13 23:07:25 +00:00
}
});
self.$sortElement = Ox.FormElementGroup({
elements: [self.$sortSelect, self.$orderButton],
float: 'right'
})
.css({
float: 'right',
margin: '4px 4px 4px 2px'
})
.appendTo(self.$menubar);
2013-07-14 10:24:38 +00:00
self.$list = getList();
self.$statusbar = Ox.Bar({
size: 16
});
2013-07-14 18:58:31 +00:00
self.$status = Ox.Element()
.css({
marginTop: '2px',
fontSize: '9px',
textAlign: 'center',
textOverflow: 'ellipsis'
})
.appendTo(self.$statusbar);
2013-07-14 10:24:38 +00:00
that.setElement(
2013-07-14 11:39:20 +00:00
self.$panel = Ox.SplitPanel({
2013-07-14 10:24:38 +00:00
elements: [
{
element: self.$menubar,
size: 24
},
{
element: self.$list
},
{
element: self.$statusbar,
size: 16
}
],
orientation: 'vertical'
})
);
2013-07-14 18:58:31 +00:00
updateStatus();
2013-07-14 10:24:38 +00:00
function editClip(data) {
var value = self.$list.value(data.id, data.key);
if (data.value != value && !(data.value === '' && value === null)) {
self.$list.value(data.id, data.key, data.value || null);
that.triggerEvent('edit', data);
}
}
function getButtonTitle() {
return self.options.sort[0].operator == '+' ? 'up' : 'down';
}
function getButtonTooltip() {
return Ox._(self.options.sort[0].operator == '+' ? 'Ascending' : 'Descending');
}
function getList() {
var $list = self.options.view == 'list' ? Ox.TableList({
2013-07-13 23:07:25 +00:00
columns: [
{
align: 'right',
id: 'index',
operator: '+',
title: Ox._('Index'),
visible: false,
width: 60
},
{
id: 'id',
operator: '+',
title: Ox._('ID'),
unique: true,
visible: false,
width: 60
},
{
id: 'item',
operator: '+',
title: Ox._(pandora.site.itemName.singular),
visible: true,
width: 60
},
{
align: 'right',
editable: isEditable,
format: function(value) {
return Ox.formatDuration(value, 3);
},
id: 'in',
operator: '+',
title: Ox._('In'),
visible: true,
width: 90
},
{
align: 'right',
editable: isEditable,
format: function(value) {
return Ox.formatDuration(value, 3);
},
id: 'out',
operator: '+',
title: Ox._('Out'),
visible: true,
width: 90
},
{
align: 'right',
editable: isEditable,
format: function(value) {
return Ox.formatDuration(value, 3);
},
id: 'duration',
operator: '+',
title: Ox._('Duration'),
visible: true,
width: 90
}
],
columnsMovable: true,
columnsRemovable: true,
columnsResizable: true,
columnsVisible: true,
2013-07-14 14:56:41 +00:00
items: Ox.clone(self.options.clips),
2013-07-13 23:07:25 +00:00
scrollbarVisible: true,
sort: self.options.sort,
2013-07-14 10:39:32 +00:00
sortable: isSortable(),
2013-07-13 23:07:25 +00:00
unique: 'id'
2013-07-14 11:39:20 +00:00
}) : Ox.Element();
$list.bindEvent({
copy: function(data) {
that.triggerEvent('copy', data);
},
cut: function(data) {
that.triggerEvent('cut', data);
},
'delete': function(data) {
that.triggerEvent('remove', data);
},
move: function(data) {
data.ids.forEach(function(id, index) {
self.$list.value(id, 'index', index);
});
that.triggerEvent('move', data);
},
open: function(data) {
that.triggerEvent('open', data);
},
paste: function() {
that.triggerEvent('paste');
},
select: function(data) {
that.triggerEvent('select', data);
},
sort: function(data) {
2013-07-14 14:56:41 +00:00
self.options.sort = [data];
updateSortElement();
2013-07-14 11:39:20 +00:00
self.$list.options({sortable: isSortable()});
2013-07-14 14:56:41 +00:00
that.triggerEvent('sort', self.options.sort);
2013-07-14 11:39:20 +00:00
},
submit: function(data) {
data.value = Ox.parseDuration(data.value);
self.$list.value(data.id, data.key, data.value);
that.triggerEvent('edit', data);
}
});
return $list;
2013-07-13 23:07:25 +00:00
}
function isEditable(data) {
return self.options.editable && !data.annotation;
}
function isSortable() {
2013-07-14 13:48:41 +00:00
return self.options.editable
&& self.options.sort && self.options.sort.length
&& self.options.sort[0].key == 'index'
&& self.options.sort[0].operator == '+';
2013-07-13 23:07:25 +00:00
}
function updateSortElement() {
2013-07-14 14:56:41 +00:00
self.$sortSelect.options({
value: self.options.sort[0].key,
});
self.$orderButton.options({
title: getButtonTitle(),
tooltip: getButtonTooltip(),
});
2013-07-13 23:07:25 +00:00
}
2013-07-14 18:58:31 +00:00
function updateStatus() {
self.$status.html(
Ox.toTitleCase(Ox.formatCount(self.options.clips.length, 'Clip'))
+ ', ' + Ox.formatDuration(self.options.duration, 3)
);
}
2013-07-13 23:07:25 +00:00
that.updateItem = function(id, data) {
['in', 'out', 'duration'].forEach(function(key) {
self.$list.value(id, key, data[key]);
});
};
return that;
};