pandora/static/js/folders.js

511 lines
27 KiB
JavaScript
Raw Permalink Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
2018-06-19 06:33:26 +00:00
2013-07-15 11:39:23 +00:00
pandora.ui.folders = function(section) {
section = section || pandora.user.ui.section;
2011-10-29 16:57:51 +00:00
var ui = pandora.user.ui,
that = Ox.Element()
.css({overflowX: 'hidden', overflowY: 'auto'})
.bindEvent({
resize: function() {
pandora.resizeFolders();
}
2013-02-16 01:20:40 +00:00
}),
2016-10-04 22:00:03 +00:00
editable = (ui[{
items: '_list',
edits: 'edit',
documents: '_collection',
texts: 'text'
}[section]] || '').split(':')[0] == pandora.user.username,
folderItems = pandora.getFolderItems(section),
folderItem = folderItems.slice(0, -1),
2017-11-04 09:53:27 +00:00
canEditFeatured = pandora.hasCapability('canEditFeatured' + folderItems),
initCounter = 0,
loadCounter = 0;
2013-07-15 11:39:23 +00:00
pandora.$ui.allItems = pandora.ui.allItems(section).appendTo(that);
2011-06-06 15:48:11 +00:00
pandora.$ui.folder = [];
pandora.$ui.folderBrowser = {};
pandora.$ui.folderList = {};
pandora.$ui.folderPlaceholder = {};
pandora.$ui.findListsElement = {};
pandora.$ui.findListsSelect = {};
pandora.$ui.findListsInput = {};
pandora.$ui.manageListsButton = {};
2013-07-15 11:39:23 +00:00
pandora.site.sectionFolders[section].forEach(function(folder, i) {
2013-02-16 01:20:40 +00:00
var extras, $select;
if (folder.id == 'personal') {
if (pandora.user.level == 'guest') {
extras = [infoButton(
Ox._('Personal ' + folderItems),
section == 'items'
2016-01-21 13:39:55 +00:00
? Ox._('To create and share your own lists of {0}, please sign up or sign in.', [Ox._(pandora.site.itemName.plural.toLowerCase())])
: Ox._('To create and share your own {0}, please sign up or sign in.', [section])
)];
2013-02-16 01:20:40 +00:00
} else {
2016-10-04 22:00:03 +00:00
if (Ox.contains(pandora.site.listSections, section)) {
2011-10-29 16:57:51 +00:00
extras = [
pandora.$ui.personalListsMenu = Ox.MenuButton({
2011-10-29 16:57:51 +00:00
items: [
2016-10-04 22:00:03 +00:00
{ id: 'newlist', title: Ox._('New {0}', [Ox._(folderItem)]), keyboard: 'control n' },
2019-07-14 10:33:38 +00:00
{
id: 'newlistfromselection',
title: Ox._('New {0} from Selection',
[Ox._(folderItem)]),
keyboard: 'shift control n',
disabled: ui.section == 'documents'
2020-01-17 23:08:20 +00:00
? ui.collectionSelection.length == 0
2019-07-14 10:33:38 +00:00
: ui.listSelection.length == 0
},
2016-10-04 22:00:03 +00:00
{ id: 'newsmartlist', title: Ox._('New Smart {0}', [Ox._(folderItem)]), keyboard: 'alt control n' },
{ id: 'newsmartlistfromresults', title: Ox._('New Smart {0} from Results', [Ox._(folderItem)]), keyboard: 'shift alt control n' },
2011-10-29 16:57:51 +00:00
{},
2020-01-17 23:08:20 +00:00
{ id: 'duplicatelist', title: Ox._('Duplicate Selected {0}', [Ox._(folderItem)]), keyboard: 'control d', disabled: ui.section == 'documents' ? !ui._collection : !ui._list },
2016-10-04 22:00:03 +00:00
{ id: 'editlist', title: Ox._('Edit Selected {0}...', [Ox._(folderItem)]), keyboard: 'control e', disabled: !editable },
{ id: 'deletelist', title: Ox._('Delete Selected {0}...', [Ox._(folderItem)]), keyboard: 'delete', disabled: !editable }
2011-10-29 16:57:51 +00:00
],
2011-12-22 07:27:48 +00:00
title: 'edit',
2016-10-04 22:00:03 +00:00
tooltip: Ox._('Manage Personal ' + folderItems),
2011-10-29 16:57:51 +00:00
type: 'image'
})
.bindEvent({
click: function(data) {
var $list = pandora.$ui.folderList[folder.id];
// fixme: duplicated
2014-02-05 13:38:36 +00:00
if (Ox.contains([
2011-10-29 16:57:51 +00:00
'newlist', 'newlistfromselection', 'newsmartlist', 'newsmartlistfromresults'
2014-02-05 13:38:36 +00:00
], data.id)) {
2011-10-29 16:57:51 +00:00
pandora.addList(data.id.indexOf('smart') > -1, data.id.indexOf('from') > -1);
} else if (data.id == 'duplicatelist') {
2020-01-17 23:08:20 +00:00
pandora.addList(ui.section == 'documents' ? ui._collection : ui._list);
2011-10-29 16:57:51 +00:00
} else if (data.id == 'editlist') {
pandora.ui.listDialog().open();
} else if (data.id == 'deletelist') {
pandora.ui.deleteListDialog().open();
}
},
2020-01-17 23:08:20 +00:00
pandora_collectionselection: function(data) {
pandora.$ui.personalListsMenu[
data.value.length ? 'enableItem' : 'disableItem'
]('newlistfromselection');
},
2011-10-29 16:57:51 +00:00
pandora_find: function() {
// fixme: duplicated
2011-10-29 16:57:51 +00:00
var action = ui._list
&& pandora.getListData(ui._list).user == pandora.user.username
? 'enableItem' : 'disableItem'
pandora.$ui.personalListsMenu[
ui._list ? 'enableItem' : 'disableItem'
]('duplicatelist');
pandora.$ui.personalListsMenu[action]('editlist');
pandora.$ui.personalListsMenu[action]('deletelist');
pandora.$ui.personalListsMenu[
ui.listSelection.length ? 'enableItem' : 'disableItem'
]('newlistfromselection');
2011-10-29 16:57:51 +00:00
},
2020-01-17 23:08:20 +00:00
pandora_finddocuments: function() {
// fixme: duplicated
var action = ui._collection
&& pandora.getListData(ui._collection).user == pandora.user.username
? 'enableItem' : 'disableItem'
pandora.$ui.personalListsMenu[
ui._collection ? 'enableItem' : 'disableItem'
]('duplicatelist');
pandora.$ui.personalListsMenu[action]('editlist');
pandora.$ui.personalListsMenu[action]('deletelist');
pandora.$ui.personalListsMenu[
ui.collectionSelection.length ? 'enableItem' : 'disableItem'
]('newlistfromselection');
},
2011-10-29 16:57:51 +00:00
pandora_listselection: function(data) {
pandora.$ui.personalListsMenu[
data.value.length ? 'enableItem' : 'disableItem'
]('newlistfromselection');
2011-09-01 04:46:44 +00:00
}
2011-10-29 16:57:51 +00:00
})
];
} else if (section == 'edits') {
2013-02-16 01:20:40 +00:00
extras = [
pandora.$ui.personalListsMenu = Ox.MenuButton({
items: [
{ id: 'newedit', title: Ox._('New Edit'), keyboard: 'control n' },
{ id: 'neweditfromselection', title: Ox._('New Edit from Selection'), keyboard: 'shift control n', disabled: !ui.edit },
{ id: 'newsmartedit', title: Ox._('New Smart Edit'), keyboard: 'alt control n'},
2013-02-16 01:20:40 +00:00
{},
{ id: 'duplicateedit', title: Ox._('Duplicate Selected Edit'), keyboard: 'control d', disabled: !ui.edit },
{ id: 'editedit', title: Ox._('Edit Selected Edit...'), keyboard: 'control e', disabled: !editable },
{ id: 'deleteedit', title: Ox._('Delete Selected Edit...'), keyboard: 'delete', disabled: !editable }
2013-02-16 01:20:40 +00:00
],
title: 'edit',
tooltip: Ox._('Manage Personal Edits'),
2013-02-16 01:20:40 +00:00
type: 'image'
})
.bindEvent({
click: function(data) {
var $list = pandora.$ui.folderList[folder.id];
if (data.id == 'newedit') {
pandora.addEdit();
} else if (data.id == 'neweditfromselection') {
2014-02-05 13:38:36 +00:00
pandora.addEdit(false, true);
} else if (data.id == 'newsmartedit') {
2014-02-05 13:38:36 +00:00
pandora.addEdit(true, false);
} else if (data.id == 'duplicateedit') {
2014-02-05 13:38:36 +00:00
pandora.addEdit(ui.edit);
} else if (data.id == 'editedit') {
pandora.ui.listDialog().open();
} else if (data.id == 'deleteedit') {
2013-02-16 01:20:40 +00:00
pandora.ui.deleteListDialog().open();
}
2011-09-01 04:46:44 +00:00
}
2013-02-16 01:20:40 +00:00
})
.bindEvent({
pandora_edit: function(data) {
var action = ui.edit
&& pandora.getListData(ui.edit).user == pandora.user.username
? 'enableItem' : 'disableItem';
pandora.$ui.personalListsMenu[
ui.edit ? 'enableItem' : 'disableItem'
]('duplicateedit');
pandora.$ui.personalListsMenu[action]('editedit');
pandora.$ui.personalListsMenu[action]('deleteedit');
},
pandora_editselection: function(data) {
pandora.$ui.personalListsMenu[
data.value.length ? 'enableItem' : 'disableItem'
]('neweditfromselection');
}
2013-02-16 01:20:40 +00:00
})
];
} else if (section == 'texts') {
2013-06-14 16:35:12 +00:00
extras = [
pandora.$ui.personalListsMenu = Ox.MenuButton({
items: [
{ id: 'newtext', title: Ox._('New Text'), keyboard: 'control n' },
{ id: 'newpdf', title: Ox._('New PDF'), keyboard: 'alt control n' },
2013-06-14 16:35:12 +00:00
{},
{ id: 'edittext', title: Ox._('Edit Selected Text...'), keyboard: 'control e', disabled: !editable },
{ id: 'deletetext', title: Ox._('Delete Selected Text...'), keyboard: 'delete', disabled: !editable }
2013-06-14 16:35:12 +00:00
],
title: 'edit',
tooltip: Ox._('Manage Personal Texts'),
2013-06-14 16:35:12 +00:00
type: 'image'
})
.bindEvent({
click: function(data) {
var $list = pandora.$ui.folderList[folder.id];
if (data.id == 'newtext') {
pandora.addText({type: 'html'});
} else if (data.id == 'newpdf') {
pandora.addText({type: 'pdf'});
} else if (data.id == 'edittext') {
pandora.ui.listDialog().open();
} else if (data.id == 'deletetext') {
2013-06-14 16:35:12 +00:00
pandora.ui.deleteListDialog().open();
}
}
})
.bindEvent('pandora_text', function(data) {
var action = ui.text
&& pandora.getListData(ui.text).user == pandora.user.username
? 'enableItem' : 'disableItem';
pandora.$ui.personalListsMenu[action]('edittext');
pandora.$ui.personalListsMenu[action]('deletetext');
2013-06-14 16:35:12 +00:00
})
];
2013-02-20 11:29:29 +00:00
} else {
extras = [];
2011-09-01 04:46:44 +00:00
}
2013-02-16 01:20:40 +00:00
}
} else if (folder.id == 'favorite') {
if (pandora.user.level == 'guest') {
extras = [infoButton(
Ox._('Favorite ' + folderItems),
Ox._('To browse and subscribe to {0} shared by other users, please sign up or sign in.', [Ox._(folderItems.toLowerCase())])
)];
2013-02-16 01:20:40 +00:00
} else {
extras = [pandora.$ui.manageListsButton['favorite'] = Ox.Button({
selectable: true,
style: 'symbol',
2013-07-14 21:36:04 +00:00
title: 'edit',
2013-05-09 10:13:58 +00:00
tooltip: Ox._('Manage Favorite {0}', [Ox._(folderItems)]),
2013-02-16 01:20:40 +00:00
type: 'image'
})
.bindEvent({
change: function(data) {
var listData;
Ox.Request.clearCache(); // fixme: remove
2013-07-15 11:39:23 +00:00
pandora.site.sectionFolders[section][i].showBrowser = !pandora.site.sectionFolders[section][i].showBrowser;
2013-05-09 10:13:58 +00:00
this.options({tooltip: data.value ? Ox._('Done') : Ox._('Manage Favorite {0}', [Ox._(folderItems)])});
2013-07-15 11:39:23 +00:00
if (pandora.site.sectionFolders[section][i].showBrowser) {
2013-02-16 01:20:40 +00:00
pandora.$ui.folderList.favorite.replaceWith(
2013-07-15 11:39:23 +00:00
pandora.$ui.folderBrowser.favorite = pandora.ui.folderBrowser('favorite', section)
2013-02-16 01:20:40 +00:00
);
pandora.$ui.folder[i].options({collapsed: false});
2013-02-16 01:20:40 +00:00
} else {
listData = pandora.getListData();
if (
pandora.$ui.folderList.favorite.options('selected').length
&& !listData.subscribed
) {
// the selected list in the favorites browser is not in the favorites folder
pandora.$ui.folderList.favorite.options({selected: []});
2013-07-15 11:39:23 +00:00
if (Ox.getObjectById(pandora.site.sectionFolders[section], 'featured').showBrowser) {
2013-02-16 01:20:40 +00:00
// but in the featured browser
pandora.$ui.folderList.featured.options({selected: [listData.id]});
} else {
// and nowhere else
2016-10-04 22:00:03 +00:00
if (section == 'items') {
pandora.UI.set({
find: pandora.site.user.ui.find
});
} else if (section == 'documents') {
pandora.UI.set({
findDocuments: pandora.site.user.ui.findDocuments
});
} else {
Ox.print('unknown section', section);
}
}
2011-09-01 04:46:44 +00:00
}
2013-02-16 01:20:40 +00:00
pandora.$ui.folderBrowser.favorite.replaceWith(
2013-07-15 11:39:23 +00:00
pandora.$ui.folderList.favorite = pandora.ui.folderList('favorite', section)
2013-02-16 01:20:40 +00:00
);
2011-05-25 19:42:45 +00:00
}
2013-02-16 01:20:40 +00:00
pandora.resizeFolders();
}
})];
2011-05-25 19:42:45 +00:00
}
2013-02-16 01:20:40 +00:00
} else if (folder.id == 'featured') {
if (!canEditFeatured) {
extras = [infoButton(
Ox._('Featured ' + folderItems),
Ox._('Featured {0} are selected public {0}, picked by the {1} staff.', [Ox._(folderItems.toLowerCase()), pandora.site.site.name])
)];
2013-02-16 01:20:40 +00:00
} else {
extras = [pandora.$ui.manageListsButton['featured'] = Ox.Button({
selectable: true,
style: 'symbol',
2013-07-14 21:36:04 +00:00
title: 'edit',
2013-05-09 10:13:58 +00:00
tooltip: Ox._('Manage Featured {0}', [Ox._(folderItems)]),
2013-02-16 01:20:40 +00:00
type: 'image'
2011-05-25 19:42:45 +00:00
})
.bindEvent({
2013-02-16 01:20:40 +00:00
change: function(data) {
var listData;
Ox.Request.clearCache(); // fixme: remove
2013-07-15 11:39:23 +00:00
pandora.site.sectionFolders[section][i].showBrowser = !pandora.site.sectionFolders[section][i].showBrowser;
2013-05-09 10:13:58 +00:00
this.options({tooltip: data.value ? Ox._('Done') : Ox._('Manage Favorite {0}', [Ox._(folderItems)])});
2013-07-15 11:39:23 +00:00
if (pandora.site.sectionFolders[section][i].showBrowser) {
2013-02-16 01:20:40 +00:00
pandora.$ui.folderList.featured.replaceWith(
2013-07-15 11:39:23 +00:00
pandora.$ui.folderBrowser.featured = pandora.ui.folderBrowser('featured', section)
2013-02-16 01:20:40 +00:00
);
pandora.$ui.folder[i].options({collapsed: false});
2013-02-16 01:20:40 +00:00
} else {
listData = pandora.getListData();
Ox.Log('', 'FEATURED', listData)
if (
pandora.$ui.folderList.featured.options('selected').length
&& listData.status != 'featured'
) {
// the selected list in the featured browser is not in the featured folder
pandora.$ui.folderList.featured.options({selected: []});
if (listData.user == pandora.user.username) {
// but in the personal folder
pandora.$ui.folderList.personal.options({selected: [listData.id]});
} else if (
listData.subscribed
2013-07-15 11:39:23 +00:00
|| Ox.getObjectById(pandora.site.sectionFolders[section], 'favorite').showBrowser
2013-02-16 01:20:40 +00:00
) {
// but in the favorites folder or browser
pandora.$ui.folderList.favorite.options({selected: [listData.id]});
} else {
// and nowhere else
2016-10-04 22:00:03 +00:00
if (section == 'items') {
pandora.UI.set({
find: pandora.site.user.ui.find
});
} else if (section == 'documents') {
pandora.UI.set({
findDocuments: pandora.site.user.ui.findDocuments
});
} else {
Ox.print('unknown section', section);
}
2013-02-16 01:20:40 +00:00
}
}
pandora.$ui.folderBrowser.featured.replaceWith(
2013-07-15 11:39:23 +00:00
pandora.$ui.folderList.featured = pandora.ui.folderList('featured', section)
2013-02-16 01:20:40 +00:00
);
2011-05-25 19:42:45 +00:00
}
pandora.resizeFolders();
}
2013-02-16 01:20:40 +00:00
})];
}
} else if (folder.id == 'volumes') {
if (pandora.user.level == 'guest') {
extras = [infoButton(
Ox._('Local Volumes'),
Ox._('To import {0} from a local disk, please sign up or sign in.', [Ox._(pandora.site.itemName.plural.toLocaleLowerCase())])
)];
2013-02-16 01:20:40 +00:00
} else {
extras = [Ox.MenuButton({
items: [
2013-05-09 10:13:58 +00:00
{ id: 'add', title: Ox._('Add Volume...'), disabled: true },
{ id: 'scan', title: Ox._('Scan Selected Volume...'), disabled: true },
{ id: 'remove', title: Ox._('Remove Selected Volume...'), disabled: true },
2013-02-16 01:20:40 +00:00
{},
2013-05-09 10:13:58 +00:00
{ id: 'import', title: Ox._('Import {0}...',
2014-02-03 05:58:33 +00:00
[Ox._(pandora.site.itemName.plural)]), disabled: true }
2013-02-16 01:20:40 +00:00
],
title: 'edit',
2013-05-09 10:13:58 +00:00
tooltip: Ox._('Manage Volumes'),
2013-02-16 01:20:40 +00:00
type: 'image'
})
.bindEvent({
2013-02-16 01:20:40 +00:00
click: function(data) {
}
2013-02-16 01:20:40 +00:00
})];
}
}
pandora.$ui.folder[i] = Ox.CollapsePanel({
id: folder.id,
collapsed: !ui.showFolder.items[folder.id],
extras: extras,
size: 16,
2013-07-17 10:25:01 +00:00
title: Ox._(folder.title)
2013-02-16 01:20:40 +00:00
})
.bindEvent({
click: function(data) {
if (data.id == 'new' || data.id == 'newsmart') {
pandora.addFolderItem(section, data.id == 'newsmart', false);
2013-02-16 01:20:40 +00:00
} else if (data.id == 'browse') {
// ...
2011-05-25 19:42:45 +00:00
}
2013-02-16 01:20:40 +00:00
},
toggle: function(data) {
data.collapsed && pandora.$ui.folderList[folder.id].loseFocus();
2016-10-04 22:00:03 +00:00
pandora.UI.set('showFolder.' + section + '.' + folder.id, !data.collapsed);
2013-02-16 01:20:40 +00:00
pandora.resizeFolders();
}
});
2013-07-15 11:39:23 +00:00
pandora.$ui.folderList[folder.id] = pandora.ui.folderList(folder.id, section)
2013-02-16 01:20:40 +00:00
.bindEvent({
selectnext: function() {
2013-02-16 01:20:40 +00:00
// ...
},
selectprevious: function() {
2013-02-16 01:20:40 +00:00
// ...
}
})
.bindEventOnce({
init: function(data) {
if (++initCounter == pandora.site.sectionFolders[section].length) {
2013-02-16 01:20:40 +00:00
pandora.$ui.folder.forEach(function($folder) {
that.append($folder);
});
pandora.resizeFolders(section);
2013-02-16 01:20:40 +00:00
pandora.selectList();
}
},
load: function(data) {
if (++loadCounter == pandora.site.sectionFolders[section].length) {
pandora.$ui.mainMenu.replaceItemMenu();
}
2013-02-16 01:20:40 +00:00
}
})
.appendTo(pandora.$ui.folder[i].$content);
pandora.$ui.folderPlaceholder[folder.id] = pandora.ui.folderPlaceholder(folder.id, section)
.hide()
.appendTo(pandora.$ui.folder[i].$content);
2013-02-16 01:20:40 +00:00
});
2011-09-01 04:46:44 +00:00
function infoButton(title, text) {
return Ox.Button({
style: 'symbol',
title: 'info',
type: 'image'
}).bindEvent({
click: function() {
2013-03-03 05:34:44 +00:00
var $dialog = pandora.ui.iconDialog({
2016-10-04 22:00:03 +00:00
buttons: title != Ox._('Featured ' + folderItems) ? [
2013-05-09 10:13:58 +00:00
Ox.Button({title: Ox._('Sign Up...')}).bindEvent({
2011-11-06 22:03:24 +00:00
click: function() {
$dialog.close();
pandora.$ui.accountDialog = pandora.ui.accountDialog('signup').open();
}
}),
2013-05-09 10:13:58 +00:00
Ox.Button({title: Ox._('Sign In...')}).bindEvent({
2011-11-06 22:03:24 +00:00
click: function() {
$dialog.close();
pandora.$ui.accountDialog = pandora.ui.accountDialog('signin').open();
}
}),
{},
2013-05-09 10:13:58 +00:00
Ox.Button({title: Ox._('Not Now')}).bindEvent({
2011-11-06 22:03:24 +00:00
click: function() {
$dialog.close();
}
})
] : [
2013-05-09 10:13:58 +00:00
Ox.Button({title: Ox._('Close')}).bindEvent({
2011-11-06 22:03:24 +00:00
click: function() {
$dialog.close();
}
})
],
content: text,
2011-09-01 04:46:44 +00:00
title: title
}).open();
}
});
}
that.bindEvent({
2013-07-14 17:22:26 +00:00
pandora_edit: function() {
var folder = pandora.getListData().folder,
edit = pandora.user.ui.edit,
previousEdit = pandora.UI.getPrevious().edit;
if (edit != previousEdit) {
2013-07-14 17:22:26 +00:00
Ox.forEach(pandora.$ui.folderList, function($list, id) {
id != folder && $list.options('selected', []);
2013-07-14 17:22:26 +00:00
});
folder && pandora.$ui.folderList[folder].options({selected: [edit]});
2013-07-14 17:22:26 +00:00
}
},
pandora_find: function() {
var folder = pandora.getListData().folder,
list = pandora.user.ui._list,
previousList = pandora.UI.getPrevious()._list;
if (list != previousList) {
Ox.forEach(pandora.$ui.folderList, function($list, id) {
id != folder && $list.options('selected', []);
});
folder && pandora.$ui.folderList[folder].options({selected: [list]});
}
/*
if (!pandora.user.ui._list && previousUI._list) {
pandora.$ui.folderList[pandora.getListData(previous)]
Ox.forEach(pandora.$ui.folderList, function($list) {
$list.options({selected: []});
});
}
*/
2013-02-16 01:20:40 +00:00
},
2016-10-04 22:00:03 +00:00
pandora_finddocuments: function() {
var folder = pandora.getListData().folder,
list = pandora.user.ui._collection,
previousList = pandora.UI.getPrevious()._collection;
if (list != previousList) {
Ox.forEach(pandora.$ui.folderList, function($list, id) {
id != folder && $list.options('selected', []);
});
folder && pandora.$ui.folderList[folder].options({selected: [list]});
}
},
2013-02-16 01:20:40 +00:00
pandora_text: function() {
if (!pandora.user.ui.text) {
Ox.forEach(pandora.$ui.folderList, function($list, id) {
$list.options('selected', []);
});
}
}
})
2011-05-25 19:42:45 +00:00
return that;
};