diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index e7f4c8e8f..ad7ea1fcd 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -97,7 +97,11 @@ class PlaylistController extends Zend_Controller_Action unset($this->view->obj); } } else { - $this->view->html = $this->view->render($viewPath); + if ($isJson) { + return $this->view->render($viewPath); + } else { + $this->view->html = $this->view->render($viewPath); + } } } @@ -112,13 +116,19 @@ class PlaylistController extends Zend_Controller_Action $this->createFullResponse($obj); } - private function playlistNotFound($p_type) + private function playlistNotFound($p_type, $p_isJson = false) { + $p_type = ucfirst($p_type); $this->view->error = "{$p_type} not found"; Logging::info("{$p_type} not found"); Application_Model_Library::changePlaylist(null, $p_type); - $this->createFullResponse(null); + + if ($p_type == 'Playlist') { + $this->createFullResponse(null); + } else { + die(json_encode(array("error"=>$this->view->error, "result"=>1, "html"=>$this->createFullResponse(null, true)))); + } } private function playlistNoPermission($p_type) @@ -478,26 +488,31 @@ class PlaylistController extends Zend_Controller_Action { $request = $this->getRequest(); $params = $request->getPost(); - $form = new Application_Form_SmartBlockCriteria(); - $form->startForm($params['obj_id']); - $bl = new Application_Model_Block($params['obj_id']); - if ($form->isValid($params)) { - $result = $bl->generateSmartBlock($params['data']); - try { + + //make sure block exists + try { + $bl = new Application_Model_Block($params['obj_id']); + + $form = new Application_Form_SmartBlockCriteria(); + $form->startForm($params['obj_id']); + if ($form->isValid($params)) { + $result = $bl->generateSmartBlock($params['data']); die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($bl, true, true)))); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound('block'); - } catch (Exception $e) { - $this->playlistUnknownError($e); + } else { + $this->view->obj = $bl; + $this->view->id = $bl->getId(); + $this->view->form = $form; + $viewPath = 'playlist/smart-block.phtml'; + $result['html'] = $this->view->render($viewPath); + $result['result'] = 1; + die(json_encode($result)); } - } else { - $this->view->obj = $bl; - $this->view->id = $bl->getId(); - $this->view->form = $form; - $viewPath = 'playlist/smart-block.phtml'; - $result['html'] = $this->view->render($viewPath); - $result['result'] = 1; - die(json_encode($result)); + } catch (BlockNotFoundException $e) { + $this->playlistNotFound('block', true); + } catch (PlaylistNotFoundException $e) { + $this->playlistNotFound('block'); + } catch (Exception $e) { + $this->playlistUnknownError($e); } } @@ -505,17 +520,21 @@ class PlaylistController extends Zend_Controller_Action { $request = $this->getRequest(); $params = $request->getPost(); - $bl = new Application_Model_Block($params['obj_id']); - $result = $bl->shuffleSmartBlock(); - - if ($result['result'] == 0) { - try { + try { + $bl = new Application_Model_Block($params['obj_id']); + $result = $bl->shuffleSmartBlock(); + + if ($result['result'] == 0) { die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($bl, true)))); - } catch (PlaylistNotFoundException $e) { - $this->playlistNotFound('block'); + } else { + die(json_encode($result)); } - } else { - die(json_encode($result)); + } catch (BlockNotFoundException $e) { + $this->playlistNotFound('block', true); + } catch (PlaylistNotFoundException $e) { + $this->playlistNotFound('block'); + } catch (Exception $e) { + $this->playlistUnknownError($e); } } diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index 65035d5ef..e53c33f81 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -437,6 +437,9 @@ function callback(data, type) { dt = $('table[id="library_display"]').dataTable(); if (type == 'shuffle' || type == 'generate') { + if (json.error !== undefined) { + alert(json.error); + } AIRTIME.playlist.fnOpenPlaylist(json); var form = $('#smart-block-form'); if (json.result == "0") {