updating to new app api, refactoring

This commit is contained in:
rlx 2011-01-30 03:54:38 +00:00
parent d172ef85e2
commit 2ac007e8a9

View file

@ -2,18 +2,17 @@
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);
$.extend(app, {
$ui: { $ui: {
body: $('body'), body: $('body'),
document: $(document), document: $(document),
@ -22,7 +21,6 @@ var pandora = new Ox.App({
.unload(unloadWindow) .unload(unloadWindow)
}, },
config: data.config, config: data.config,
requests: {},
ui: { ui: {
findKeys: $.map(data.config.itemKeys, function(key, i) { findKeys: $.map(data.config.itemKeys, function(key, i) {
return key.find ? key : null; return key.find ? key : null;
@ -59,32 +57,20 @@ var pandora = new Ox.App({
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() {
URL.update(); URL.update();
}; };
Ox.theme(app.user.ui.theme); Ox.theme(app.user.ui.theme);
app.$ui.appPanel = ui.appPanel(); app.$ui.appPanel = ui.appPanel().display();
$(function() {
app.$ui.appPanel.display();
Ox.Request.requests() && app.$ui.loadingIcon.start(); Ox.Request.requests() && app.$ui.loadingIcon.start();
app.$ui.body.ajaxStart(app.$ui.loadingIcon.start); app.$ui.body.ajaxStart(app.$ui.loadingIcon.start);
@ -92,21 +78,13 @@ var pandora = new Ox.App({
app.ui.sectionButtonsWidth = app.$ui.sectionButtons.width() + 8; app.ui.sectionButtonsWidth = app.$ui.sectionButtons.width() + 8;
window.pandora.app = app;
}); });
} 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()
@ -3308,6 +3289,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({
@ -3337,7 +3330,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();
}); });
@ -3843,6 +3836,4 @@ var pandora = new Ox.App({
} }
} }
load(); })();
});