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

310 lines
8.8 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: [],
editable: false,
'in': 0,
out: 0,
position: 0,
selected: '',
sort: [],
sortOptions: [],
view: 'list',
width: 0
})
.options(options || {})
.update({
clips: function() {
self.$list.options({items: self.options.clips});
}
});
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 10:24:38 +00:00
that.triggerEvent('sort', [{
2013-07-13 23:07:25 +00:00
key: data.value,
operator: Ox.getObjectById(
self.options.sortOptions, data.value
).operator
2013-07-14 10:24:38 +00:00
}]);
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 10:24:38 +00:00
that.triggerEvent('sort', [{
2013-07-13 23:07:25 +00:00
key: self.options.sort[0].key,
operator: self.options.sort[0].operator == '+' ? '-' : '+'
2013-07-14 10:24:38 +00:00
}]);
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
});
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'
})
);
function cutClips() {
}
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,
items: self.options.clips,
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();
2013-07-13 23:07:25 +00:00
2013-07-14 11:39:20 +00:00
$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) {
self.options.sort = self.$list.options('sort');
self.$list.options({sortable: isSortable()});
that.triggerEvent('sort', data);
},
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() {
return self.options.editable && self.options.sort[0].key == 'index';
}
function moveClips(data) {
Ox.Request.clearCache();
pandora.api.sortClips({
edit: pandora.user.ui.edit,
ids: data.ids
})
}
function openClips(data) {
}
function pasteClips() {
}
function removeClips() {
}
function updateSortElement() {
}
that.updateItem = function(id, data) {
['in', 'out', 'duration'].forEach(function(key) {
self.$list.value(id, key, data[key]);
});
};
return that;
};