openmedialibrary/static/js/mainMenu.js

1029 lines
42 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
oml.ui.mainMenu = function() {
var ui = oml.user.ui,
findState = oml.getFindState(ui.find),
2014-05-12 23:43:27 +00:00
fromMenu = false,
2014-05-04 17:26:43 +00:00
that = Ox.MainMenu({
extras: [
2014-09-01 12:01:41 +00:00
oml.$ui.updateButton = oml.ui.updateButton(),
2016-01-13 07:04:35 +00:00
oml.$ui.transferButton = oml.ui.transferButton(),
oml.$ui.peersButton = oml.ui.peersButton(),
2014-05-04 17:26:43 +00:00
oml.$ui.loadingIcon = oml.ui.loadingIcon()
],
menus: [
{
id: 'appMenu',
title: '<img src="/static/png/oml.png" style="width: 14px; height: 14px">',
items: [
2016-01-13 06:44:00 +00:00
{
id: 'about',
title: Ox._('About Open Media Library')
},
{},
{
id: 'faq',
title: Ox._('Frequently Asked Questions')
},
{
id: 'terms',
title: Ox._('Terms and Conditions')
},
{
id: 'development',
title: Ox._('Software Development')
},
{
id: 'contact',
title: Ox._('Send Feedback')
},
{},
{
id: 'update',
2016-01-13 06:44:00 +00:00
title: Ox._('Software Update...')
},
2014-05-04 17:26:43 +00:00
{},
2016-01-08 03:41:55 +00:00
{
id: 'quit',
title: Ox._('Quit Open Media Library'),
keyboard: 'control q'
}
2016-01-13 06:44:00 +00:00
]
2014-05-04 17:26:43 +00:00
},
{
id: 'userMenu',
title: Ox._('User'),
items: [
{
id: 'preferences',
title: Ox._('Preferences...'),
keyboard: 'control ,'
},
{},
{
2016-01-13 06:44:00 +00:00
id: 'peers',
title: Ox._('Peers...')
2014-05-04 17:26:43 +00:00
},
{
2016-01-13 06:44:00 +00:00
id: 'transfers',
title: Ox._('Transfers...')
2014-05-04 17:26:43 +00:00
}
]
},
2014-05-12 12:57:47 +00:00
getListMenu(),
getEditMenu(),
2014-05-04 17:26:43 +00:00
{
id: 'viewMenu',
title: Ox._('View'),
items: [
{
id: 'section',
title: Ox._('Section'),
items: [
{
group: 'section',
min: 1,
max: 1,
items: [
{
id: 'books',
title: Ox._('Books'),
checked: true
},
{
id: 'music',
title: Ox._('Music'),
disabled: true
},
{
id: 'movies',
title: Ox._('Movies'),
disabled: true
}
]
}
]
},
{},
{
id: 'listviewSubmenu',
title: Ox._('Books'),
items: [
{
group: 'listview',
min: 1,
max: 1,
items: [
{
id: 'list',
title: Ox._('List'),
checked: ui.listView == 'list'
},
{
id: 'grid',
title: Ox._('Grid'),
checked: ui.listView == 'grid'
}
]
}
]
},
{
id: 'itemviewSubmenu',
title: Ox._('Book'),
items: [
{
group: 'itemview',
min: 1,
max: 1,
items: [
{
id: 'info',
title: Ox._('Info'),
checked: ui.itemView == 'info',
disabled: !ui.item
},
{
id: 'book',
title: Ox._('Reader'),
checked: ui.itemView == 'book',
disabled: !ui.item
}
]
}
]
},
2014-05-04 17:26:43 +00:00
{
2014-05-21 00:02:39 +00:00
id: 'iconsSubmenu',
2014-05-04 17:26:43 +00:00
title: 'Icons',
items: [
{
group: 'icons',
min: 1,
max: 1,
items: [
{
id: 'cover',
title: Ox._('Cover'),
checked: ui.icons == 'cover'
},
{
id: 'preview',
title: Ox._('Preview'),
checked: ui.icons == 'preview'
}
]
},
{},
{
2014-05-21 00:02:39 +00:00
id: 'showiconinfo',
title: 'Show Icon Info',
checked: ui.showIconInfo
2014-05-04 17:26:43 +00:00
},
{},
{
2014-05-21 00:02:39 +00:00
group: 'iconinfo',
2014-05-04 17:26:43 +00:00
min: 1,
max: 1,
items: [
{
id: 'extension',
title: Ox._('Show Extension'),
2014-05-21 00:02:39 +00:00
checked: ui.iconInfo == 'extension',
disabled: !ui.showIconInfo
2014-05-04 17:26:43 +00:00
},
{
id: 'size',
title: Ox._('Show Size'),
2014-05-21 00:02:39 +00:00
checked: ui.iconInfo == 'size',
disabled: !ui.showIconInfo
2014-05-04 17:26:43 +00:00
}
]
}
]
},
{},
{
id: 'showsidebar',
title: Ox._((ui.showSidebar ? 'Hide' : 'Show') + ' Sidebar'),
keyboard: 'shift s'
},
{
id: 'showinfo',
title: Ox._((ui.showInfo ? 'Hide' : 'Show') + ' Info'),
keyboard: 'shift i',
disabled: !ui.showSidebar
},
{
id: 'showfilters',
title: Ox._((ui.showFilters ? 'Hide' : 'Show') + ' Filters'),
keyboard: 'shift f',
disabled: !!ui.item
},
{
id: 'showbrowser',
title: Ox._((ui.showBrowser ? 'Hide': 'Show') + ' Browser'),
keyboard: 'shift b',
disabled: !ui.item
},
{},
{
id: 'preview',
title: Ox._('Show Preview'),
keyboard: 'space',
disabled: !!ui.item || !ui.listSelection.length
},
{
id: 'fullscreen',
title: Ox._('Enter Fullscreen'),
keyboard: 'shift alt f',
disabled: !ui.item || ui.itemView == 'info'
2014-05-04 17:26:43 +00:00
}
]
},
{
id: 'sortMenu',
title: Ox._('Sort'),
items: [
{
id: 'sortitems',
title: Ox._('Sort Books by'),
items: [
{
group: 'sort',
title: Ox._('Sort Books by'),
min: 1,
max: 1,
items: oml.config.sortKeys.map(function(key) {
return {
id: key.id,
title: Ox._(key.title),
checked: key.id == ui.listSort[0].key
};
})
}
]
},
{
id: 'orderitems',
title: Ox._('Order Books'),
items: [
{
group: 'order',
min: 1,
max: 1,
items: [
{
id: 'ascending',
title: Ox._('Ascending'),
checked: ui.listSort[0].operator == '+'
},
{
id: 'descending',
title: Ox._('Descending'),
checked: ui.listSort[0].operator == '-'
}
],
}
]
},
{
id: 'advancedsort',
title: Ox._('Advanced Sort'),
keyboard: 'shift control s',
disabled: true
2014-05-25 12:16:04 +00:00
},
{},
{
id: 'sorttitles',
title: Ox._('Sort Titles...')
},
{
id: 'sortnames',
title: Ox._('Sort Names...')
2014-05-04 17:26:43 +00:00
}
]
},
2014-05-17 14:42:46 +00:00
getFindMenu(),
2014-05-04 17:26:43 +00:00
{
id: 'helpMenu',
title: Ox._('Help'),
items: [
{
id: 'gettingstarted',
title: 'Getting Started...'
},
{
id: 'help',
title: Ox._('{0} Help...', ['Open Media Library']),
keyboard: 'control ?'
},
{
id: 'documentation',
title: Ox._('Documentation...'),
keyboard: 'shift control ?'
}
]
},
{
id: 'debugMenu',
title: Ox._('Debug'),
items: [
{
id: 'debugmode',
title: Ox._((
oml.localStorage('enableDebugMode')
? 'Disable' : 'Enable'
) + ' Debug Mode'),
},
{
id: 'eventlogging',
title: Ox._((
oml.localStorage('enableEventLogging')
? 'Disable' : 'Enable'
) + ' Event Logging'),
},
{},
{
id: 'changelog',
title: Ox._('Change Log...')
},
{
id: 'errorlog',
title: Ox._('Error Log...')
}
]
}
]
})
.bindEvent({
change: function(data) {
var id = data.id,
value = Ox.isBoolean(data.checked)
? data.checked : data.checked[0].id;
if (id == 'listview') {
oml.UI.set({listView: value});
} else if (id == 'itemview') {
oml.UI.set({itemView: value});
} else if (id == 'icons') {
2014-05-04 17:26:43 +00:00
oml.UI.set({icons: value});
2014-05-21 00:02:39 +00:00
} else if (id == 'icons') {
oml.UI.set({icons: value});
} else if (id == 'showiconinfo') {
oml.UI.set({showIconInfo: value});
} else if (id == 'iconinfo') {
oml.UI.set({iconInfo: value});
2014-05-17 11:45:57 +00:00
} else if (id == 'sort') {
oml.UI.set({
listSort: [{
key: value,
operator: oml.getSortOperator(value)
}]
});
} else if (id == 'order') {
oml.UI.set({
listSort: [{
key: ui.listSort[0].key,
operator: value == 'ascending' ? '+' : '-'
}]
});
2014-05-17 14:42:46 +00:00
} else if (id == 'findin') {
oml.$ui.findInSelect.value(value);
if (ui._findState.key == 'advanced') {
// ...
} else {
oml.$ui.findInput.focusInput(true);
}
2014-05-17 11:45:57 +00:00
} else if (id == 'find') {
if (value) {
oml.$ui.findSelect.value(value);
if (ui._findState.key == 'advanced') {
// fixme: autocomplete function doesn't get updated
2014-05-17 14:42:46 +00:00
oml.$ui.findInput.options({placeholder: ''});
} else {
oml.$ui.findInput.focusInput(true);
2014-05-17 11:45:57 +00:00
}
}
2014-05-04 17:26:43 +00:00
} else {
2014-05-17 11:45:57 +00:00
Ox.print('MAIN MENU DOES NOT YET HANDLE', id, data);
2014-05-04 17:26:43 +00:00
}
},
click: function(data) {
var id = data.id;
if (Ox.contains([
2016-01-14 08:50:53 +00:00
'about', 'faq', 'terms', 'development', 'contact', 'update'
2014-05-04 17:26:43 +00:00
], id)) {
2016-01-13 06:44:00 +00:00
oml.UI.set({page: id});
} else if (id == 'quit') {
oml.api.quit();
2014-05-04 17:26:43 +00:00
} else if (id == 'preferences') {
oml.UI.set({page: 'preferences'});
2016-01-13 06:44:00 +00:00
} else if (id == 'peers') {
oml.UI.set({page: 'peers'});
} else if (id == 'transfers') {
oml.UI.set({page: 'transfers'});
2014-05-12 23:43:27 +00:00
} else if (id == 'alllibraries') {
if (!ui._list) {
oml.UI.set({item: ''});
} else {
oml.UI.set({find: {
conditions: [],
operator: '&'
}});
}
} else if (id == 'thislibrary') {
if (Ox.endsWith(ui._list, ':')) {
oml.UI.set({item: ''});
} else {
oml.UI.set({find: {
conditions: [{
key: 'list',
operator: '==',
value: ui._list.split(':')[0] + ':'
}],
operator: '&'
}});
}
} else if (id == 'thislist') {
oml.UI.set({item: ''});
2014-05-04 17:26:43 +00:00
} else if (Ox.contains([
'newlist', 'newlistfromselection',
'newsmartlist', 'newsmartlistfromresults'
], id)) {
oml.addList(Ox.contains(id, 'smart'), Ox.contains(id, 'from'));
} else if (id == 'duplicatelist') {
oml.addList(ui._list);
2015-02-27 12:28:01 +00:00
} else if (id == 'delete') {
var listData = oml.getListData();
if (listData.editable && listData.type == 'static') {
oml.doHistory('delete', ui.listSelection, ui._list, function() {
oml.UI.set({listSelection: []});
2016-01-12 08:52:20 +00:00
oml.reloadLists();
2015-02-27 12:28:01 +00:00
});
}
2015-02-27 11:03:20 +00:00
} else if (id == 'deletefromlibrary') {
oml.ui.deleteItemsDialog().open();
2014-05-04 17:26:43 +00:00
} else if (id == 'editlist') {
oml.ui.listDialog.open();
} else if (id == 'deletelist') {
2014-05-12 23:43:27 +00:00
oml.ui.deleteListDialog().open();
2014-05-16 14:30:16 +00:00
} else if (id == 'import') {
2014-05-17 08:17:34 +00:00
oml.UI.set({page: 'import'});
} else if (id == 'export') {
oml.UI.set({page: 'export'});
2014-05-12 23:43:27 +00:00
} else if (id == 'selectall') {
oml.$ui.list.selectAll();
} else if (id == 'selectnone') {
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?
});
2014-05-19 15:00:33 +00:00
} else if (Ox.contains(['cut', 'cutadd'], id)) {
var action = data.id == 'cut' ? 'copy' : 'add';
fromMenu = true;
oml.clipboard[action](ui.listSelection, 'item');
oml.doHistory('cut', ui.listSelection, ui._list, function() {
oml.UI.set({listSelection: []});
2016-01-12 08:52:20 +00:00
oml.reloadLists();
2014-05-19 15:00:33 +00:00
});
} else if (Ox.contains(['copy', 'copyadd'], id)) {
var action = data.id == 'copy' ? 'copy' : 'add';
fromMenu = true;
oml.clipboard[action](ui.listSelection, 'item');
} else if (id == 'paste') {
var items = oml.clipboard.paste();
oml.doHistory('paste', items, ui._list, function() {
oml.UI.set({listSelection: items});
2016-01-12 08:52:20 +00:00
oml.reloadLists();
2014-05-19 15:00:33 +00:00
});
2014-05-12 23:43:27 +00:00
} else if (data.id == 'clearclipboard') {
oml.clipboard.clear();
} else if (data.id == 'delete') {
oml.doHistory('delete', ui.listSelection, ui._list, function() {
oml.UI.set({listSelection: []});
2016-01-12 08:52:20 +00:00
oml.reloadLists();
2014-05-12 23:43:27 +00:00
});
2016-01-05 08:32:07 +00:00
} else if (data.id == 'editmetadata') {
oml.$ui.editDialog = oml.ui.editDialog().open();
2014-05-12 23:43:27 +00:00
} else if (data.id == 'undo') {
fromMenu = true;
oml.undoHistory();
} else if (data.id == 'redo') {
fromMenu = true;
oml.redoHistory();
} else if (id == 'clearhistory') {
fromMenu = true;
oml.history.clear();
2014-05-04 17:26:43 +00:00
} else if (id == 'showsidebar') {
oml.UI.set({showSidebar: !ui.showSidebar});
} else if (id == 'showinfo') {
oml.UI.set({showInfo: !ui.showInfo});
} else if (id == 'showfilters') {
oml.UI.set({showFilters: !ui.showFilters});
} else if (id == 'showbrowser') {
oml.UI.set({showBrowser: !ui.showBrowser});
} else if (id == 'preview') {
that.setItemTitle(
'preview',
data.title == Ox._('Show Preview')
? Ox._('Hide Preview') : Ox._('Show Preview')
);
oml.$ui.list[
data.title == Ox._('Show Preview')
? 'openPreview' : 'closePreview'
]();
} else if (id == 'fullscreen') {
Ox.Fullscreen.enter(oml.$ui.viewer.find('iframe')[0]);
2014-05-12 23:43:27 +00:00
} else if (id == 'debugmode') {
if (oml.localStorage('enableDebugMode')) {
oml.localStorage['delete']('enableDebugMode');
} else {
oml.localStorage('enableDebugMode', true);
}
window.location.reload();
2015-05-14 11:03:49 +00:00
} else if (id == 'sortnames') {
(oml.$ui.namesDialog || (
oml.$ui.namesDialog = oml.ui.namesDialog()
)).open();
} else if (id == 'sorttitles') {
(oml.$ui.titlesDialog || (
oml.$ui.titlesDialog = oml.ui.titlesDialog()
)).open();
2016-01-14 08:41:52 +00:00
} else if (id == 'advancedfind') {
oml.$ui.findDialog = oml.ui.findDialog().open();
2014-05-04 17:26:43 +00:00
} else {
Ox.print('MAIN MENU DOES NOT YET HANDLE', id);
}
},
oml_find: function() {
2014-05-12 12:57:47 +00:00
that.replaceMenu('listMenu', getListMenu());
that.replaceMenu('editMenu', getEditMenu());
2014-05-17 14:42:46 +00:00
that.replaceMenu('findMenu', getFindMenu());
2014-05-04 17:26:43 +00:00
},
2014-05-21 00:02:39 +00:00
oml_iconinfo: function(data) {
// ...
},
oml_icons: function(data) {
that.checkItem('viewMenu_iconsSubmenu_' + data.value);
},
2014-05-04 17:26:43 +00:00
oml_item: function(data) {
if (!!data.value != !!data.previousValue) {
that[data.value ? 'enableItem' : 'disableItem']('info');
that[data.value ? 'enableItem' : 'disableItem']('book');
2014-05-04 17:26:43 +00:00
that[data.value ? 'disableItem' : 'enableItem']('showfilters');
that[data.value ? 'enableItem' : 'disableItem']('showbrowser');
}
},
oml_itemview: function(data) {
that.checkItem('viewMenu_itemviewSubmenu_' + data.value);
that[data.value == 'book' ? 'enableItem' : 'disableItem']('fullscreen');
},
2014-05-12 12:57:47 +00:00
oml_listselection: function(data) {
2016-01-17 10:13:17 +00:00
that.replaceMenu('listMenu', getListMenu());
2014-05-12 12:57:47 +00:00
that.replaceMenu('editMenu', getEditMenu());
that[!ui.item && data.value.length ? 'enableItem' : 'disableItem']('preview');
2014-05-12 12:57:47 +00:00
},
2014-05-12 23:43:27 +00:00
oml_listsort: function(data) {
that.checkItem('sortMenu_sortitems_' + data.value[0].key);
that.checkItem('sortMenu_orderitems_' + (
data.value[0].operator == '+' ? 'ascending' : 'descending')
);
},
oml_listview: function(data) {
that.checkItem('viewMenu_listviewSubmenu_' + data.value);
},
2014-05-04 17:26:43 +00:00
oml_showbrowser: function(data) {
that.setItemTitle('showbrowser', Ox._((data.value ? 'Hide' : 'Show') + ' Browser'));
},
oml_showfilters: function(data) {
that.setItemTitle('showfilters', Ox._((data.value ? 'Hide' : 'Show') + ' Filters'));
},
2014-05-21 00:02:39 +00:00
oml_showiconinfo: function(data) {
var action = data.value ? 'enableItem' : 'disableItem';
that[action]('viewMenu_iconsSubmenu_extension');
that[action]('viewMenu_iconsSubmenu_size');
},
2014-05-04 17:26:43 +00:00
oml_showinfo: function(data) {
that.setItemTitle('showinfo', Ox._((data.value ? 'Hide' : 'Show') + ' Info'));
},
oml_showsidebar: function(data) {
that.setItemTitle('showsidebar', Ox._((data.value ? 'Hide' : 'Show') + ' Sidebar'));
that[data.value ? 'enableItem' : 'disableItem']('showinfo');
},
});
Ox.Event.bind({
key_alt_shift_f: function() {
if (ui.item && ui.itemView == 'book') {
Ox.Fullscreen.enter(oml.$ui.viewer.find('iframe')[0]);
}
},
key_backtick: function() {
2014-09-24 13:30:23 +00:00
changeFocus(1);
},
key_control_comma: function() {
2014-09-24 13:30:23 +00:00
if (!oml.hasDialogOrScreen()) {
oml.UI.set({page: 'preferences'});
}
},
key_control_e: function() {
if (
!oml.hasDialogOrScreen()
&& ui.listSelection.length
&& !oml.getListData().user
) {
oml.$ui.editDialog = oml.ui.editDialog().open()
}
},
key_control_f: function() {
2014-09-24 13:30:23 +00:00
if (!oml.hasDialogOrScreen()) {
if (ui._findState.key != 'advanced') {
setTimeout(function() {
oml.$ui.findInput.focusInput(true);
});
} else {
2016-01-14 08:41:52 +00:00
oml.$ui.findDialog = oml.ui.findDialog().open();
2014-09-24 13:30:23 +00:00
}
}
},
key_control_m: function() {
2014-09-24 13:30:23 +00:00
if (!oml.hasDialogOrScreen() && !that.isSelected()) {
that.options('menus')[0].element.trigger('click');
}
},
key_control_shift_f: function() {
2016-01-14 08:41:52 +00:00
if (!oml.hasDialogOrScreen()) {
oml.$ui.findDialog = oml.ui.findDialog().open();
}
},
key_control_shift_w: function() {
2014-09-24 13:30:23 +00:00
if (!oml.hasDialogOrScreen()) {
oml.UI.set({
find: oml.config.user.ui.find,
item: ''
});
}
},
key_control_shift_z: function() {
2014-09-24 13:30:23 +00:00
oml.redoHistory();
},
key_control_slash: function() {
2014-09-24 13:30:23 +00:00
if (!oml.hasDialogOrScreen()) {
oml.UI.set({page: 'help'});
}
},
key_control_w: function() {
2014-09-24 13:30:23 +00:00
if (!oml.hasDialogOrScreen()) {
oml.UI.set({item: ''});
}
},
key_control_z: function() {
2014-09-24 13:30:23 +00:00
oml.undoHistory();
},
key_shift_b: function() {
2014-09-24 13:30:23 +00:00
ui.item && oml.UI.set({showBrowser: !ui.showBrowser});
},
key_shift_f: function() {
2014-09-24 13:30:23 +00:00
!ui.item && oml.UI.set({showFilters: !ui.showFilters});
},
key_shift_i: function() {
2014-09-24 13:30:23 +00:00
ui.showSidebar && oml.UI.set({showInfo: !ui.showInfo});
},
key_shift_s: function() {
2014-09-24 13:30:23 +00:00
oml.UI.set({showSidebar: !ui.showSidebar});
}
});
2015-05-14 11:40:29 +00:00
setTimeout(oml.updateDebugMenu);
2014-05-04 17:26:43 +00:00
2014-05-12 12:57:47 +00:00
function getEditMenu() {
var listData = oml.getListData(),
isLocal = listData.user === '' && listData.type != 'smart',
2014-05-12 12:57:47 +00:00
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,
2014-05-12 12:57:47 +00:00
selectionItemName = (
selectionItems > 1 ? Ox.formatNumber(selectionItems) + ' ' : ''
2014-05-12 23:43:27 +00:00
) + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
downloadItemName = (
selectionItems > 1 && unavailableItems ? Ox.formatNumber(unavailableItems) + ' ' + (
availableItems ? ' of ' + Ox.formatNumber(selectionItems) + ' ' : ''
) : '') + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
2016-01-05 17:35:35 +00:00
editItemName = (
selectionItems > 1 && availableItems ? Ox.formatNumber(availableItems) + ' ' + (
unavailableItems ? ' of ' + Ox.formatNumber(selectionItems) + ' ' : ''
) : '') + Ox._(selectionItems == 1 ? 'Book' : 'Books'),
2014-05-12 12:57:47 +00:00
clipboardItems = oml.clipboard.items(),
clipboardType = oml.clipboard.type(),
clipboardItemName = !clipboardItems ? ''
: (
clipboardItems > 1 ? Ox.formatNumber(clipboardItems) + ' ' : ''
) + Ox._(clipboardItems == 1 ? 'Book' : 'Books'),
canSelect = !ui.item,
canDownload = !!unavailableItems,
2014-05-12 12:57:47 +00:00
canCopy = canSelect && selectionItems,
canCut = canCopy && listData.editable,
canPaste = listData.editable && clipboardItems,
2014-05-19 15:00:33 +00:00
canAdd = canCopy && clipboardItems && clipboardType == 'book',
canDelete = !!availableItems,
canEdit = !!availableItems,
2014-05-12 12:57:47 +00:00
historyItems = oml.history.items(),
undoText = oml.history.undoText(),
redoText = oml.history.redoText();
if (!isLocal && !oml.$ui.list) {
oml._updateEditMenu = true;
}
2014-05-12 12:57:47 +00:00
return {
id: 'editMenu',
title: Ox._('Edit'),
items: [
{
2014-05-16 14:30:16 +00:00
id: 'import',
2014-05-17 08:17:34 +00:00
title: Ox._(oml.user.importing ? 'Importing Books...' : 'Import Books...') // FIXME
2014-05-12 12:57:47 +00:00
},
{
2014-05-16 14:30:16 +00:00
id: 'export',
2014-05-17 08:17:34 +00:00
title: Ox._(oml.user.exporting ? 'Exporting Books...' : 'Export Books...') // FIXME
2014-05-12 12:57:47 +00:00
},
{},
{
id: 'selectall',
title: Ox._('Select All'),
disabled: !canSelect,
keyboard: 'control a'
},
{
id: 'selectnone',
title: Ox._('Select None'),
disabled: !canSelect,
keyboard: 'shift control a'
},
{
id: 'invertselection',
title: Ox._('Invert Selection'),
disabled: !canSelect,
keyboard: 'alt control a'
},
{},
2014-05-12 23:43:27 +00:00
{
id: 'download',
title: Ox._('Download {0}', [downloadItemName]),
2014-05-12 23:43:27 +00:00
disabled: !canDownload,
keyboard: 'control d'
},
2014-05-12 12:57:47 +00:00
{
id: 'cut',
title: Ox._('Cut {0}', [selectionItemName]),
disabled: !canCut,
keyboard: 'control x'
},
{
id: 'cutadd',
title: Ox._('Cut and Add to Clipboard'),
disabled: !canCut || !canAdd,
keyboard: 'shift control x'
},
{
id: 'copy',
title: Ox._('Copy {0}', [selectionItemName]),
disabled: !canCopy,
keyboard: 'control c'
},
{
id: 'copyadd',
title: Ox._('Copy and Add to Clipboard'),
disabled: !canCopy || !canAdd,
keyboard: 'shift control c'
},
{
id: 'paste',
title: !clipboardItems ? Ox._('Paste') : Ox._('Paste {0}', [clipboardItemName]),
disabled: !canPaste,
keyboard: 'control v'
},
{
id: 'clearclipboard',
title: Ox._('Clear Clipboard'),
disabled: !clipboardItems
},
{},
{
id: 'delete',
title: Ox._('Delete {0} from List', [selectionItemName]),
disabled: !canCut,
keyboard: 'delete'
},
2014-05-12 23:43:27 +00:00
{
id: 'deletefromlibrary',
title: Ox._('Delete {0} from Library...', [editItemName]),
2014-05-12 23:43:27 +00:00
disabled: !canDelete,
2014-05-17 11:45:57 +00:00
keyboard: 'control delete'
2014-05-12 23:43:27 +00:00
},
2014-05-12 12:57:47 +00:00
{},
2016-01-05 08:32:07 +00:00
{
id: 'editmetadata',
title: Ox._('Edit Metadata for {0}', [editItemName]),
disabled: !canEdit || ui.item,
2016-01-05 08:32:07 +00:00
keyboard: 'control e'
},
{},
2014-05-12 12:57:47 +00:00
{
id: 'undo',
title: undoText ? Ox._('Undo {0}', [undoText]) : Ox._('Undo'),
disabled: !undoText,
keyboard: 'control z'
},
{
id: 'redo',
title: redoText ? Ox._('Redo {0}', [redoText]) : Ox._('Redo'),
disabled: !redoText,
keyboard: 'shift control z'
},
{
id: 'clearhistory',
title: Ox._('Clear History'),
disabled: !historyItems,
}
]
};
}
2014-05-12 23:43:27 +00:00
function getFindMenu() {
2014-05-17 14:42:46 +00:00
var isLibraries = !ui._list,
isLibrary = Ox.endsWith(ui._list, ':'),
isList = !isLibraries && !isLibrary;
return {
id: 'findMenu',
title: Ox._('Find'),
items: [
{
id: 'findlists',
title: Ox._('Find In'),
items: [
{
group: 'findin',
min: 1,
max: 1,
items: [
{id: 'all', title: Ox._('All Libraries'), checked: isLibraries}
].concat(!isLibraries ? [
{id: 'user', title: Ox._('This Library'), checked: isLibrary}
] : []).concat(isList ? [
{id: 'list', title: Ox._('This List'), checked: isList}
] : [])
}
]
},
{
id: 'finditems',
title: Ox._('Find'),
items: [
{
group: 'find',
min: 1,
max: 1,
items: oml.config.findKeys.map(function(key) {
var checked = key.id == findState.key;
return {
id: key.id,
title: Ox._(key.title),
checked: checked,
keyboard: checked ? 'control f' : ''
};
})
},
]
},
{
id: 'advancedfind',
title: Ox._('Advanced Find'),
keyboard: 'shift control f'
}
]
};
2014-05-12 23:43:27 +00:00
}
2014-05-12 12:57:47 +00:00
function getListMenu() {
var isLibraries = !ui._list,
isLibrary = Ox.endsWith(ui._list, ':'),
isList = !isLibraries && !isLibrary,
isOwnList = ui._list[0] == ':';
return {
id: 'listMenu',
title: Ox._('List'),
2014-05-12 23:43:27 +00:00
items: [].concat(!isLibraries || ui.item ? [
2014-05-12 12:57:47 +00:00
{
2014-05-12 23:43:27 +00:00
id: 'alllibraries',
2014-05-12 12:57:47 +00:00
title: Ox._('All Libraries'),
keyboard: 'shift control w'
2014-05-12 23:43:27 +00:00
}
] : []).concat(isList || (isLibrary && ui.item) ? [
2014-05-12 12:57:47 +00:00
{
2014-05-12 23:43:27 +00:00
id: 'thislibrary',
2014-05-12 12:57:47 +00:00
title: Ox._('This Library'),
keyboard: isLibrary ? 'control w' : ''
2014-05-12 23:43:27 +00:00
}
] : []).concat(isList && ui.item ? [
2014-05-12 12:57:47 +00:00
{
2014-05-12 23:43:27 +00:00
id: 'thislist',
2014-05-12 12:57:47 +00:00
title: Ox._('This List'),
2014-05-12 23:43:27 +00:00
keyboard: isList ? 'control w' : ''
}
] : []).concat(!isLibraries || ui.item ? [
2014-05-12 12:57:47 +00:00
{},
2014-05-12 23:43:27 +00:00
] : []).concat([
2014-05-12 12:57:47 +00:00
{
id: 'newlist',
2014-05-12 23:43:27 +00:00
title: Ox._('New List...'),
2014-05-12 12:57:47 +00:00
keyboard: 'control n'
},
{
id: 'newlistfromselection',
2014-05-12 23:43:27 +00:00
title: Ox._('New List from Selection...'),
2014-05-12 12:57:47 +00:00
keyboard: 'shift control n',
disabled: !ui.listSelection.length
},
{
id: 'newsmartlist',
2014-05-12 23:43:27 +00:00
title: Ox._('New Smart List...'),
2014-05-12 12:57:47 +00:00
keyboard: 'alt control n'
},
{
id: 'newsmartlistfromresults',
2014-05-12 23:43:27 +00:00
title: Ox._('New Smart List from Results...'),
2014-05-12 12:57:47 +00:00
keyboard: 'shift alt control n'
},
{},
{
id: 'duplicatelist',
2014-05-12 23:43:27 +00:00
title: Ox._('Duplicate List...'),
2014-05-12 12:57:47 +00:00
disabled: !isList
},
{
id: 'editlist',
title: Ox._('Edit List...'),
keyboard: 'return',
2014-05-17 11:45:57 +00:00
disabled: !isList || !isOwnList
2014-05-12 12:57:47 +00:00
},
{
id: 'deletelist',
title: Ox._('Delete List...'),
keyboard: 'delete',
2014-05-17 11:45:57 +00:00
disabled: !isList || !isOwnList
2014-05-12 12:57:47 +00:00
}
2014-05-12 23:43:27 +00:00
])
2014-05-12 12:57:47 +00:00
};
2014-05-04 17:26:43 +00:00
}
2014-05-19 15:00:33 +00:00
oml.clipboard.bindEvent(function(data, event) {
if (Ox.contains(['add', 'copy', 'clear'], event)) {
that.replaceMenu('editMenu', getEditMenu());
}
if (Ox.contains(['add', 'copy', 'paste'], event) && !fromMenu) {
that.highlightMenu('editMenu');
}
fromMenu = false;
});
oml.history.bindEvent(function(data, event) {
that.replaceMenu('editMenu', getEditMenu());
if (Ox.contains(['undo', 'redo'], event) && !fromMenu) {
that.highlightMenu('editMenu');
}
fromMenu = false;
});
2014-05-17 11:45:57 +00:00
that.updateElement = function(menu) {
2014-05-12 23:43:27 +00:00
(
2014-05-17 14:42:46 +00:00
menu ? Ox.makeArray(menu) : ['listMenu', 'editMenu', 'findMenu']
2014-05-12 23:43:27 +00:00
).forEach(function(menu) {
that.replaceMenu(
2014-05-12 23:43:27 +00:00
menu,
2014-05-17 14:42:46 +00:00
menu == 'listMenu' ? getListMenu()
: menu == 'editMenu' ? getEditMenu()
: getFindMenu()
2014-05-12 23:43:27 +00:00
);
});
return that;
2014-05-12 12:57:47 +00:00
};
2014-05-04 17:26:43 +00:00
return that;
};