Create oauth controller interface for oauth-specific actions; small refactoring on tabs.js

This commit is contained in:
Duncan Sommerville 2015-09-16 15:29:10 -04:00
parent 7006b55818
commit 9ed3145473
5 changed files with 80 additions and 50 deletions

View File

@ -29,6 +29,7 @@ require_once "GoogleAnalytics.php";
require_once "Timezone.php"; require_once "Timezone.php";
require_once "Auth.php"; require_once "Auth.php";
require_once "interface/OAuth2.php"; require_once "interface/OAuth2.php";
require_once "interface/OAuth2Controller.php";
require_once "TaskManager.php"; require_once "TaskManager.php";
require_once "UsabilityHints.php"; require_once "UsabilityHints.php";
require_once "MediaType.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/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/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/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/libs/jquery.stickyPanel.js?' . $CC_CONFIG['airtime_version'], 'text/javascript')
->appendFile($baseUrl . 'js/qtip/jquery.qtip.js?' . $CC_CONFIG['airtime_version'], 'text/javascript') ->appendFile($baseUrl . 'js/qtip/jquery.qtip.js?' . $CC_CONFIG['airtime_version'], 'text/javascript')

View File

@ -0,0 +1,27 @@
<?php
interface OAuth2Controller {
/**
* Send user to a third-party service to authorize before being redirected
*
* @return void
*/
public function authorizeAction();
/**
* Clear the previously saved request token from the preferences
*
* @return void
*/
public function deauthorizeAction();
/**
* Called when user successfully completes third-party authorization
* Store the returned request token for future requests
*
* @return void
*/
public function redirectAction();
}

View File

@ -3,7 +3,7 @@
require_once "ThirdPartyController.php"; require_once "ThirdPartyController.php";
require_once "ise/php-soundcloud/src/Soundcloud/Service.php"; require_once "ise/php-soundcloud/src/Soundcloud/Service.php";
class SoundcloudController extends ThirdPartyController { class SoundcloudController extends ThirdPartyController implements OAuth2Controller {
/** /**
* @var SoundcloudService * @var SoundcloudService
@ -23,6 +23,39 @@ class SoundcloudController extends ThirdPartyController {
$this->_service = new SoundcloudService(); $this->_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. * Fetch the permalink to a file on SoundCloud and redirect to it.
*/ */

View File

@ -31,39 +31,6 @@ abstract class ThirdPartyController extends Zend_Controller_Action {
$this->_helper->viewRenderer->setNoRender(true); // Don't use (phtml) templates $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 * Upload the file with the given id to a third-party service
* *

View File

@ -14,7 +14,7 @@ var AIRTIME = (function(AIRTIME){
Internal Functions Internal Functions
##################################################### */ ##################################################### */
function buildNewTab(json) { function _buildNewTab(json) {
AIRTIME.library.selectNone(); AIRTIME.library.selectNone();
var tabId = $openTabs[json.type + json.id]; 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), t = $("#show_builder").append(wrapper).find("#pl-tab-content-" + $tabCount),
pane = $(".editor_pane_wrapper:last"), pane = $(".editor_pane_wrapper:last"),
name = json.type == "md" ? // file name = json.type == "md" ? // file
pane.append(json.html).find("#track_title").val() + $.i18n._(" - Metadata Editor") 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(".playlist_name_display").val(),
tab = tab =
"<li data-tab-id='" + $tabCount + "' data-tab-type='" + json.type + "' id='pl-tab-" + $tabCount + "' role='presentation' class='active'>" + "<li data-tab-id='" + $tabCount + "' data-tab-type='" + json.type + "' id='pl-tab-" + $tabCount + "' role='presentation' class='active'>" +
"<a href='javascript:void(0)'><span class='tab-name'></span>" + "<a href='javascript:void(0)'>" +
"<span href='#' class='lib_pl_close icon-remove'></span>" + "<span class='tab-name'></span>" +
"</a>" + "<span href='#' class='lib_pl_close icon-remove'></span>" +
"</a>" +
"</li>", "</li>",
tabs = $(".nav.nav-tabs"); tabs = $(".nav.nav-tabs");
@ -52,7 +53,7 @@ var AIRTIME = (function(AIRTIME){
return {wrapper: pane, tab: newTab, pane: t}; return {wrapper: pane, tab: newTab, pane: t};
} }
function initFileMdEvents(newTab) { function _initFileMdEvents(newTab) {
newTab.tab.on("click", function() { newTab.tab.on("click", function() {
if (!$(this).hasClass('active')) { if (!$(this).hasClass('active')) {
mod.switchTab(newTab.pane, newTab.tab); mod.switchTab(newTab.pane, newTab.tab);
@ -89,17 +90,17 @@ var AIRTIME = (function(AIRTIME){
##################################################### */ ##################################################### */
mod.openFileMdEditorTab = function(json) { mod.openFileMdEditorTab = function(json) {
var newTab = buildNewTab(json); var newTab = _buildNewTab(json);
if (newTab === undefined) { if (newTab === undefined) {
return; return;
} }
initFileMdEvents(newTab); _initFileMdEvents(newTab);
AIRTIME.playlist.setupEventListeners(); AIRTIME.playlist.setupEventListeners();
}; };
mod.openPlaylistTab = function(json) { mod.openPlaylistTab = function(json) {
var newTab = buildNewTab(json); var newTab = _buildNewTab(json);
if (newTab === undefined) { if (newTab === undefined) {
return; return;
} }
@ -129,18 +130,18 @@ var AIRTIME = (function(AIRTIME){
toTab = tab.next().length > 0 ? tab.next() : tab.prev(), toTab = tab.next().length > 0 ? tab.next() : tab.prev(),
objId = pane.find(".obj_id").val(), objId = pane.find(".obj_id").val(),
contents = id ? pane : $activeTabPane; 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(); tab.remove();
contents.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); 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 // If we close a tab that was causing tabs to wrap to the next row
// margin for the tab nav // we need to resize to change the margin for the tab nav
AIRTIME.playlist.onResize(); AIRTIME.playlist.onResize();
}; };
@ -188,9 +189,9 @@ var AIRTIME = (function(AIRTIME){
allTabs.each(function() { allTabs.each(function() {
if ($(this).data("tab-id") == id) { if ($(this).data("tab-id") == id) {
t = $(this); t = $(this);
return false; // Break out of the loop
} }
}); });
// An id was passed in, but no tab with that id exists
return t; return t;
} }
return allTabs; return allTabs;