From 5110410edaea4dc41d69bf5b72aa754964667a7d Mon Sep 17 00:00:00 2001 From: j Date: Sat, 16 Jan 2016 12:05:23 +0530 Subject: [PATCH] Edit->Download should only be enabled if selected books are not available, fixes #59 --- static/js/mainMenu.js | 23 ++++++++++++++--------- static/js/utils.js | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/static/js/mainMenu.js b/static/js/mainMenu.js index 23c541e..7c7014b 100644 --- a/static/js/mainMenu.js +++ b/static/js/mainMenu.js @@ -479,12 +479,16 @@ oml.ui.mainMenu = function() { } else if (id == 'advancedfind') { oml.$ui.findDialog = oml.ui.findDialog().open(); } else if (id == 'download') { - // FIXME: what is this?? - if (oml.user.ui.item) { - document.location.href = '/' + oml.user.ui.item + '/get/'; - } else { - Ox.print('no way to download multiple right now'); - } + var ids = (ui.item ? [ui.item] : ui.listSelection).filter(function(id) { + return oml.$ui.list && oml.$ui.list.value(id, 'mediastate') == 'unavailable' + }); + ids.length && oml.api.addListItems({ + items: ids, + list: ':' + }, function(result) { + Ox.Request.clearCache(); + //FIXME: reload? + }); } else { Ox.print('MAIN MENU DOES NOT YET HANDLE', id); } @@ -624,7 +628,6 @@ oml.ui.mainMenu = function() { function getEditMenu() { var listData = oml.getListData(), - username = oml.user.preferences.username, selectionItems = ui.listSelection.length, selectionItemName = ( selectionItems > 1 ? Ox.formatNumber(selectionItems) + ' ' : '' @@ -639,7 +642,9 @@ oml.ui.mainMenu = function() { clipboardItems > 1 ? Ox.formatNumber(clipboardItems) + ' ' : '' ) + Ox._(clipboardItems == 1 ? 'Book' : 'Books'), canSelect = !ui.item, - canDownload = listData.user != username && selectionItems, + canDownload = ui.listSelection.filter(function(id) { + return oml.$ui.list && oml.$ui.list.value(id, 'mediastate') == 'unavailable' + }).length, canCopy = canSelect && selectionItems, canCut = canCopy && listData.editable, canPaste = listData.editable && clipboardItems, @@ -683,7 +688,7 @@ oml.ui.mainMenu = function() { {}, { id: 'download', - title: Ox._('Download {0}', [selectionItemName]), + title: Ox._('Download {0}', [canDownload]), disabled: !canDownload, keyboard: 'control d' }, diff --git a/static/js/utils.js b/static/js/utils.js index a838e53..260c0d7 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -253,7 +253,7 @@ oml.createLinks = function($element) { }, function(result) { Ox.Request.clearCache(); callback(result, addedItems); - }); + }); } else { callback(null, []); }