From 881956b4f4601b5f0cddf18db9b96bf8a5de3d47 Mon Sep 17 00:00:00 2001 From: rlx Date: Sun, 17 Jan 2016 16:04:38 +0530 Subject: [PATCH] transfer panel: fix cancel button --- static/js/transfersPanel.js | 104 ++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 46 deletions(-) diff --git a/static/js/transfersPanel.js b/static/js/transfersPanel.js index 9eb218d..b8dde9d 100644 --- a/static/js/transfersPanel.js +++ b/static/js/transfersPanel.js @@ -5,55 +5,68 @@ oml.ui.transfersPanel = function() { var ui = oml.user.ui, $list = Ox.TableList({ - columns: [ - 'id', 'title', 'extension', 'size', - 'transferadded', 'transferprogress' - ].map(function(id) { - var key = Ox.getObjectById(oml.config.itemKeys, id); - return { - align: Ox.contains([ - 'size', 'transferprogress' - ], id) ? 'right' : 'left', - format: function(value) { - return Ox.encodeHTMLEntities( - (key.format || Ox.identity)(value) - ); - }, - 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 - }; + columns: [ + 'id', 'title', 'extension', 'size', + 'transferadded', 'transferprogress' + ].map(function(id) { + var key = Ox.getObjectById(oml.config.itemKeys, id); + return { + align: Ox.contains([ + 'size', 'transferprogress' + ], id) ? 'right' : 'left', + format: function(value) { + return Ox.encodeHTMLEntities( + (key.format || Ox.identity)(value) + ); + }, + 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...' + ) + }); + } }), - 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(), $cancelButton = Ox.Button({ + disabled: true, style: 'squared', - title: 'Cancel Transfer...', + title: Ox._('Cancel Transfer...'), width: 128 }) .css({ @@ -61,9 +74,8 @@ oml.ui.transfersPanel = function() { }) .bindEvent({ click: function() { - var ids = $list.options('selected'); - ids && ids.length && oml.api.cancelDownloads({ - ids: ids + oml.api.cancelDownloads({ + ids: $list.options('selected') }, function() { $list.reloadList(true); });