2011-07-29 18:37:11 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.ui.folders = function() {
|
2011-06-19 17:49:25 +00:00
|
|
|
var that = Ox.Element()
|
2011-05-25 19:42:45 +00:00
|
|
|
.css({overflowX: 'hidden', overflowY: 'auto'})
|
|
|
|
.bindEvent({
|
|
|
|
resize: function(event, data) {
|
|
|
|
pandora.resizeFolders();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var counter = 0;
|
|
|
|
//var $sections = [];
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.folder = [];
|
|
|
|
pandora.$ui.folderBrowser = {};
|
|
|
|
pandora.$ui.folderList = {};
|
2011-09-01 07:00:35 +00:00
|
|
|
pandora.$ui.findListElement = {};
|
|
|
|
pandora.$ui.findListSelect = {};
|
|
|
|
pandora.$ui.findListInput = {};
|
2011-09-04 16:08:28 +00:00
|
|
|
pandora.$ui.manageListsButton = {};
|
2011-09-01 04:46:44 +00:00
|
|
|
if (pandora.user.ui.section == 'items') {
|
2011-08-28 19:50:38 +00:00
|
|
|
pandora.site.sectionFolders.items.forEach(function(folder, i) {
|
2011-09-01 04:46:44 +00:00
|
|
|
var extras;
|
|
|
|
if (folder.id == 'personal') {
|
|
|
|
if (pandora.user.level == 'guest') {
|
|
|
|
extras = [infoButton('Personal Lists', 'To create and publish your own lists of movies, please sign up or sign in.')];
|
|
|
|
} else {
|
|
|
|
extras = [Ox.Select({
|
|
|
|
items: [
|
|
|
|
{ id: 'new', title: 'New List...' },
|
|
|
|
{ id: 'newfromselection', title: 'New List from Current Selection...', disabled: true },
|
2011-09-04 16:08:28 +00:00
|
|
|
{},
|
2011-09-01 04:46:44 +00:00
|
|
|
{ id: 'newsmart', title: 'New Smart List...' },
|
|
|
|
{ id: 'newfromresults', title: 'New Smart List from Current Results...', disabled: true },
|
|
|
|
{},
|
2011-09-04 16:08:28 +00:00
|
|
|
{ id: 'copyselection', title: 'Copy Selection to List...' },
|
|
|
|
{ id: 'moveselection', title: 'Move Selection to List...' }
|
2011-09-01 04:46:44 +00:00
|
|
|
],
|
|
|
|
max: 0,
|
|
|
|
min: 0,
|
|
|
|
selectable: false,
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function(event, data) {
|
2011-09-04 16:08:28 +00:00
|
|
|
var $list = pandora.$ui.folderList[folder.id];
|
|
|
|
// fixme: duplicated
|
2011-09-01 04:46:44 +00:00
|
|
|
if (data.id == 'new' || data.id == 'newsmart') {
|
|
|
|
pandora.api.addList({
|
|
|
|
name: 'Untitled',
|
|
|
|
status: 'private',
|
|
|
|
type: data.id == 'new' ? 'static' : 'smart'
|
|
|
|
}, function(result) {
|
2011-09-04 16:08:28 +00:00
|
|
|
var id = result.data.id;
|
2011-09-01 04:46:44 +00:00
|
|
|
pandora.UI.set(['lists', id].join('|'), pandora.site.user.ui.lists['']); // fixme: necessary?
|
|
|
|
pandora.URL.set('?find=list:' + id)
|
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
|
|
|
$list.reloadList().bindEventOnce({
|
|
|
|
load: function(event, data) {
|
|
|
|
$list.gainFocus()
|
|
|
|
.options({selected: [id]})
|
|
|
|
.editCell(id, 'name');
|
|
|
|
}
|
|
|
|
});
|
2011-05-25 19:42:45 +00:00
|
|
|
});
|
2011-09-01 04:46:44 +00:00
|
|
|
}
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
2011-09-01 04:46:44 +00:00
|
|
|
})];
|
|
|
|
}
|
|
|
|
} else if (folder.id == 'favorite') {
|
|
|
|
if (pandora.user.level == 'guest') {
|
|
|
|
extras = [infoButton('Favorite Lists', 'To browse and subscribe to shared lists from other users, please sign up or sign in.')];
|
|
|
|
} else {
|
2011-09-04 16:08:28 +00:00
|
|
|
extras = [pandora.$ui.manageListsButton['favorite'] = Ox.Button({
|
2011-09-01 04:46:44 +00:00
|
|
|
selectable: true,
|
|
|
|
style: 'symbol',
|
|
|
|
title: 'Edit',
|
|
|
|
tooltip: 'Manage Favorite Lists',
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
change: function(event, data) {
|
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
|
|
|
pandora.site.sectionFolders.items[i].showBrowser = !pandora.site.sectionFolders.items[i].showBrowser;
|
|
|
|
if (pandora.site.sectionFolders.items[i].showBrowser) {
|
|
|
|
pandora.$ui.folderList.favorite.replaceWith(
|
|
|
|
pandora.$ui.folderBrowser.favorite = pandora.ui.folderBrowser('favorite')
|
|
|
|
);
|
|
|
|
} else {
|
2011-09-04 16:08:28 +00:00
|
|
|
listData = pandora.getListData();
|
|
|
|
if (
|
|
|
|
pandora.$ui.folderList.favorite.options('selected').length
|
|
|
|
&& !listData.subscribed
|
|
|
|
) {
|
2011-09-04 16:42:34 +00:00
|
|
|
// the selected list in the favorites browser is not in the favorites folder
|
2011-09-04 16:08:28 +00:00
|
|
|
pandora.$ui.folderList.favorite.options({selected: []});
|
|
|
|
if (Ox.getObjectById(pandora.site.sectionFolders.items, 'featured').showBrowser) {
|
|
|
|
// but in the featured browser
|
|
|
|
pandora.$ui.folderList.featured.options({selected: [listData.id]});
|
|
|
|
} else {
|
|
|
|
// and nowhere else
|
|
|
|
pandora.URL.set('?find=');
|
|
|
|
}
|
|
|
|
}
|
2011-09-01 04:46:44 +00:00
|
|
|
pandora.$ui.folderBrowser.favorite.replaceWith(
|
|
|
|
pandora.$ui.folderList.favorite = pandora.ui.folderList('favorite')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
pandora.resizeFolders();
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
2011-09-01 04:46:44 +00:00
|
|
|
})];
|
|
|
|
}
|
|
|
|
} else if (folder.id == 'featured') {
|
|
|
|
if (pandora.user.level != 'admin') {
|
|
|
|
extras = [infoButton('Featured Lists', 'Featured lists are selected public lists, picked by the ' + pandora.site.site.name + ' staff.')];
|
|
|
|
} else {
|
2011-09-04 16:08:28 +00:00
|
|
|
extras = [pandora.$ui.manageListsButton['featured'] = Ox.Button({
|
2011-09-01 04:46:44 +00:00
|
|
|
selectable: true,
|
|
|
|
style: 'symbol',
|
|
|
|
title: 'Edit',
|
|
|
|
tooltip: 'Manage Featured Lists',
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
change: function(event, data) {
|
2011-09-04 16:08:28 +00:00
|
|
|
var listData;
|
2011-09-01 04:46:44 +00:00
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
|
|
|
pandora.site.sectionFolders.items[i].showBrowser = !pandora.site.sectionFolders.items[i].showBrowser;
|
|
|
|
if (pandora.site.sectionFolders.items[i].showBrowser) {
|
|
|
|
pandora.$ui.folderList.featured.replaceWith(
|
2011-09-04 16:08:28 +00:00
|
|
|
pandora.$ui.folderBrowser.featured = pandora.ui.folderBrowser('featured')
|
|
|
|
);
|
2011-09-01 04:46:44 +00:00
|
|
|
} else {
|
2011-09-04 16:08:28 +00:00
|
|
|
listData = pandora.getListData();
|
|
|
|
Ox.print('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]});
|
2011-09-04 16:42:34 +00:00
|
|
|
} else if (
|
|
|
|
listData.subscribed
|
|
|
|
|| Ox.getObjectById(pandora.site.sectionFolders.items, 'favorite').showBrowser
|
|
|
|
) {
|
|
|
|
// but in the favorites folder or browser
|
2011-09-04 16:08:28 +00:00
|
|
|
pandora.$ui.folderList.favorite.options({selected: [listData.id]});
|
|
|
|
} else {
|
|
|
|
// and nowhere else
|
|
|
|
pandora.URL.set('?find=');
|
|
|
|
}
|
|
|
|
}
|
2011-09-01 04:46:44 +00:00
|
|
|
pandora.$ui.folderBrowser.featured.replaceWith(
|
|
|
|
pandora.$ui.folderList.featured = pandora.ui.folderList('featured')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
pandora.resizeFolders();
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
2011-09-01 04:46:44 +00:00
|
|
|
})];
|
|
|
|
}
|
|
|
|
} else if (folder.id == 'volumes') {
|
|
|
|
if (pandora.user.level == 'guest') {
|
|
|
|
extras = [infoButton('Local Volumes', 'To import movies from a local disk, please sign up or sign in.')];
|
|
|
|
} else {
|
|
|
|
extras = [Ox.Select({
|
|
|
|
items: [
|
|
|
|
{ id: 'add', title: 'Add Volume...' },
|
|
|
|
{ id: 'scan', title: 'Scan Selected Volume...' },
|
|
|
|
{ id: 'remove', title: 'Remove Selected Volume...' },
|
|
|
|
{},
|
|
|
|
{ id: 'import', title: 'Import Movies...' }
|
|
|
|
],
|
|
|
|
max: 0,
|
|
|
|
min: 0,
|
|
|
|
selectable: false,
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function(data) {
|
|
|
|
}
|
|
|
|
})];
|
|
|
|
}
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
2011-06-19 17:49:25 +00:00
|
|
|
pandora.$ui.folder[i] = Ox.CollapsePanel({
|
2011-05-25 19:42:45 +00:00
|
|
|
id: folder.id,
|
2011-06-06 15:48:11 +00:00
|
|
|
collapsed: !pandora.user.ui.showFolder.items[folder.id],
|
2011-05-25 19:42:45 +00:00
|
|
|
extras: extras,
|
|
|
|
size: 16,
|
|
|
|
title: folder.title
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
// fixme: duplicated
|
|
|
|
click: function(event, data) {
|
2011-06-06 15:48:11 +00:00
|
|
|
var $list = pandora.$ui.folderList[i],
|
2011-05-25 19:42:45 +00:00
|
|
|
hasFocus, id;
|
|
|
|
if (data.id == 'new' || data.id == 'newsmart') {
|
|
|
|
pandora.api.addList({
|
|
|
|
name: 'Untitled',
|
|
|
|
status: 'private',
|
|
|
|
type: data.id == 'new' ? 'static' : 'smart'
|
|
|
|
}, function(result) {
|
|
|
|
id = result.data.id;
|
|
|
|
pandora.URL.set('?find=list:' + id)
|
|
|
|
Ox.Request.clearCache(); // fixme: remove
|
|
|
|
$list.reloadList().bindEventOnce({
|
|
|
|
load: function(event, data) {
|
|
|
|
$list.gainFocus()
|
|
|
|
.options({selected: [id]})
|
|
|
|
.editCell(id, 'name');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (data.id == 'browse') {
|
|
|
|
alert('??')
|
|
|
|
/*
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.sectionList[1].replaceWith(pandora.$ui.publicLists = pandora.ui.publicLists());
|
|
|
|
pandora.site.showAllPublicLists = true;
|
2011-05-25 19:42:45 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggle: function(event, data) {
|
2011-06-06 15:48:11 +00:00
|
|
|
data.collapsed && pandora.$ui.folderList[folder.id].loseFocus();
|
2011-05-25 19:42:45 +00:00
|
|
|
pandora.UI.set('showFolder|items|' + folder.id, !data.collapsed);
|
|
|
|
pandora.resizeFolders();
|
|
|
|
}
|
|
|
|
});
|
2011-06-06 15:48:11 +00:00
|
|
|
//$sections.push(pandora.$ui.section[i]);
|
|
|
|
pandora.$ui.folderList[folder.id] = pandora.ui.folderList(folder.id)
|
2011-05-25 19:42:45 +00:00
|
|
|
.bindEventOnce({
|
|
|
|
init: function(event, data) {
|
|
|
|
Ox.print('init', i, counter)
|
2011-09-01 04:46:44 +00:00
|
|
|
if (++counter == 4) {
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.folder.forEach(function($folder) {
|
2011-05-25 19:42:45 +00:00
|
|
|
that.append($folder);
|
|
|
|
});
|
|
|
|
pandora.resizeFolders();
|
|
|
|
pandora.selectList(); //fixme: doesn't work
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2011-06-06 15:48:11 +00:00
|
|
|
.appendTo(pandora.$ui.folder[i].$content);
|
2011-05-25 19:42:45 +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() {
|
|
|
|
var $dialog = Ox.Dialog({
|
|
|
|
buttons: Ox.merge([
|
|
|
|
Ox.Button({title: 'Close'}).bindEvent({
|
|
|
|
click: function() {
|
|
|
|
$dialog.close();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
], title != 'Featured Lists' ? [
|
|
|
|
Ox.Button({title: 'Sign Up'}).bindEvent({
|
|
|
|
click: function() {
|
|
|
|
$dialog.close();
|
|
|
|
pandora.$ui.accountDialog = pandora.ui.accountDialog('signup').open();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
Ox.Button({title: 'Sign In'}).bindEvent({
|
|
|
|
click: function() {
|
|
|
|
$dialog.close();
|
|
|
|
pandora.$ui.accountDialog = pandora.ui.accountDialog('signin').open();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
] : []),
|
|
|
|
content: Ox.Element()
|
|
|
|
.append(
|
|
|
|
$('<img>')
|
|
|
|
.attr({src: '/static/png/icon64.png'})
|
|
|
|
.css({position: 'absolute', left: '16px', top: '16px', width: '64px', height: '64px'})
|
|
|
|
)
|
|
|
|
.append(
|
|
|
|
$('<div>')
|
|
|
|
.css({position: 'absolute', left: '96px', top: '16px', width: '192px'})
|
|
|
|
.html(text)
|
|
|
|
),
|
|
|
|
fixedSize: true,
|
|
|
|
height: 128,
|
|
|
|
width: 304,
|
|
|
|
title: title
|
|
|
|
}).open();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-05-25 19:42:45 +00:00
|
|
|
that.toggle = function() {
|
|
|
|
|
|
|
|
};
|
|
|
|
return that;
|
|
|
|
};
|