merge changes

This commit is contained in:
j 2011-01-30 17:11:32 +05:30
commit a52d2cb74f

View file

@ -2,36 +2,34 @@
Pandora Pandora
***/ ***/
var pandora = new Ox.App({ // fixme: never set ui.videoPosition to 0 ... set to null a.k.a. delete
apiURL: '/api/', // fixme: sort=-director doesn't work
init: 'init', // fixme: don't reload full right panel on sortSelect
}).launch(function(data) {
//Ox.print('data', data); (function() {
// fixme: never set ui.videoPosition to 0 ... set to null a.k.a. delete window.pandora = new Ox.App({url: '/api/'}).launch(function(data) {
// fixme: sort=-director doesn't work
// fixme: don't reload full right panel on sortSelect
var app = { Ox.print('Ox.App launch', data);
$ui: {
body: $('body'), $.extend(app, {
document: $(document), $ui: {
window: $(window) body: $('body'),
.resize(resizeWindow) document: $(document),
.unload(unloadWindow) window: $(window)
}, .resize(resizeWindow)
config: data.config, .unload(unloadWindow)
requests: {}, },
ui: { config: data.config,
findKeys: $.map(data.config.itemKeys, function(key, i) { ui: {
return key.find ? key : null; findKeys: $.map(data.config.itemKeys, function(key, i) {
}), return key.find ? key : null;
infoRatio: 16 / 9, }),
scrollbarSize: $.browser.mozilla ? 16 : 12, infoRatio: 16 / 9,
sectionElement: 'buttons', scrollbarSize: $.browser.mozilla ? 16 : 12,
sectionFolders: { sectionElement: 'buttons',
site: $.merge([ sectionFolders: {
site: $.merge([
{id: 'site', title: 'Site', items: $.merge([ {id: 'site', title: 'Site', items: $.merge([
{id: 'home', title: 'Home'} {id: 'home', title: 'Home'}
], $.merge(data.config.sitePages, [ ], $.merge(data.config.sitePages, [
@ -48,31 +46,23 @@ var pandora = new Ox.App({
{id: 'users', title: 'Users'} {id: 'users', title: 'Users'}
]} ]}
] : []), ] : []),
items: [ items: [
{id: 'personal', title: 'Personal Lists'}, {id: 'personal', title: 'Personal Lists'},
{id: 'favorite', title: 'Favorite Lists', showBrowser: false}, {id: 'favorite', title: 'Favorite Lists', showBrowser: false},
{id: 'featured', title: 'Featured Lists', showBrowser: false} {id: 'featured', title: 'Featured Lists', showBrowser: false}
], ],
}, },
selectedMovies: [], selectedMovies: [],
sortKeys: $.map(data.config.itemKeys, function(key, i) { sortKeys: $.map(data.config.itemKeys, function(key, i) {
return key.columnWidth ? key : null; return key.columnWidth ? key : null;
}) })
}, },
user: data.user user: data.user.level == 'guest' ? $.extend({}, data.config.user) : data.user
}; });
pandora.app = app; // remove later if (data.user.level == 'guest' && $.browser.mozilla) {
app.user.ui.theme = 'classic'
if ($.browser.mozilla) { }
app.config.user.ui.theme = 'classic'
}
if (app.user.level == 'guest') {
app.user = $.extend({}, app.config.user);
}
function load() {
URL.parse(); URL.parse();
window.onpopstate = function() { window.onpopstate = function() {
@ -80,33 +70,21 @@ var pandora = new Ox.App({
}; };
Ox.theme(app.user.ui.theme); Ox.theme(app.user.ui.theme);
app.$ui.appPanel = ui.appPanel(); app.$ui.appPanel = ui.appPanel().display();
$(function() { Ox.Request.requests() && app.$ui.loadingIcon.start();
app.$ui.body.ajaxStart(app.$ui.loadingIcon.start);
app.$ui.body.ajaxStop(app.$ui.loadingIcon.stop);
app.$ui.appPanel.display(); app.ui.sectionButtonsWidth = app.$ui.sectionButtons.width() + 8;
Ox.Request.requests() && app.$ui.loadingIcon.start(); window.pandora.app = app;
app.$ui.body.ajaxStart(app.$ui.loadingIcon.start);
app.$ui.body.ajaxStop(app.$ui.loadingIcon.stop);
app.ui.sectionButtonsWidth = app.$ui.sectionButtons.width() + 8; });
}); var app = {
requests: {}
} };
function login(data) {
app.user = data.user;
Ox.theme(app.user.ui.theme);
app.$ui.appPanel.reload();
}
function logout(data) {
app.user = data.user;
Ox.theme(app.config.user.ui.theme);
app.$ui.appPanel.reload();
}
var ui = { var ui = {
accountDialog: function(action) { accountDialog: function(action) {
@ -744,13 +722,16 @@ var pandora = new Ox.App({
] : [], [ ] : [], [
app.$ui.findSelect = new Ox.Select({ app.$ui.findSelect = new Ox.Select({
id: 'select', id: 'select',
items: $.merge($.map(app.ui.findKeys, function(key, i) { items: $.merge($.merge([{
id: 'all',
title: 'Find: All'
}], $.map(app.ui.findKeys, function(key, i) {
return { return {
id: key.id, id: key.id,
checked: key.id == findKey, checked: key.id == findKey,
title: 'Find: ' + key.title title: 'Find: ' + key.title
}; };
}), [{}, { })), [{}, {
id: 'advanced', id: 'advanced',
title: 'Find: Advanced' title: 'Find: Advanced'
}]), }]),
@ -994,7 +975,7 @@ var pandora = new Ox.App({
}, function(result) { }, function(result) {
Ox.print('result', result) Ox.print('result', result)
if (result.data.user == app.user.username || result.data.subscribed) { if (result.data.user == app.user.username || result.data.subscribed) {
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
app.$ui.folderList[ app.$ui.folderList[
result.data.user == app.user.username ? 'personal' : 'favorite' result.data.user == app.user.username ? 'personal' : 'favorite'
].reloadList(); ].reloadList();
@ -1223,14 +1204,14 @@ var pandora = new Ox.App({
// fixme: is this the best way to delete a ui preference? // fixme: is this the best way to delete a ui preference?
delete app.user.ui.lists[data.ids[0]]; delete app.user.ui.lists[data.ids[0]];
UI.set({lists: app.user.ui.lists}); UI.set({lists: app.user.ui.lists});
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
$list.reloadList(); $list.reloadList();
}); });
} else if (id == 'favorite') { } else if (id == 'favorite') {
pandora.api.unsubscribeFromList({ pandora.api.unsubscribeFromList({
id: data.ids[0] id: data.ids[0]
}, function(result) { }, function(result) {
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
$list.reloadList(); $list.reloadList();
}); });
} else if (id == 'featured' && app.user.level == 'admin') { } else if (id == 'featured' && app.user.level == 'admin') {
@ -1240,7 +1221,7 @@ var pandora = new Ox.App({
}, function(result) { }, function(result) {
// fixme: duplicated // fixme: duplicated
if (result.data.user == app.user.username || result.data.subscribed) { if (result.data.user == app.user.username || result.data.subscribed) {
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
app.$ui.folderList[ app.$ui.folderList[
result.data.user == app.user.username ? 'personal' : 'favorite' result.data.user == app.user.username ? 'personal' : 'favorite'
].reloadList(); ].reloadList();
@ -1371,7 +1352,7 @@ var pandora = new Ox.App({
id = result.data.id; id = result.data.id;
UI.set(['lists', id].join('|'), app.config.user.ui.lists['']); // fixme: necessary? UI.set(['lists', id].join('|'), app.config.user.ui.lists['']); // fixme: necessary?
URL.set('?find=list:' + id) URL.set('?find=list:' + id)
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
$list.reloadList().bindEvent({load: load}); $list.reloadList().bindEvent({load: load});
function load(event, data) { function load(event, data) {
$list.gainFocus() $list.gainFocus()
@ -1393,7 +1374,7 @@ var pandora = new Ox.App({
}) })
.bindEvent({ .bindEvent({
change: function(event, data) { change: function(event, data) {
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
app.ui.sectionFolders.items[i].showBrowser = !app.ui.sectionFolders.items[i].showBrowser; app.ui.sectionFolders.items[i].showBrowser = !app.ui.sectionFolders.items[i].showBrowser;
if (app.ui.sectionFolders.items[i].showBrowser) { if (app.ui.sectionFolders.items[i].showBrowser) {
app.$ui.folderList.favorite.replaceWith( app.$ui.folderList.favorite.replaceWith(
@ -1417,7 +1398,7 @@ var pandora = new Ox.App({
}) })
.bindEvent({ .bindEvent({
change: function(event, data) { change: function(event, data) {
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
app.ui.sectionFolders.items[i].showBrowser = !app.ui.sectionFolders.items[i].showBrowser; app.ui.sectionFolders.items[i].showBrowser = !app.ui.sectionFolders.items[i].showBrowser;
if (app.ui.sectionFolders.items[i].showBrowser) { if (app.ui.sectionFolders.items[i].showBrowser) {
app.$ui.folderList.featured.replaceWith( app.$ui.folderList.featured.replaceWith(
@ -1450,7 +1431,7 @@ var pandora = new Ox.App({
}, function(result) { }, function(result) {
id = result.data.id; id = result.data.id;
URL.set('?find=list:' + id) URL.set('?find=list:' + id)
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
$list.reloadList().bindEvent({load: load}); $list.reloadList().bindEvent({load: load});
function load(event, data) { function load(event, data) {
$list.gainFocus() $list.gainFocus()
@ -3401,6 +3382,18 @@ var pandora = new Ox.App({
) > -1 ? '+' : '-'; ) > -1 ? '+' : '-';
} }
function login(data) {
app.user = data.user;
Ox.theme(app.user.ui.theme);
app.$ui.appPanel.reload();
}
function logout(data) {
app.user = data.user;
Ox.theme(app.config.user.ui.theme);
app.$ui.appPanel.reload();
}
function reloadGroups(i) { function reloadGroups(i) {
var query = Query.toObject(); var query = Query.toObject();
app.$ui.list.options({ app.$ui.list.options({
@ -3430,7 +3423,7 @@ var pandora = new Ox.App({
function reloadList() { function reloadList() {
Ox.print('reloadList') Ox.print('reloadList')
var listData = getListData(); var listData = getListData();
Ox.Request.emptyCache(); // fixme: remove Ox.Request.clearCache(); // fixme: remove
app.$ui.groups.forEach(function($group) { app.$ui.groups.forEach(function($group) {
$group.reloadList(); $group.reloadList();
}); });
@ -3936,6 +3929,4 @@ var pandora = new Ox.App({
} }
} }
load(); })();
});