refactor dialog closing code in app panel

This commit is contained in:
rolux 2013-03-04 12:32:08 +00:00
parent c4feabb3cb
commit 889aace64e

View file

@ -36,13 +36,26 @@ pandora.ui.appPanel = function() {
}
});
function setPage(page) {
var dialogPages = {
site: pandora.site.sitePages.map(function(page) {
return page.id;
}).concat(['software']),
account: ['signup', 'signin'],
accountSignout: ['signout'],
preferences: ['preferences'],
help: ['help'],
api: ['api']
};
if (page === '') {
if (pandora.$ui.home && pandora.$ui.appPanel) {
// unless we're on page load, remove home screen
pandora.$ui.home.fadeOutScreen();
}
['site', 'account', 'preferences', 'help', 'api'].forEach(function(dialog) {
pandora.$ui[dialog + 'Dialog'] && pandora.$ui[dialog + 'Dialog'].close();
Ox.forEach(dialogPages, function(pages, dialog) {
// close all dialogs
if (pandora.$ui[dialog + 'Dialog']) {
pandora.$ui[dialog + 'Dialog'].close();
}
});
if (pandora.$ui.tv) {
pandora.$ui.tv.fadeOutScreen();
@ -52,19 +65,25 @@ pandora.ui.appPanel = function() {
pandora.$ui.home = pandora.ui.home()[
!pandora.$ui.appPanel ? 'showScreen' : 'fadeInScreen'
]();
} else if (
Ox.getIndexById(pandora.site.sitePages, page) > -1
|| page == 'software'
) {
} else if (page == 'tv') {
pandora.$ui.tv = pandora.ui.tv()[
!pandora.$ui.appPanel ? 'showScreen' : 'fadeInScreen'
]();
pandora.$ui.home && pandora.$ui.tv.mute();
} else {
// open dialog
Ox.forEach(dialogPages, function(pages, dialog) {
// close all other dialogs
if (pages.indexOf(page) == -1 && pandora.$ui[dialog + 'Dialog']) {
pandora.$ui[dialog + 'Dialog'].close();
}
});
if (Ox.getIndexById(pandora.site.sitePages, page) > -1 || page == 'software') {
if (pandora.$ui.siteDialog && pandora.$ui.siteDialog.is(':visible')) {
pandora.$ui.siteDialog.select(page);
} else {
pandora.$ui.siteDialog = pandora.ui.siteDialog(page).open();
}
} else if (page == 'help') {
pandora.$ui.helpDialog = pandora.ui.helpDialog().open();
} else if (page == 'api') {
pandora.$ui.apiDialog = pandora.ui.apiDialog().open();
} else if (['signup', 'signin'].indexOf(page) > -1) {
if (pandora.user.level == 'guest') {
if (pandora.$ui.accountDialog && pandora.$ui.accountDialog.is(':visible')) {
@ -83,11 +102,11 @@ pandora.ui.appPanel = function() {
} else {
pandora.ui.accountSignoutDialog().open();
}
} else if (page == 'tv') {
pandora.$ui.tv = pandora.ui.tv()[
!pandora.$ui.appPanel ? 'showScreen' : 'fadeInScreen'
]();
pandora.$ui.home && pandora.$ui.tv.mute();
} else if (page == 'help') {
pandora.$ui.helpDialog = pandora.ui.helpDialog().open();
} else if (page == 'api') {
pandora.$ui.apiDialog = pandora.ui.apiDialog().open();
}
}
}
return that;