diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index eeb2b9d35..067a33ac6 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -59,7 +59,7 @@ class LibraryController extends Zend_Controller_Action if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($this->obj_sess->type === "playlist") { $menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); - } else { + } else if ($this->obj_sess->type === "block") { $menu["pl_add"] = array("name"=> "Add to Smart Playlist", "icon" => "add-playlist", "icon" => "copy"); } } @@ -101,8 +101,6 @@ class LibraryController extends Zend_Controller_Action if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($this->obj_sess->type === "playlist") { $menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); - } else { - $menu["pl_add"] = array("name"=> "Add to Smart Playlist", "icon" => "add-playlist", "icon" => "copy"); } } } @@ -181,7 +179,7 @@ class LibraryController extends Zend_Controller_Action try { Application_Model_Block::deleteBlocks($blocks, $user->getId()); } catch (Exception $e) { - //TODO: warn user that not all blocks could be deleted. + //TODO: warn user that not all blocks could be deleted. } try { diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index b8468af6b..8738a4d21 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -24,7 +24,7 @@ class PlaylistController extends Zend_Controller_Action ->addActionContext('set-playlist-description', 'json') ->addActionContext('playlist-preview', 'json') ->addActionContext('get-playlist', 'json') - ->addActionContext('smart-block-criteria-save', 'json') + ->addActionContext('save', 'json') ->addActionContext('smart-block-generate', 'json') ->addActionContext('smart-block-shuffle', 'json') ->addActionContext('get-block-info', 'json') @@ -153,8 +153,8 @@ class PlaylistController extends Zend_Controller_Action Logging::log("{$e->getMessage()}"); } - private function playlistDenied($obj) { - $this->view->error = "You cannot add playlists to smart playlists."; + private function wrongTypeToBlock($obj) { + $this->view->error = "You can only add tracks to smart playlists."; $this->createFullResponse($obj); } @@ -315,13 +315,15 @@ class PlaylistController extends Zend_Controller_Action // if the dest is a block object //check if any items are playlists foreach($ids as $id) { - if (is_array($id) && isset($id[1]) && $id[1] == 'playlist') { - throw new Exception('playlist to block'); + if (is_array($id) && isset($id[1])) { + if ($id[1] != 'audioclip') { + throw new WrongTypeToBlockException; + } } } $obj->addAudioClips($ids, $afterItem, $addType); } else { - throw new Exception('track to dynamic'); + throw new BlockDynamicException; } $this->createUpdateResponse($obj); } @@ -331,14 +333,14 @@ class PlaylistController extends Zend_Controller_Action catch (PlaylistNotFoundException $e) { $this->playlistNotFound($obj_type); } + catch (WrongTypeToBlockException $e) { + $this->wrongTypeToBlock($obj); + } + catch (BlockDynamicException $e) { + $this->blockDynamic($obj); + } catch (Exception $e) { - if ($e->getMessage() == 'playlist to block') { - $this->playlistDenied($obj); - } else if ($e->getMessage() == 'track to dynamic') { - $this->blockDynamic($obj); - } else { - $this->playlistUnknownError($e); - } + $this->playlistUnknownError($e); } } @@ -478,14 +480,17 @@ class PlaylistController extends Zend_Controller_Action } } - public function setPlaylistNameAction() + public function setPlaylistNameDescAction() { $name = $this->_getParam('name', 'Unknown Playlist'); + $description = $this->_getParam('description', ""); $type = $this->_getParam('type'); try { $obj = $this->getPlaylist($type); $obj->setName($name); + $obj->setDescription($description); + $this->view->description = $obj->getDescription(); $this->view->playlistName = $name; $this->view->modified = $obj->getLastModified("U"); } catch (PlaylistOutDatedException $e) { @@ -497,6 +502,7 @@ class PlaylistController extends Zend_Controller_Action } } + /* public function setPlaylistDescriptionAction() { $description = $this->_getParam('description', ""); @@ -515,13 +521,22 @@ class PlaylistController extends Zend_Controller_Action $this->playlistUnknownError($e); } } + */ - public function smartBlockCriteriaSaveAction() + public function saveAction() { $request = $this->getRequest(); $params = $request->getPost(); - $bl = new Application_Model_Block($params['obj_id']); - $result = $bl->saveSmartBlockCriteria($params['data']); + $result = array(); + + $this->setPlaylistNameDescAction(); + + if ($params['type'] == 'block') { + $bl = new Application_Model_Block($params['obj_id']); + $result = $bl->saveSmartBlockCriteria($params['criteria']); + } + + $result["modified"] = $this->view->modified; die(json_encode($result)); } @@ -593,5 +608,6 @@ class PlaylistController extends Zend_Controller_Action } die(json_encode($out)); } - } +class WrongTypeToBlockException extends Exception {} +class BlockDynamicException extends Exception {} diff --git a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml index 509457d67..37b798813 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -18,7 +18,6 @@ - element->getElement('save_button') ?> element->getElement('generate_button') ?> element->getElement('shuffle_button') ?> @@ -96,10 +95,5 @@ - numOfSubForm; $i++){ - echo $this->parent_form->getSubform('sp_set_'.$i); - }*/ - ?> diff --git a/airtime_mvc/application/views/scripts/playlist/playlist.phtml b/airtime_mvc/application/views/scripts/playlist/playlist.phtml index 795c44a6d..35593e06e 100644 --- a/airtime_mvc/application/views/scripts/playlist/playlist.phtml +++ b/airtime_mvc/application/views/scripts/playlist/playlist.phtml @@ -12,6 +12,8 @@ if (isset($this->obj)) { + + obj)) : ?> @@ -22,6 +24,7 @@ if (isset($this->obj)) {

length; ?>

+
View / edit description @@ -30,11 +33,6 @@ if (isset($this->obj)) {
- -
- - -
diff --git a/airtime_mvc/application/views/scripts/playlist/smart-block.phtml b/airtime_mvc/application/views/scripts/playlist/smart-block.phtml index 457615882..35e581858 100644 --- a/airtime_mvc/application/views/scripts/playlist/smart-block.phtml +++ b/airtime_mvc/application/views/scripts/playlist/smart-block.phtml @@ -12,6 +12,8 @@ if (isset($this->obj)) { +form->getElement('save_button');?> + obj)) : ?> @@ -30,11 +32,6 @@ if (isset($this->obj)) {
- -
- - -
diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index 41d230e8a..e12df0030 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -502,7 +502,7 @@ table.library-get-file-md.table-small{ /***** SMART PLAYLIST SPECIFIC STYLES BEGIN *****/ .sp-scrollable{ overflow-x: auto; - width: 781px; + width: 765px; } .sp-invisible{ diff --git a/airtime_mvc/public/js/airtime/library/spl.js b/airtime_mvc/public/js/airtime/library/spl.js index c3ecab51e..0996b67bc 100644 --- a/airtime_mvc/public/js/airtime/library/spl.js +++ b/airtime_mvc/public/js/airtime/library/spl.js @@ -590,41 +590,39 @@ var AIRTIME = (function(AIRTIME){ }); - } - - - ) - $pl.on("click", "#description_save", function(){ - var textarea = $pl.find("#fieldset-metadate_change textarea"), - description = textarea.val(), - url, - lastMod = getModified(), - type = $('#obj_type').val(); - - url = '/Playlist/set-playlist-description'; - - $.post(url, - {format: "json", description: description, modified: lastMod, type: type}, - function(json){ - if (json.error !== undefined){ - playlistError(json); - } - else{ - setModified(json.modified); - textarea.val(json.description); - $pl.find("#fieldset-metadate_change").addClass("closed"); - redrawLib(); - } - }); - }); - - $pl.on("click", "#description_cancel", function(){ - var textarea = $pl.find("#fieldset-metadate_change textarea"); - - textarea.val(cachedDescription); - $pl.find("#fieldset-metadate_change").addClass("closed"); - }); - //end edit playlist description events. + }); + + $('#save_button').live("click", function(event){ + /* Smart blocks: get name, description, and criteria + * Playlists: get name, description + */ + var criteria = $('form').serializeArray(), + block_name = $('#playlist_name_display').text(), + block_desc = $('textarea[name="description"]').val(), + save_action = 'Playlist/save', + obj_id = $('input[id="obj_id"]').val(), + obj_type = $('#obj_type').val(), + lastMod = getModified(), + dt = $('table[id="library_display"]').dataTable(); + enableLoadingIcon(); + $.post(save_action, + {format: "json", criteria: criteria, name: block_name, description: block_desc, obj_id: obj_id, type: obj_type, modified: lastMod}, + function(data){ + var json = $.parseJSON(data); + setModified(json.modified); + if (obj_type == "block") { + callback(data, "save"); + } else { + $('.success').text('Playlist saved'); + $('.success').show(); + setTimeout(removeSuccessMsg, 5000); + dt.fnStandingRedraw(); + } + setFadeIcon(); + disableLoadingIcon(); + } + ); + }); } function setUpPlaylist() { diff --git a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js index ae7ea76c5..058f51060 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js @@ -186,17 +186,21 @@ function setSmartPlaylistEvents() { }); /********** SAVE ACTION **********/ - form.find('button[id="save_button"]').live("click", function(event){ - var data = $('form').serializeArray(), - save_action = 'Playlist/smart-block-criteria-save', + /* moved to spl.js + $('#save_button').live("click", function(event){ + var criteria = $('form').serializeArray(), + block_name = $('#playlist_name_display').text(), + block_desc = $('textarea[name="description"]').val(), + save_action = 'Playlist/save', obj_id = $('input[id="obj_id"]').val(); enableLoadingIcon(); - $.post(save_action, {format: "json", data: data, obj_id: obj_id}, function(data){ + $.post(save_action, {format: "json", criteria: criteria, name: block_name, desc: block_desc, obj_id: obj_id}, function(data){ callback(data, "save"); setFadeIcon(); disableLoadingIcon(); }); }); + */ /********** GENERATE ACTION **********/ form.find('button[id="generate_button"]').live("click", function(event){ @@ -480,10 +484,8 @@ function callback(data, type) { form.find('.success').show(); form.find('#smart_playlist_options').removeClass("closed"); } else { - form.find('.success').text('Criteria saved'); + form.find('.success').text('Smart Playlist saved'); form.find('.success').show(); - //redraw library table incase block changed from static to dynamic or vice versa - dt.fnStandingRedraw(); /* Update number of files that meet criteria and change icon to success/warning * as appropriate. This is also done in the form but we do not pass the form @@ -515,7 +517,7 @@ function callback(data, type) { } function removeSuccessMsg() { - var $status = $('#smart-playlist-form').find('.success'); + var $status = $('.success'); $status.fadeOut("slow", function(){$status.empty()}); }