openmedialibrary/static/js/transfersPanel.js

97 lines
3.0 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
oml.ui.transfersPanel = function() {
2014-05-04 17:26:43 +00:00
var ui = oml.user.ui,
$list = Ox.TableList({
columns: [
2015-04-20 07:52:44 +00:00
'id', 'title', 'extension', 'size',
2014-05-04 17:26:43 +00:00
'transferadded', 'transferprogress'
].map(function(id) {
var key = Ox.getObjectById(oml.config.itemKeys, id);
return {
align: Ox.contains([
'size', 'transferprogress'
], id) ? 'right' : 'left',
2016-01-17 10:23:50 +00:00
format: function(value) {
2016-01-17 10:29:00 +00:00
return Ox.encodeHTMLEntities(
(key.format || Ox.identity)(value)
);
2016-01-17 10:23:50 +00:00
},
2014-05-04 17:26:43 +00:00
id: id,
operator: oml.getSortOperator(id),
title: Ox._(key.title),
2015-04-20 07:52:44 +00:00
visible: id != 'id',
2014-05-04 17:26:43 +00:00
width: id == 'title' ? 240
2016-01-14 10:11:34 +00:00
: id == 'transferadded' ? 160
2014-05-18 23:24:04 +00:00
: id == 'transferprogress' ? 80 - Ox.UI.SCROLLBAR_SIZE
2014-05-04 17:26:43 +00:00
: key.columnWidth
};
}),
columnsVisible: true,
items: function(data, callback) {
Ox.Request.clearCache('find'); // FIXME: not ideal - and doesn't work
oml.api.find(Ox.extend(data, {
query: {
conditions: [{
key: 'mediastate',
operator: '==',
value: 'transferring'
}],
operator: '&'
}
}), callback);
},
keys: ['author'],
2014-05-18 23:24:04 +00:00
scrollbarVisible: true,
2015-04-20 08:08:36 +00:00
sort: [{key: 'transferadded', operator: '-'}],
2014-05-04 17:26:43 +00:00
unique: 'id'
}),
$item = Ox.Element(),
$cancelButton = Ox.Button({
2016-01-14 10:11:34 +00:00
style: 'squared',
2014-05-04 17:26:43 +00:00
title: 'Cancel Transfer...',
width: 128
})
.css({
margin: '8px'
})
.bindEvent({
click: function() {
2014-05-18 10:44:56 +00:00
var ids = $list.options('selected');
ids && ids.length && oml.api.cancelDownloads({
ids: ids
}, function() {
$list.reloadList(true);
});
2014-05-04 17:26:43 +00:00
}
})
.appendTo($item),
that = Ox.SplitPanel({
2014-05-04 17:26:43 +00:00
elements: [
{element: $list},
2016-01-14 10:11:34 +00:00
{element: $item, size: 144}
2014-05-04 17:26:43 +00:00
],
orientation: 'horizontal'
});
2014-05-04 17:26:43 +00:00
oml.bindEvent({
2015-03-22 14:04:42 +00:00
transfer: Ox.throttle(function(data) {
var current = $list.value(data.id);
if (
!Ox.isEmpty(current)
&& current.transferprogress != data.progress
) {
2015-04-20 07:52:44 +00:00
$list.value(data.id, 'transferprogress', data.progress);
2015-03-22 14:04:42 +00:00
}
2014-05-04 17:26:43 +00:00
}, 1000)
});
return that;
2014-05-18 10:44:56 +00:00
};