diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 002b26952..271eac46c 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -12,6 +12,7 @@ class LibraryController extends Zend_Controller_Action $ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext->addActionContext('contents-feed', 'json') ->addActionContext('delete', 'json') + ->addActionContext('duplicate', 'json') ->addActionContext('delete-group', 'json') ->addActionContext('context-menu', 'json') ->addActionContext('get-file-metadata', 'html') @@ -215,6 +216,7 @@ class LibraryController extends Zend_Controller_Action if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { $menu["del"] = array("name"=> _("Delete"), "icon" => "delete", "url" => $baseUrl."/library/delete"); } + $menu["duplicate"] = array("name" => _("Duplicate Playlist"), "icon" => "edit", "url" => $baseUrl."/library/duplicate"); } elseif ($type == "stream") { $webstream = CcWebstreamQuery::create()->findPK($id); @@ -339,6 +341,36 @@ class LibraryController extends Zend_Controller_Action $this->view->message = $message; } } + + // duplicate playlist + public function duplicateAction(){ + $params = $this->getRequest()->getParams(); + $id = $params['id']; + + $originalPl = new Application_Model_Playlist($id); + $newPl = new Application_Model_Playlist(); + + $contents = $originalPl->getContents(); + foreach ($contents as &$c) { + if ($c['type'] == '0') { + $c[1] = 'audioclip'; + } else if ($c['type'] == '2') { + $c[1] = 'block'; + } else if ($c['type'] == '1') { + $c[1] = 'stream'; + } + $c[0] = $c['item_id']; + } + $newPl->addAudioClips($contents, null, 'begining'); + + $newPl->setCreator(Application_Model_User::getCurrentUser()->getId()); + $newPl->setDescription($originalPl->getDescription()); + + list($plFadeIn, ) = $originalPl->getFadeInfo(0); + list($plFadeOut, ) = $originalPl->getFadeInfo($originalPl->getSize()-1); + $newPl->setfades($plFadeIn, $plFadeOut); + $newPl->setName("Copy of ".$originalPl->getName()); + } public function contentsFeedAction() { diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 2b5fd65c6..35caf2ebd 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -915,6 +915,16 @@ var AIRTIME = (function(AIRTIME) { soundcloud.view.callback = callback; } } + // add callbacks for duplicate menu items. + if (oItems.duplicate !== undefined) { + var url = oItems.duplicate.url; + callback = function() { + $.post(url, {format: "json", id: data.id }, function(json){ + oTable.fnStandingRedraw(); + }); + }; + oItems.duplicate.callback = callback; + } // remove 'Add to smart block' option if the current // block is dynamic if ($('input:radio[name=sp_type]:checked').val() === "1") {