forked from 0x2620/pandora
updating to new app api, refactoring
This commit is contained in:
parent
b42dfb5e0b
commit
028e77ae4b
1 changed files with 75 additions and 84 deletions
|
@ -2,18 +2,17 @@
|
|||
Pandora
|
||||
***/
|
||||
|
||||
var pandora = new Ox.App({
|
||||
apiURL: '/api/',
|
||||
init: 'init',
|
||||
}).launch(function(data) {
|
||||
// fixme: never set ui.videoPosition to 0 ... set to null a.k.a. delete
|
||||
// fixme: sort=-director doesn't work
|
||||
// fixme: don't reload full right panel on sortSelect
|
||||
|
||||
//Ox.print('data', data);
|
||||
(function() {
|
||||
|
||||
// fixme: never set ui.videoPosition to 0 ... set to null a.k.a. delete
|
||||
// fixme: sort=-director doesn't work
|
||||
// fixme: don't reload full right panel on sortSelect
|
||||
window.pandora = new Ox.App({url: '/api/'}).launch(function(data) {
|
||||
|
||||
var app = {
|
||||
Ox.print('Ox.App launch', data);
|
||||
|
||||
$.extend(app, {
|
||||
$ui: {
|
||||
body: $('body'),
|
||||
document: $(document),
|
||||
|
@ -22,7 +21,6 @@ var pandora = new Ox.App({
|
|||
.unload(unloadWindow)
|
||||
},
|
||||
config: data.config,
|
||||
requests: {},
|
||||
ui: {
|
||||
findKeys: $.map(data.config.itemKeys, function(key, i) {
|
||||
return key.find ? key : null;
|
||||
|
@ -59,32 +57,20 @@ var pandora = new Ox.App({
|
|||
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 ($.browser.mozilla) {
|
||||
app.config.user.ui.theme = 'classic'
|
||||
if (data.user.level == 'guest' && $.browser.mozilla) {
|
||||
app.user.ui.theme = 'classic'
|
||||
}
|
||||
|
||||
if (app.user.level == 'guest') {
|
||||
app.user = $.extend({}, app.config.user);
|
||||
}
|
||||
|
||||
function load() {
|
||||
|
||||
URL.parse();
|
||||
window.onpopstate = function() {
|
||||
URL.update();
|
||||
};
|
||||
|
||||
Ox.theme(app.user.ui.theme);
|
||||
app.$ui.appPanel = ui.appPanel();
|
||||
|
||||
$(function() {
|
||||
|
||||
app.$ui.appPanel.display();
|
||||
app.$ui.appPanel = ui.appPanel().display();
|
||||
|
||||
Ox.Request.requests() && 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;
|
||||
|
||||
window.pandora.app = app;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
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 app = {
|
||||
requests: {}
|
||||
};
|
||||
|
||||
var ui = {
|
||||
accountDialog: function(action) {
|
||||
|
@ -744,13 +722,16 @@ var pandora = new Ox.App({
|
|||
] : [], [
|
||||
app.$ui.findSelect = new Ox.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 {
|
||||
id: key.id,
|
||||
checked: key.id == findKey,
|
||||
title: 'Find: ' + key.title
|
||||
};
|
||||
}), [{}, {
|
||||
})), [{}, {
|
||||
id: 'advanced',
|
||||
title: 'Find: Advanced'
|
||||
}]),
|
||||
|
@ -994,7 +975,7 @@ var pandora = new Ox.App({
|
|||
}, function(result) {
|
||||
Ox.print('result', result)
|
||||
if (result.data.user == app.user.username || result.data.subscribed) {
|
||||
Ox.Request.emptyCache(); // fixme: remove
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
app.$ui.folderList[
|
||||
result.data.user == app.user.username ? 'personal' : 'favorite'
|
||||
].reloadList();
|
||||
|
@ -1223,14 +1204,14 @@ var pandora = new Ox.App({
|
|||
// fixme: is this the best way to delete a ui preference?
|
||||
delete app.user.ui.lists[data.ids[0]];
|
||||
UI.set({lists: app.user.ui.lists});
|
||||
Ox.Request.emptyCache(); // fixme: remove
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
$list.reloadList();
|
||||
});
|
||||
} else if (id == 'favorite') {
|
||||
pandora.api.unsubscribeFromList({
|
||||
id: data.ids[0]
|
||||
}, function(result) {
|
||||
Ox.Request.emptyCache(); // fixme: remove
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
$list.reloadList();
|
||||
});
|
||||
} else if (id == 'featured' && app.user.level == 'admin') {
|
||||
|
@ -1240,7 +1221,7 @@ var pandora = new Ox.App({
|
|||
}, function(result) {
|
||||
// fixme: duplicated
|
||||
if (result.data.user == app.user.username || result.data.subscribed) {
|
||||
Ox.Request.emptyCache(); // fixme: remove
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
app.$ui.folderList[
|
||||
result.data.user == app.user.username ? 'personal' : 'favorite'
|
||||
].reloadList();
|
||||
|
@ -1371,7 +1352,7 @@ var pandora = new Ox.App({
|
|||
id = result.data.id;
|
||||
UI.set(['lists', id].join('|'), app.config.user.ui.lists['']); // fixme: necessary?
|
||||
URL.set('?find=list:' + id)
|
||||
Ox.Request.emptyCache(); // fixme: remove
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
$list.reloadList().bindEvent({load: load});
|
||||
function load(event, data) {
|
||||
$list.gainFocus()
|
||||
|
@ -1393,7 +1374,7 @@ var pandora = new Ox.App({
|
|||
})
|
||||
.bindEvent({
|
||||
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;
|
||||
if (app.ui.sectionFolders.items[i].showBrowser) {
|
||||
app.$ui.folderList.favorite.replaceWith(
|
||||
|
@ -1417,7 +1398,7 @@ var pandora = new Ox.App({
|
|||
})
|
||||
.bindEvent({
|
||||
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;
|
||||
if (app.ui.sectionFolders.items[i].showBrowser) {
|
||||
app.$ui.folderList.featured.replaceWith(
|
||||
|
@ -1450,7 +1431,7 @@ var pandora = new Ox.App({
|
|||
}, function(result) {
|
||||
id = result.data.id;
|
||||
URL.set('?find=list:' + id)
|
||||
Ox.Request.emptyCache(); // fixme: remove
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
$list.reloadList().bindEvent({load: load});
|
||||
function load(event, data) {
|
||||
$list.gainFocus()
|
||||
|
@ -3308,6 +3289,18 @@ var pandora = new Ox.App({
|
|||
) > -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) {
|
||||
var query = Query.toObject();
|
||||
app.$ui.list.options({
|
||||
|
@ -3337,7 +3330,7 @@ var pandora = new Ox.App({
|
|||
function reloadList() {
|
||||
Ox.print('reloadList')
|
||||
var listData = getListData();
|
||||
Ox.Request.emptyCache(); // fixme: remove
|
||||
Ox.Request.clearCache(); // fixme: remove
|
||||
app.$ui.groups.forEach(function($group) {
|
||||
$group.reloadList();
|
||||
});
|
||||
|
@ -3843,6 +3836,4 @@ var pandora = new Ox.App({
|
|||
}
|
||||
}
|
||||
|
||||
load();
|
||||
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue