From 889aace64e3457eb93391dff20760fef0e8a786b Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 4 Mar 2013 12:32:08 +0000 Subject: [PATCH] refactor dialog closing code in app panel --- static/js/pandora/appPanel.js | 85 +++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/static/js/pandora/appPanel.js b/static/js/pandora/appPanel.js index 51c8ea39..bf700a63 100644 --- a/static/js/pandora/appPanel.js +++ b/static/js/pandora/appPanel.js @@ -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,42 +65,48 @@ 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' - ) { - 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')) { - pandora.$ui.accountDialog.options(pandora.ui.accountDialogOptions(page)); - } else { - pandora.$ui.accountDialog = pandora.ui.accountDialog(page).open(); - } - } else { - pandora.UI.set({page: ''}); - } - } else if (['preferences', 'signout'].indexOf(page) > -1) { - if (pandora.user.level == 'guest') { - pandora.UI.set({page: ''}); - } else if (page == 'preferences') { - pandora.$ui.preferencesDialog = pandora.ui.preferencesDialog().open(); - } 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 { + // 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 (['signup', 'signin'].indexOf(page) > -1) { + if (pandora.user.level == 'guest') { + if (pandora.$ui.accountDialog && pandora.$ui.accountDialog.is(':visible')) { + pandora.$ui.accountDialog.options(pandora.ui.accountDialogOptions(page)); + } else { + pandora.$ui.accountDialog = pandora.ui.accountDialog(page).open(); + } + } else { + pandora.UI.set({page: ''}); + } + } else if (['preferences', 'signout'].indexOf(page) > -1) { + if (pandora.user.level == 'guest') { + pandora.UI.set({page: ''}); + } else if (page == 'preferences') { + pandora.$ui.preferencesDialog = pandora.ui.preferencesDialog().open(); + } else { + pandora.ui.accountSignoutDialog().open(); + } + } else if (page == 'help') { + pandora.$ui.helpDialog = pandora.ui.helpDialog().open(); + } else if (page == 'api') { + pandora.$ui.apiDialog = pandora.ui.apiDialog().open(); + } } } return that;