correctly handle download/edit/delete for selections with mixed mediastate

This commit is contained in:
rlx 2016-01-16 12:49:08 +05:30
parent 6838a2f0f2
commit 5882e97608
4 changed files with 51 additions and 29 deletions

View file

@ -4,7 +4,9 @@ oml.ui.deleteItemsDialog = function() {
var ui = oml.user.ui, var ui = oml.user.ui,
items = ui.listSelection, items = ui.listSelection.filter(function(id) {
return oml.$ui.list.value(id, 'mediastate') == 'available';
}),
itemsName = Ox._(items.length == 1 ? 'Item' : 'Items'), itemsName = Ox._(items.length == 1 ? 'Item' : 'Items'),
theseItemsName = items.length == 1 theseItemsName = items.length == 1
? Ox._('this item') ? Ox._('this item')

View file

@ -7,7 +7,9 @@ oml.ui.editDialog = function() {
'author', 'place', 'publisher', 'language' 'author', 'place', 'publisher', 'language'
], ],
hasChanged = false, hasChanged = false,
ids = ui.listSelection, ids = ui.listSelection.filter(function(id) {
return oml.$ui.list.value(id, 'mediastate') == 'available';
}),
keys = [ keys = [
'title', 'author', 'title', 'author',
'publisher', 'place', 'date', 'publisher', 'place', 'date',

View file

@ -57,8 +57,9 @@ oml.ui.list = function() {
oml.$ui.statusbar.set('total', data); oml.$ui.statusbar.set('total', data);
}, },
key_control_delete: function() { key_control_delete: function() {
var listData = oml.getListData(); if (that.options('selected').filter(function(id) {
if (listData.own) { return that.value(id, 'mediastate') == 'available';
}).length) {
oml.ui.deleteItemsDialog().open(); oml.ui.deleteItemsDialog().open();
} }
}, },
@ -71,6 +72,12 @@ oml.ui.list = function() {
}); });
} }
}, },
load: function() {
if (oml._updateEditMenu) {
oml.$ui.mainMenu.updateElement('editMenu');
oml._udpateEditMenu = false;
}
},
open: function(data) { open: function(data) {
oml.UI.set({ oml.UI.set({
item: data.ids[0], item: data.ids[0],

View file

@ -399,10 +399,7 @@ oml.ui.mainMenu = function() {
}); });
} }
} else if (id == 'deletefromlibrary') { } else if (id == 'deletefromlibrary') {
var listData = oml.getListData();
if (listData.own) {
oml.ui.deleteItemsDialog().open(); oml.ui.deleteItemsDialog().open();
}
} else if (id == 'editlist') { } else if (id == 'editlist') {
oml.ui.listDialog.open(); oml.ui.listDialog.open();
} else if (id == 'deletelist') { } else if (id == 'deletelist') {
@ -417,6 +414,16 @@ oml.ui.mainMenu = function() {
oml.UI.set({listSelection: []}); oml.UI.set({listSelection: []});
} else if (id == 'invertselection') { } else if (id == 'invertselection') {
oml.$ui.list.invertSelection(); oml.$ui.list.invertSelection();
} else if (id == 'download') {
oml.api.addListItems({
items: ui.listSelection.filter(function(id) {
return oml.$ui.list.value(id, 'mediastate') == 'unavailable';
}),
list: ':'
}, function(result) {
Ox.Request.clearCache();
// FIXME: reload?
});
} else if (Ox.contains(['cut', 'cutadd'], id)) { } else if (Ox.contains(['cut', 'cutadd'], id)) {
var action = data.id == 'cut' ? 'copy' : 'add'; var action = data.id == 'cut' ? 'copy' : 'add';
fromMenu = true; fromMenu = true;
@ -478,17 +485,6 @@ oml.ui.mainMenu = function() {
)).open(); )).open();
} 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') {
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 { } else {
Ox.print('MAIN MENU DOES NOT YET HANDLE', id); Ox.print('MAIN MENU DOES NOT YET HANDLE', id);
} }
@ -628,13 +624,27 @@ oml.ui.mainMenu = function() {
function getEditMenu() { function getEditMenu() {
var listData = oml.getListData(), var listData = oml.getListData(),
isLocal = listData.user === '' && listData.type != 'smart',
selectionItems = ui.listSelection.length, selectionItems = ui.listSelection.length,
availableItems = isLocal
? selectionItems
: oml.$ui.list
? ui.listSelection.filter(function(id) {
return oml.$ui.list.value(id, 'mediastate') == 'available';
}).length
: 0,
unavailableItems = selectionItems - availableItems,
selectionItemName = ( selectionItemName = (
selectionItems > 1 ? Ox.formatNumber(selectionItems) + ' ' : '' selectionItems > 1 ? Ox.formatNumber(selectionItems) + ' ' : ''
) + Ox._(selectionItems == 1 ? 'Book' : 'Books'), ) + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
downloadItemName = (
selectionItems > 1 && unavailableItems ? Ox.formatNumber(unavailableItems) + ' ' + (
availableItems ? ' of ' + Ox.formatNumber(selectionItems) + ' ' : ''
) : '') + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
editItemName = ( editItemName = (
selectionItems > 0 ? Ox.formatNumber(selectionItems) + ' ' : '' selectionItems > 1 && availableItems ? Ox.formatNumber(availableItems) + ' ' + (
) + Ox._(selectionItems == 1 ? 'Book' : 'Books'), unavailableItems ? ' of ' + Ox.formatNumber(selectionItems) + ' ' : ''
) : '') + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
clipboardItems = oml.clipboard.items(), clipboardItems = oml.clipboard.items(),
clipboardType = oml.clipboard.type(), clipboardType = oml.clipboard.type(),
clipboardItemName = !clipboardItems ? '' clipboardItemName = !clipboardItems ? ''
@ -642,18 +652,19 @@ 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 = ui.listSelection.filter(function(id) { canDownload = !!unavailableItems,
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,
canAdd = canCopy && clipboardItems && clipboardType == 'book', canAdd = canCopy && clipboardItems && clipboardType == 'book',
canDelete = listData.user == '' && selectionItems, canDelete = !!availableItems,
canEdit = listData.user == '' && selectionItems, canEdit = !!availableItems,
historyItems = oml.history.items(), historyItems = oml.history.items(),
undoText = oml.history.undoText(), undoText = oml.history.undoText(),
redoText = oml.history.redoText(); redoText = oml.history.redoText();
if (!isLocal && !oml.$ui.list) {
oml._updateEditMenu = true;
}
return { return {
id: 'editMenu', id: 'editMenu',
title: Ox._('Edit'), title: Ox._('Edit'),
@ -688,7 +699,7 @@ oml.ui.mainMenu = function() {
{}, {},
{ {
id: 'download', id: 'download',
title: Ox._('Download {0}', [canDownload]), title: Ox._('Download {0}', [downloadItemName]),
disabled: !canDownload, disabled: !canDownload,
keyboard: 'control d' keyboard: 'control d'
}, },
@ -736,7 +747,7 @@ oml.ui.mainMenu = function() {
}, },
{ {
id: 'deletefromlibrary', id: 'deletefromlibrary',
title: Ox._('Delete {0} from Library...', [selectionItemName]), title: Ox._('Delete {0} from Library...', [editItemName]),
disabled: !canDelete, disabled: !canDelete,
keyboard: 'control delete' keyboard: 'control delete'
}, },
@ -919,7 +930,7 @@ oml.ui.mainMenu = function() {
( (
menu ? Ox.makeArray(menu) : ['listMenu', 'editMenu', 'findMenu'] menu ? Ox.makeArray(menu) : ['listMenu', 'editMenu', 'findMenu']
).forEach(function(menu) { ).forEach(function(menu) {
that.updateMenu( that.replaceMenu(
menu, menu,
menu == 'listMenu' ? getListMenu() menu == 'listMenu' ? getListMenu()
: menu == 'editMenu' ? getEditMenu() : menu == 'editMenu' ? getEditMenu()