transfer panel: fix cancel button

This commit is contained in:
rlx 2016-01-17 16:04:38 +05:30
parent 36be2bb3b2
commit 881956b4f4

View file

@ -5,55 +5,68 @@ oml.ui.transfersPanel = function() {
var ui = oml.user.ui, var ui = oml.user.ui,
$list = Ox.TableList({ $list = Ox.TableList({
columns: [ columns: [
'id', 'title', 'extension', 'size', 'id', 'title', 'extension', 'size',
'transferadded', 'transferprogress' 'transferadded', 'transferprogress'
].map(function(id) { ].map(function(id) {
var key = Ox.getObjectById(oml.config.itemKeys, id); var key = Ox.getObjectById(oml.config.itemKeys, id);
return { return {
align: Ox.contains([ align: Ox.contains([
'size', 'transferprogress' 'size', 'transferprogress'
], id) ? 'right' : 'left', ], id) ? 'right' : 'left',
format: function(value) { format: function(value) {
return Ox.encodeHTMLEntities( return Ox.encodeHTMLEntities(
(key.format || Ox.identity)(value) (key.format || Ox.identity)(value)
); );
}, },
id: id, id: id,
operator: oml.getSortOperator(id), operator: oml.getSortOperator(id),
title: Ox._(key.title), title: Ox._(key.title),
visible: id != 'id', visible: id != 'id',
width: id == 'title' ? 240 width: id == 'title' ? 240
: id == 'transferadded' ? 160 : id == 'transferadded' ? 160
: id == 'transferprogress' ? 80 - Ox.UI.SCROLLBAR_SIZE : id == 'transferprogress' ? 80 - Ox.UI.SCROLLBAR_SIZE
: key.columnWidth : 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...'
)
});
}
}), }),
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'
}),
$item = Ox.Element(), $item = Ox.Element(),
$cancelButton = Ox.Button({ $cancelButton = Ox.Button({
disabled: true,
style: 'squared', style: 'squared',
title: 'Cancel Transfer...', title: Ox._('Cancel Transfer...'),
width: 128 width: 128
}) })
.css({ .css({
@ -61,9 +74,8 @@ oml.ui.transfersPanel = function() {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
var ids = $list.options('selected'); oml.api.cancelDownloads({
ids && ids.length && oml.api.cancelDownloads({ ids: $list.options('selected')
ids: ids
}, function() { }, function() {
$list.reloadList(true); $list.reloadList(true);
}); });