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') {
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'
},

View file

@ -253,7 +253,7 @@ oml.createLinks = function($element) {
}, function(result) {
Ox.Request.clearCache();
callback(result, addedItems);
});
});
} else {
callback(null, []);
}