Edit->Download should only be enabled if selected books are not available, fixes #59

This commit is contained in:
j 2016-01-16 12:05:23 +05:30
parent 249b8628d2
commit 5110410eda
2 changed files with 15 additions and 10 deletions

View file

@ -479,12 +479,16 @@ oml.ui.mainMenu = function() {
} else if (id == 'advancedfind') { } else if (id == 'advancedfind') {
oml.$ui.findDialog = oml.ui.findDialog().open(); oml.$ui.findDialog = oml.ui.findDialog().open();
} else if (id == 'download') { } else if (id == 'download') {
// FIXME: what is this?? var ids = (ui.item ? [ui.item] : ui.listSelection).filter(function(id) {
if (oml.user.ui.item) { return oml.$ui.list && oml.$ui.list.value(id, 'mediastate') == 'unavailable'
document.location.href = '/' + oml.user.ui.item + '/get/'; });
} else { ids.length && oml.api.addListItems({
Ox.print('no way to download multiple right now'); items: ids,
} list: ':'
}, function(result) {
Ox.Request.clearCache();
//FIXME: reload?
});
} else { } else {
Ox.print('MAIN MENU DOES NOT YET HANDLE', id); Ox.print('MAIN MENU DOES NOT YET HANDLE', id);
} }
@ -624,7 +628,6 @@ oml.ui.mainMenu = function() {
function getEditMenu() { function getEditMenu() {
var listData = oml.getListData(), var listData = oml.getListData(),
username = oml.user.preferences.username,
selectionItems = ui.listSelection.length, selectionItems = ui.listSelection.length,
selectionItemName = ( selectionItemName = (
selectionItems > 1 ? Ox.formatNumber(selectionItems) + ' ' : '' selectionItems > 1 ? Ox.formatNumber(selectionItems) + ' ' : ''
@ -639,7 +642,9 @@ oml.ui.mainMenu = function() {
clipboardItems > 1 ? Ox.formatNumber(clipboardItems) + ' ' : '' clipboardItems > 1 ? Ox.formatNumber(clipboardItems) + ' ' : ''
) + Ox._(clipboardItems == 1 ? 'Book' : 'Books'), ) + Ox._(clipboardItems == 1 ? 'Book' : 'Books'),
canSelect = !ui.item, 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, canCopy = canSelect && selectionItems,
canCut = canCopy && listData.editable, canCut = canCopy && listData.editable,
canPaste = listData.editable && clipboardItems, canPaste = listData.editable && clipboardItems,
@ -683,7 +688,7 @@ oml.ui.mainMenu = function() {
{}, {},
{ {
id: 'download', id: 'download',
title: Ox._('Download {0}', [selectionItemName]), title: Ox._('Download {0}', [canDownload]),
disabled: !canDownload, disabled: !canDownload,
keyboard: 'control d' keyboard: 'control d'
}, },