From 9ed31454730e598368f5c48175d71147404bb29a Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 16 Sep 2015 15:29:10 -0400 Subject: [PATCH] Create oauth controller interface for oauth-specific actions; small refactoring on tabs.js --- airtime_mvc/application/Bootstrap.php | 2 ++ .../common/interface/OAuth2Controller.phtml | 27 ++++++++++++++ .../controllers/SoundcloudController.php | 35 ++++++++++++++++++- .../controllers/ThirdPartyController.php | 33 ----------------- .../public/js/airtime/showbuilder/tabs.js | 33 ++++++++--------- 5 files changed, 80 insertions(+), 50 deletions(-) create mode 100644 airtime_mvc/application/common/interface/OAuth2Controller.phtml diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 863ae1ecc..510e591f5 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -29,6 +29,7 @@ require_once "GoogleAnalytics.php"; require_once "Timezone.php"; require_once "Auth.php"; require_once "interface/OAuth2.php"; +require_once "interface/OAuth2Controller.php"; require_once "TaskManager.php"; require_once "UsabilityHints.php"; require_once "MediaType.php"; @@ -180,6 +181,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap ->appendFile($baseUrl . 'js/libs/jquery-ui-1.8.24.min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript') ->appendFile($baseUrl . 'js/bootstrap/bootstrap.js?' . $CC_CONFIG['airtime_version'], 'text/javascript') ->appendFile($baseUrl . 'js/libs/underscore-min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript') + ->appendFile($baseUrl . 'js/libs/angular.js?' . $CC_CONFIG['airtime_version'], 'text/javascript') // ->appendFile($baseUrl . 'js/libs/jquery.stickyPanel.js?' . $CC_CONFIG['airtime_version'], 'text/javascript') ->appendFile($baseUrl . 'js/qtip/jquery.qtip.js?' . $CC_CONFIG['airtime_version'], 'text/javascript') diff --git a/airtime_mvc/application/common/interface/OAuth2Controller.phtml b/airtime_mvc/application/common/interface/OAuth2Controller.phtml new file mode 100644 index 000000000..58759d01a --- /dev/null +++ b/airtime_mvc/application/common/interface/OAuth2Controller.phtml @@ -0,0 +1,27 @@ +_service = new SoundcloudService(); } + /** + * Send user to SoundCloud to authorize before being redirected + * + * @return void + */ + public function authorizeAction() { + $auth_url = $this->_service->getAuthorizeUrl(); + header('Location: ' . $auth_url); + } + + /** + * Clear the previously saved request token from preferences + * + * @return void + */ + public function deauthorizeAction() { + $function = $this->_SERVICE_TOKEN_ACCESSOR; + Application_Model_Preference::$function(""); + header('Location: ' . $this->_baseUrl . 'preference'); // Redirect back to the preference page + } + + /** + * Called when user successfully completes SoundCloud authorization + * Store the returned request token for future requests + * + * @return void + */ + public function redirectAction() { + $code = $_GET['code']; + $this->_service->requestNewAccessToken($code); + header('Location: ' . $this->_baseUrl . 'preference'); // Redirect back to the preference page + } + /** * Fetch the permalink to a file on SoundCloud and redirect to it. */ diff --git a/airtime_mvc/application/controllers/ThirdPartyController.php b/airtime_mvc/application/controllers/ThirdPartyController.php index 8e1ef869d..7189b8c35 100644 --- a/airtime_mvc/application/controllers/ThirdPartyController.php +++ b/airtime_mvc/application/controllers/ThirdPartyController.php @@ -31,39 +31,6 @@ abstract class ThirdPartyController extends Zend_Controller_Action { $this->_helper->viewRenderer->setNoRender(true); // Don't use (phtml) templates } - /** - * Send user to a third-party service to authorize before being redirected - * - * @return void - */ - public function authorizeAction() { - $auth_url = $this->_service->getAuthorizeUrl(); - header('Location: ' . $auth_url); - } - - /** - * Clear the previously saved request token from the preferences - * - * @return void - */ - public function deauthorizeAction() { - $function = $this->_SERVICE_TOKEN_ACCESSOR; - Application_Model_Preference::$function(""); - header('Location: ' . $this->_baseUrl . 'preference'); // Redirect back to the preference page - } - - /** - * Called when user successfully completes third-party authorization - * Store the returned request token for future requests - * - * @return void - */ - public function redirectAction() { - $code = $_GET['code']; - $this->_service->requestNewAccessToken($code); - header('Location: ' . $this->_baseUrl . 'preference'); // Redirect back to the preference page - } - /** * Upload the file with the given id to a third-party service * diff --git a/airtime_mvc/public/js/airtime/showbuilder/tabs.js b/airtime_mvc/public/js/airtime/showbuilder/tabs.js index 5b1d84691..6734f352d 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/tabs.js +++ b/airtime_mvc/public/js/airtime/showbuilder/tabs.js @@ -14,7 +14,7 @@ var AIRTIME = (function(AIRTIME){ Internal Functions ##################################################### */ - function buildNewTab(json) { + function _buildNewTab(json) { AIRTIME.library.selectNone(); var tabId = $openTabs[json.type + json.id]; @@ -28,13 +28,14 @@ var AIRTIME = (function(AIRTIME){ t = $("#show_builder").append(wrapper).find("#pl-tab-content-" + $tabCount), pane = $(".editor_pane_wrapper:last"), name = json.type == "md" ? // file - pane.append(json.html).find("#track_title").val() + $.i18n._(" - Metadata Editor") - : pane.append(json.html).find(".playlist_name_display").val(), + pane.append(json.html).find("#track_title").val() + $.i18n._(" - Metadata Editor") + : pane.append(json.html).find(".playlist_name_display").val(), tab = "", tabs = $(".nav.nav-tabs"); @@ -52,7 +53,7 @@ var AIRTIME = (function(AIRTIME){ return {wrapper: pane, tab: newTab, pane: t}; } - function initFileMdEvents(newTab) { + function _initFileMdEvents(newTab) { newTab.tab.on("click", function() { if (!$(this).hasClass('active')) { mod.switchTab(newTab.pane, newTab.tab); @@ -89,17 +90,17 @@ var AIRTIME = (function(AIRTIME){ ##################################################### */ mod.openFileMdEditorTab = function(json) { - var newTab = buildNewTab(json); + var newTab = _buildNewTab(json); if (newTab === undefined) { return; } - initFileMdEvents(newTab); + _initFileMdEvents(newTab); AIRTIME.playlist.setupEventListeners(); }; mod.openPlaylistTab = function(json) { - var newTab = buildNewTab(json); + var newTab = _buildNewTab(json); if (newTab === undefined) { return; } @@ -129,18 +130,18 @@ var AIRTIME = (function(AIRTIME){ toTab = tab.next().length > 0 ? tab.next() : tab.prev(), objId = pane.find(".obj_id").val(), contents = id ? pane : $activeTabPane; - delete $openTabs[tab.data("tab-type") + objId]; // Remove the closed tab from our open tabs array + delete $openTabs[tab.data("tab-type") + objId]; // Remove the closed tab from our open tabs array - // Remove the relevant DOM elements (the tab and the tab content) + // Remove the relevant DOM elements (the tab and its contents) tab.remove(); contents.remove(); - if (pane.get(0) == $activeTabPane.get(0)) { // Closing the current tab, otherwise we don't need to switch tabs + if (pane.get(0) == $activeTabPane.get(0)) { // Closing the current tab, otherwise we don't need to switch tabs mod.switchTab(toPane, toTab); } - // If we close a tab that was causing tabs to wrap to the next row, we need to resize to change the - // margin for the tab nav + // If we close a tab that was causing tabs to wrap to the next row + // we need to resize to change the margin for the tab nav AIRTIME.playlist.onResize(); }; @@ -188,9 +189,9 @@ var AIRTIME = (function(AIRTIME){ allTabs.each(function() { if ($(this).data("tab-id") == id) { t = $(this); + return false; // Break out of the loop } }); - // An id was passed in, but no tab with that id exists return t; } return allTabs;