From fab68dfad10e128ade95b1216f8b9128f12a14b7 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 18 Apr 2011 12:43:04 -0400 Subject: [PATCH] CC-2203: Search results: "Delete" should be at the bottom of the list and should have a confirmation -Fixed --- .../controllers/LibraryController.php | 161 +++++++++--------- .../controllers/ScheduleController.php | 2 - .../public/js/airtime/library/library.js | 23 ++- 3 files changed, 106 insertions(+), 80 deletions(-) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index bd10c63b3..23400c344 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -10,13 +10,13 @@ class LibraryController extends Zend_Controller_Action { $ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext->addActionContext('contents', 'json') - ->addActionContext('delete', 'json') - ->addActionContext('context-menu', 'json') + ->addActionContext('delete', 'json') + ->addActionContext('context-menu', 'json') ->addActionContext('get-file-meta-data', 'html') ->initContext(); - $this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME); - $this->search_sess = new Zend_Session_Namespace("search"); + $this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME); + $this->search_sess = new Zend_Session_Namespace("search"); } public function indexAction() @@ -30,108 +30,115 @@ class LibraryController extends Zend_Controller_Action $this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/library.js','text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/advancedsearch.js','text/javascript'); - $this->view->headLink()->appendStylesheet($baseUrl.'/css/media_library.css'); - $this->view->headLink()->appendStylesheet($baseUrl.'/css/contextmenu.css'); - - $this->_helper->layout->setLayout('library'); + $this->view->headLink()->appendStylesheet($baseUrl.'/css/media_library.css'); + $this->view->headLink()->appendStylesheet($baseUrl.'/css/contextmenu.css'); + + $this->_helper->layout->setLayout('library'); $this->_helper->viewRenderer->setResponseSegment('library'); $form = new Application_Form_AdvancedSearch(); $form->addGroup(1, 1); - $this->search_sess->next_group = 2; - $this->search_sess->next_row[1] = 2; - $this->view->form = $form; + $this->search_sess->next_group = 2; + $this->search_sess->next_row[1] = 2; + $this->view->form = $form; $this->view->md = $this->search_sess->md; - - $this->_helper->actionStack('index', 'playlist'); + + $this->_helper->actionStack('index', 'playlist'); } public function contextMenuAction() { $id = $this->_getParam('id'); - $type = $this->_getParam('type'); + $type = $this->_getParam('type'); - $params = '/format/json/id/#id#/type/#type#'; + $params = '/format/json/id/#id#/type/#type#'; + + $paramsPop = str_replace('#id#', $id, $params); + $paramsPop = str_replace('#type#', $type, $paramsPop); $pl_sess = $this->pl_sess; - if($type === "au") { + if($type === "au") { + + if(isset($pl_sess->id)) { + $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/add-item'.$params, 'callback' => 'window["setSPLContent"]'), + 'title' => 'Add to Playlist'); + } - $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Library/delete'.$params, 'callback' => 'window["deleteAudioClip"]'), - 'title' => 'Delete'); - - if(isset($pl_sess->id)) { - $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/add-item'.$params, 'callback' => 'window["setSPLContent"]'), - 'title' => 'Add to Playlist'); - } + $menu[] = array('action' => array('type' => 'gourl', 'url' => '/Library/edit-file-md/id/#id#'), + 'title' => 'Edit Metadata'); - $menu[] = array('action' => array('type' => 'gourl', 'url' => '/Library/edit-file-md/id/#id#'), - 'title' => 'Edit Metadata'); + $menu[] = array('action' => array('type' => 'fn', + 'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"), + 'title' => 'Delete'); + } + else if($type === "pl") { - } - else if($type === "pl") { - - if(!isset($pl_sess->id) || $pl_sess->id !== $id) { - $menu[] = array('action' => - array('type' => 'ajax', - 'url' => '/Playlist/edit'.$params, - 'callback' => 'window["openDiffSPL"]'), - 'title' => 'Edit'); - } - else if(isset($pl_sess->id) && $pl_sess->id === $id) { - $menu[] = array('action' => - array('type' => 'ajax', - 'url' => '/Playlist/close'.$params, - 'callback' => 'window["noOpenPL"]'), - 'title' => 'Close'); - } + if(!isset($pl_sess->id) || $pl_sess->id !== $id) { + $menu[] = array('action' => + array('type' => 'ajax', + 'url' => '/Playlist/edit'.$params, + 'callback' => 'window["openDiffSPL"]'), + 'title' => 'Edit'); + } + else if(isset($pl_sess->id) && $pl_sess->id === $id) { + $menu[] = array('action' => + array('type' => 'ajax', + 'url' => '/Playlist/close'.$params, + 'callback' => 'window["noOpenPL"]'), + 'title' => 'Close'); + } $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/metadata/format/json/id/#id#', 'callback' => 'window["createPlaylistMetaForm"]'), - 'title' => 'Edit Metadata'); + 'title' => 'Edit Metadata'); - $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/delete'.$params, 'callback' => 'window["deletePlaylist"]'), - 'title' => 'Delete'); + //$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/delete'.$params, 'callback' => 'window["deletePlaylist"]'), + // 'title' => 'Delete'); - } + $menu[] = array('action' => array('type' => 'fn', + 'callback' => "window['confirmDeletePlaylist']('$paramsPop')"), + 'title' => 'Delete'); - //returns format jjmenu is looking for. - die(json_encode($menu)); + } + + //returns format jjmenu is looking for. + die(json_encode($menu)); } public function deleteAction() { $id = $this->_getParam('id'); - - if (!is_null($id)) { - $file = StoredFile::Recall($id); - - if (PEAR::isError($file)) { - $this->view->message = $file->getMessage(); - return; - } - else if(is_null($file)) { - $this->view->message = "file doesn't exist"; - return; - } + + if (!is_null($id)) { + $file = StoredFile::Recall($id); + + if (PEAR::isError($file)) { + $this->view->message = $file->getMessage(); + return; + } + else if(is_null($file)) { + $this->view->message = "file doesn't exist"; + return; + } - $res = $file->delete(); - - if (PEAR::isError($res)) { - $this->view->message = $res->getMessage(); - return; - } - } - - $this->view->id = $id; + $res = $file->delete(); + + if (PEAR::isError($res)) { + $this->view->message = $res->getMessage(); + return; + } + } + + $this->view->id = $id; } public function contentsAction() { - $post = $this->getRequest()->getPost(); - $datatables = StoredFile::searchFilesForPlaylistBuilder($post); + $post = $this->getRequest()->getPost(); + $datatables = StoredFile::searchFilesForPlaylistBuilder($post); - die(json_encode($datatables)); + die(json_encode($datatables)); } public function editFileMdAction() @@ -140,19 +147,19 @@ class LibraryController extends Zend_Controller_Action $form = new Application_Form_EditAudioMD(); $file_id = $this->_getParam('id', null); - $file = StoredFile::Recall($file_id); + $file = StoredFile::Recall($file_id); if ($request->isPost()) { if ($form->isValid($request->getPost())) { - $formdata = $form->getValues(); - $file->replaceDbMetadata($formdata); + $formdata = $form->getValues(); + $file->replaceDbMetadata($formdata); - $this->_helper->redirector('index'); + $this->_helper->redirector('index'); } } - $form->populate($file->md); + $form->populate($file->md); $this->view->form = $form; } diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 774a73aac..59b3f9e30 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -248,8 +248,6 @@ class ScheduleController extends Zend_Controller_Action $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/edit-show/format/json/id/'.$id, 'callback' => 'window["beginEditShow"]'), 'title' => 'Edit Show'); - //$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/cancel-show'.$params, - // 'callback' => 'window["scheduleRefetchEvents"]'), 'title' => 'Edit This Instance and All Following'); $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/delete-show'.$params, 'callback' => 'window["scheduleRefetchEvents"]'), 'title' => 'Delete This Instance'); $menu[] = array('action' => array('type' => 'ajax', 'url' => '/Schedule/cancel-show'.$params, diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 6bdc73014..b7eae6079 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -24,7 +24,6 @@ function deleteItem(type, id) { dt.fnDeleteRow( tr ); } -//callbacks called by jjmenu function deleteAudioClip(json) { if(json.message) { alert(json.message); @@ -34,6 +33,28 @@ function deleteAudioClip(json) { deleteItem("au", json.id); } +//callbacks called by jjmenu +function confirmDeleteAudioClip(params){ + if(confirm('Are you sure you want to delete?')){ + var url = '/Library/delete' + params; + $.ajax({ + url: url, + success: deleteAudioClip + }); + } +} + +//callbacks called by jjmenu +function confirmDeletePlaylist(params){ + if(confirm('Are you sure you want to delete?')){ + var url = '/Playlist/delete' + params; + $.ajax({ + url: url, + success: deletePlaylist + }); + } +} + function deletePlaylist(json) { if(json.message) { alert(json.message);