From ed3371434090fce8fc1c1aa11086cdfbabeb91bb Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Tue, 22 Sep 2015 18:33:27 -0400 Subject: [PATCH] SAAS-1064: Publish action for library context menu --- .../controllers/LibraryController.php | 13 ++- .../controllers/ShowbuilderController.php | 1 + .../public/js/airtime/library/library.js | 8 +- .../public/js/airtime/library/podcast.js | 45 ++++---- .../public/js/airtime/library/publish.js | 101 ++++++++++++++++++ 5 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 airtime_mvc/public/js/airtime/library/publish.js diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index ba5a56d2c..fff58a7c8 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -18,6 +18,7 @@ class LibraryController extends Zend_Controller_Action ->addActionContext('get-file-metadata', 'html') ->addActionContext('set-num-entries', 'json') ->addActionContext('edit-file-md', 'json') + ->addActionContext('publish-dialog', 'html') ->initContext(); } @@ -120,7 +121,7 @@ class LibraryController extends Zend_Controller_Action } if ($isAdminOrPM || $file->getFileOwnerId() == $user->getId()) { $menu["del"] = array("name"=> _("Delete"), "icon" => "delete", "url" => $baseUrl."library/delete"); - $menu["edit"] = array("name"=> _("Edit Metadata"), "icon" => "edit", "url" => $baseUrl."library/edit-file-md/id/{$id}"); + $menu["edit"] = array("name"=> _("Edit..."), "icon" => "edit", "url" => $baseUrl."library/edit-file-md/id/{$id}"); $menu["publish"] = array("name"=> _("Publish..."), "icon" => "soundcloud", "url" => $baseUrl."library/publish/id/{$id}"); } @@ -182,7 +183,7 @@ class LibraryController extends Zend_Controller_Action if ($obj_sess->id !== $id && $screen == "playlist") { if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { - $menu["edit"] = array("name"=> _("Edit"), "icon" => "edit"); + $menu["edit"] = array("name"=> _("Edit..."), "icon" => "edit"); } } @@ -204,7 +205,7 @@ class LibraryController extends Zend_Controller_Action } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($screen == "playlist") { - $menu["edit"] = array("name"=> _("Edit"), "icon" => "edit", "url" => $baseUrl."library/edit-file-md/id/{$id}"); + $menu["edit"] = array("name"=> _("Edit..."), "icon" => "edit", "url" => $baseUrl."library/edit-file-md/id/{$id}"); } $menu["del"] = array("name"=> _("Delete"), "icon" => "delete", "url" => $baseUrl."library/delete"); } @@ -451,4 +452,10 @@ class LibraryController extends Zend_Controller_Action Logging::info($e->getMessage()); } } + + public function publishDialogAction() { + $this->_helper->layout->disableLayout(); + + //This just spits out publish-dialog.phtml! + } } diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index 6a1f8efc3..579fdf1da 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -66,6 +66,7 @@ class ShowbuilderController extends Zend_Controller_Action // MEDIA BUILDER $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/spl.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/podcast.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/publish.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/playlist/smart_blockbuilder.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); $this->view->headLink()->appendStylesheet($baseUrl.'css/playlist_builder.css?'.$CC_CONFIG['airtime_version']); diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 65494fa69..59f1ec47b 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -1174,13 +1174,7 @@ var AIRTIME = (function(AIRTIME) { if (oItems.publish !== undefined) { if (data.ftype === "audioclip") { callback = function() { - alert("TODO: Publish track with ID " + data.id); - - /* - $.get(oItems.publish.url, {format: "json"}, function(json){ - //AIRTIME.playlist.fileMdEdit(json); - alert("derp"); - });*/ + AIRTIME.publish.publishTrack(data.id); }; } oItems.publish.callback = callback; diff --git a/airtime_mvc/public/js/airtime/library/podcast.js b/airtime_mvc/public/js/airtime/library/podcast.js index 2f9efc396..250680f37 100644 --- a/airtime_mvc/public/js/airtime/library/podcast.js +++ b/airtime_mvc/public/js/airtime/library/podcast.js @@ -1,32 +1,39 @@ -var endpoint = 'rest/podcast/'; - -var podcastApp = angular.module('podcast', []) - .controller('RestController', function($scope, $http, podcast) { - $scope.podcast = podcast; - AIRTIME.tabs.setActiveTabName($scope.podcast.title); - - $scope.savePodcast = function() { - $http.put(endpoint + $scope.podcast.id, { csrf_token: jQuery("#csrf").val(), podcast: $scope.podcast }) - .success(function() { - // TODO - }); - }; - - $scope.discard = function() { - AIRTIME.tabs.getActiveTab().close(); - $scope.podcast = {}; - }; - }); var AIRTIME = (function (AIRTIME) { var mod; + if (AIRTIME.podcast === undefined) { AIRTIME.podcast = {}; } mod = AIRTIME.podcast; + var endpoint = 'rest/podcast/'; + + //AngularJS app + var podcastApp = angular.module('podcast', []) + .controller('RestController', function($scope, $http, podcast) { + + //We take a podcast object in as a parameter rather fetching the podcast by ID here because + //when you're creating a new podcast, we already have the object from the result of the POST. We're saving + //a roundtrip by not fetching it again here. + $scope.podcast = podcast; + AIRTIME.tabs.setActiveTabName($scope.podcast.title); + + $scope.savePodcast = function() { + $http.put(endpoint + $scope.podcast.id, { csrf_token: jQuery("#csrf").val(), podcast: $scope.podcast }) + .success(function() { + // TODO + }); + }; + + $scope.discard = function() { + AIRTIME.tabs.getActiveTab().close(); + $scope.podcast = {}; + }; + }); + function _bulkAction(method, callback) { var selected = $("#podcast_table").find(".selected"), ids = []; diff --git a/airtime_mvc/public/js/airtime/library/publish.js b/airtime_mvc/public/js/airtime/library/publish.js new file mode 100644 index 000000000..300356eb6 --- /dev/null +++ b/airtime_mvc/public/js/airtime/library/publish.js @@ -0,0 +1,101 @@ + +var AIRTIME = (function (AIRTIME) { + var mod; + + if (AIRTIME.publish === undefined) { + AIRTIME.publish = {}; + } + + mod = AIRTIME.publish; + + var endpoint = 'rest/media/'; + var dialogUrl = 'library/publish-dialog'; + var PUBLISH_APP_NAME = 'publish'; + + + //AngularJS app + var publishApp = angular.module(PUBLISH_APP_NAME, []) + .controller('RestController', function($scope, $http, mediaId) { + + $http.get(endpoint + mediaId, { csrf_token: jQuery("#csrf").val() }) + .success(function(json) { + console.log(json); + $scope.media = json; + AIRTIME.tabs.setActiveTabName($scope.media.track_title); + }); + + $scope.save = function() { + $http.put(endpoint + $scope.media.id, { csrf_token: jQuery("#csrf").val(), media: $scope.media }) + .success(function() { + // TODO + }); + }; + + $scope.discard = function() { + AIRTIME.tabs.getActiveTab().close(); + $scope.media = {}; + }; + }); + + + /* + var selected = $("#podcast_table").find(".selected"), + ids = []; + var selectedData = AIRTIME.library.podcastTableWidget.getSelectedRows(); + selectedData.forEach(function(el) { + ids.push(el.id); + });*/ + + function _bootstrapAngularApp(mediaId) { + publishApp.value('mediaId', mediaId); + var wrapper = AIRTIME.tabs.getActiveTab().contents.find(".editor_pane_wrapper"); + wrapper.attr("ng-controller", "RestController"); + angular.bootstrap(wrapper.get(0), [PUBLISH_APP_NAME]); + } + + mod.publishSelectedTracks = function() { + /* + _bulkAction("GET", function(json) { + json.forEach(function(el) { + var uid = AIRTIME.library.MediaTypeStringEnum.FILE+"_"+el.id; + var mediaId = el.id; + + $http.get(dialogUrl, { csrf_token: jQuery("#csrf").val() }) + .success(function(json) { + + AIRTIME.tabs.openTab(json, uid, null); + _bootstrapAngularApp(mediaId); + }); + }); + });*/ + + }; + + mod.publishTrack = function(mediaId) { + + jQuery.get(dialogUrl, { csrf_token: jQuery("#csrf").val() }) + .success(function(html) { + + var jsonWrapper = {'html' : html}; //Silly wrapper to make the openTab function happy + AIRTIME.tabs.openTab(jsonWrapper, mediaId); + _bootstrapAngularApp(mediaId); + }); + + /* + _bulkAction("GET", function(json) { + json.forEach(function(el) { + var uid = AIRTIME.library.MediaTypeStringEnum.FILE+"_"+el.id; + + $http.get(dialogUrl, { csrf_token: jQuery("#csrf").val() }) + .success(function(json) { + + AIRTIME.tabs.openTab(json, uid, null); + _bootstrapAngularApp(el.media); + }); + }); + });*/ + }; + + + return AIRTIME; +}(AIRTIME || {}));