openmedialibrary/static/js/transfersPanel.js

112 lines
3.8 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({
2016-01-17 10:34:38 +00:00
columns: [
'id', 'title', 'extension', 'size',
'transferadded', 'transferprogress'
].map(function(id) {
var key = Ox.getObjectById(oml.config.itemKeys, id);
2016-01-17 10:34:38 +00:00
return {
align: Ox.contains([
'size', 'transferprogress'
], id) ? 'right' : 'left',
format: function(value) {
return Ox.encodeHTMLEntities(key.format
? Ox['format' + Ox.toTitleCase(key.format.type)].apply(
this, [value].concat(key.format.args || [])
)
: Ox.isArray(key.type) ? (value || []).join(', ')
: (value || ''));
2016-01-17 10:34:38 +00:00
},
id: id,
operator: oml.getSortOperator(id),
title: Ox._(key.title),
visible: id != 'id',
width: id == 'title' ? 240
: id == 'transferadded' ? 160
: id == 'transferprogress' ? 80 - Ox.UI.SCROLLBAR_SIZE
: 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'],
scrollbarVisible: true,
sort: [{key: 'transferadded', operator: '-'}],
unique: 'id'
})
.bindEvent({
select: function(data) {
$cancelButton.options({
disabled: data.ids.length == 0,
title: Ox._(
data.ids.length < 2
? 'Cancel Transfer...'
: 'Cancel Transfers...'
)
});
}
2014-05-04 17:26:43 +00:00
}),
$item = Ox.Element(),
$cancelButton = Ox.Button({
2016-01-17 10:34:38 +00:00
disabled: true,
2016-01-14 10:11:34 +00:00
style: 'squared',
2016-01-17 10:34:38 +00:00
title: Ox._('Cancel Transfer...'),
2014-05-04 17:26:43 +00:00
width: 128
})
.css({
margin: '8px'
})
.bindEvent({
click: function() {
2016-01-17 10:34:38 +00:00
oml.api.cancelDownloads({
ids: $list.options('selected')
2014-05-18 10:44:56 +00:00
}, 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
};