correctly handle download/edit/delete for selections with mixed mediastate
This commit is contained in:
parent
6838a2f0f2
commit
5882e97608
4 changed files with 51 additions and 29 deletions
|
@ -4,7 +4,9 @@ oml.ui.deleteItemsDialog = function() {
|
|||
|
||||
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'),
|
||||
theseItemsName = items.length == 1
|
||||
? Ox._('this item')
|
||||
|
|
|
@ -7,7 +7,9 @@ oml.ui.editDialog = function() {
|
|||
'author', 'place', 'publisher', 'language'
|
||||
],
|
||||
hasChanged = false,
|
||||
ids = ui.listSelection,
|
||||
ids = ui.listSelection.filter(function(id) {
|
||||
return oml.$ui.list.value(id, 'mediastate') == 'available';
|
||||
}),
|
||||
keys = [
|
||||
'title', 'author',
|
||||
'publisher', 'place', 'date',
|
||||
|
|
|
@ -57,8 +57,9 @@ oml.ui.list = function() {
|
|||
oml.$ui.statusbar.set('total', data);
|
||||
},
|
||||
key_control_delete: function() {
|
||||
var listData = oml.getListData();
|
||||
if (listData.own) {
|
||||
if (that.options('selected').filter(function(id) {
|
||||
return that.value(id, 'mediastate') == 'available';
|
||||
}).length) {
|
||||
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) {
|
||||
oml.UI.set({
|
||||
item: data.ids[0],
|
||||
|
|
|
@ -399,10 +399,7 @@ oml.ui.mainMenu = function() {
|
|||
});
|
||||
}
|
||||
} else if (id == 'deletefromlibrary') {
|
||||
var listData = oml.getListData();
|
||||
if (listData.own) {
|
||||
oml.ui.deleteItemsDialog().open();
|
||||
}
|
||||
oml.ui.deleteItemsDialog().open();
|
||||
} else if (id == 'editlist') {
|
||||
oml.ui.listDialog.open();
|
||||
} else if (id == 'deletelist') {
|
||||
|
@ -417,6 +414,16 @@ oml.ui.mainMenu = function() {
|
|||
oml.UI.set({listSelection: []});
|
||||
} else if (id == '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)) {
|
||||
var action = data.id == 'cut' ? 'copy' : 'add';
|
||||
fromMenu = true;
|
||||
|
@ -478,17 +485,6 @@ oml.ui.mainMenu = function() {
|
|||
)).open();
|
||||
} else if (id == 'advancedfind') {
|
||||
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 {
|
||||
Ox.print('MAIN MENU DOES NOT YET HANDLE', id);
|
||||
}
|
||||
|
@ -628,13 +624,27 @@ oml.ui.mainMenu = function() {
|
|||
|
||||
function getEditMenu() {
|
||||
var listData = oml.getListData(),
|
||||
isLocal = listData.user === '' && listData.type != 'smart',
|
||||
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 = (
|
||||
selectionItems > 1 ? Ox.formatNumber(selectionItems) + ' ' : ''
|
||||
) + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
|
||||
downloadItemName = (
|
||||
selectionItems > 1 && unavailableItems ? Ox.formatNumber(unavailableItems) + ' ' + (
|
||||
availableItems ? ' of ' + Ox.formatNumber(selectionItems) + ' ' : ''
|
||||
) : '') + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
|
||||
editItemName = (
|
||||
selectionItems > 0 ? Ox.formatNumber(selectionItems) + ' ' : ''
|
||||
) + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
|
||||
selectionItems > 1 && availableItems ? Ox.formatNumber(availableItems) + ' ' + (
|
||||
unavailableItems ? ' of ' + Ox.formatNumber(selectionItems) + ' ' : ''
|
||||
) : '') + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
|
||||
clipboardItems = oml.clipboard.items(),
|
||||
clipboardType = oml.clipboard.type(),
|
||||
clipboardItemName = !clipboardItems ? ''
|
||||
|
@ -642,18 +652,19 @@ oml.ui.mainMenu = function() {
|
|||
clipboardItems > 1 ? Ox.formatNumber(clipboardItems) + ' ' : ''
|
||||
) + Ox._(clipboardItems == 1 ? 'Book' : 'Books'),
|
||||
canSelect = !ui.item,
|
||||
canDownload = ui.listSelection.filter(function(id) {
|
||||
return oml.$ui.list && oml.$ui.list.value(id, 'mediastate') == 'unavailable'
|
||||
}).length,
|
||||
canDownload = !!unavailableItems,
|
||||
canCopy = canSelect && selectionItems,
|
||||
canCut = canCopy && listData.editable,
|
||||
canPaste = listData.editable && clipboardItems,
|
||||
canAdd = canCopy && clipboardItems && clipboardType == 'book',
|
||||
canDelete = listData.user == '' && selectionItems,
|
||||
canEdit = listData.user == '' && selectionItems,
|
||||
canDelete = !!availableItems,
|
||||
canEdit = !!availableItems,
|
||||
historyItems = oml.history.items(),
|
||||
undoText = oml.history.undoText(),
|
||||
redoText = oml.history.redoText();
|
||||
if (!isLocal && !oml.$ui.list) {
|
||||
oml._updateEditMenu = true;
|
||||
}
|
||||
return {
|
||||
id: 'editMenu',
|
||||
title: Ox._('Edit'),
|
||||
|
@ -688,7 +699,7 @@ oml.ui.mainMenu = function() {
|
|||
{},
|
||||
{
|
||||
id: 'download',
|
||||
title: Ox._('Download {0}', [canDownload]),
|
||||
title: Ox._('Download {0}', [downloadItemName]),
|
||||
disabled: !canDownload,
|
||||
keyboard: 'control d'
|
||||
},
|
||||
|
@ -736,7 +747,7 @@ oml.ui.mainMenu = function() {
|
|||
},
|
||||
{
|
||||
id: 'deletefromlibrary',
|
||||
title: Ox._('Delete {0} from Library...', [selectionItemName]),
|
||||
title: Ox._('Delete {0} from Library...', [editItemName]),
|
||||
disabled: !canDelete,
|
||||
keyboard: 'control delete'
|
||||
},
|
||||
|
@ -919,7 +930,7 @@ oml.ui.mainMenu = function() {
|
|||
(
|
||||
menu ? Ox.makeArray(menu) : ['listMenu', 'editMenu', 'findMenu']
|
||||
).forEach(function(menu) {
|
||||
that.updateMenu(
|
||||
that.replaceMenu(
|
||||
menu,
|
||||
menu == 'listMenu' ? getListMenu()
|
||||
: menu == 'editMenu' ? getEditMenu()
|
||||
|
|
Loading…
Reference in a new issue