search maintains state

This commit is contained in:
naomiaro 2010-12-22 15:08:38 -05:00
parent b1a4cb5bd4
commit e768539ea8
7 changed files with 51 additions and 34 deletions

View file

@ -4,6 +4,7 @@ class LibraryController extends Zend_Controller_Action
{ {
protected $pl_sess = null; protected $pl_sess = null;
protected $search_sess = null;
public function init() public function init()
{ {
@ -20,6 +21,7 @@ class LibraryController extends Zend_Controller_Action
->initContext(); ->initContext();
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME); $this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
$this->search_sess = new Zend_Session_Namespace("search");
} }
public function indexAction() public function indexAction()
@ -28,6 +30,9 @@ class LibraryController extends Zend_Controller_Action
$this->_helper->layout->setLayout('library'); $this->_helper->layout->setLayout('library');
unset($this->search_sess->md);
unset($this->search_sess->order);
$this->_helper->actionStack('context-menu', 'library'); $this->_helper->actionStack('context-menu', 'library');
$this->_helper->actionStack('contents', 'library'); $this->_helper->actionStack('contents', 'library');
$this->_helper->actionStack('index', 'sideplaylist'); $this->_helper->actionStack('index', 'sideplaylist');
@ -82,14 +87,17 @@ class LibraryController extends Zend_Controller_Action
public function contentsAction() public function contentsAction()
{ {
$this->_helper->viewRenderer->setResponseSegment('library');
$this->view->headScript()->appendFile('/js/campcaster/library/library.js','text/javascript'); $this->view->headScript()->appendFile('/js/campcaster/library/library.js','text/javascript');
$query["category"] = $this->_getParam('ob', "dc:creator"); $this->_helper->viewRenderer->setResponseSegment('library');
$query["order"] = $this->_getParam('order', "asc");
$order["category"] = $this->_getParam('ob', "dc:creator");
$this->view->files = StoredFile::getFiles($query); $order["order"] = $this->_getParam('order', "asc");
$this->search_sess->order = $order;
$md = isset($this->search_sess->md) ? $this->search_sess->md : array();
$this->view->files = StoredFile::searchFiles($md, $order);
} }
public function searchAction() public function searchAction()

View file

@ -4,6 +4,7 @@ class SearchController extends Zend_Controller_Action
{ {
protected $form; protected $form;
protected $search_sess = null;
public function init() public function init()
{ {
@ -18,6 +19,7 @@ class SearchController extends Zend_Controller_Action
->initContext(); ->initContext();
$this->form = new Application_Form_AdvancedSearch(); $this->form = new Application_Form_AdvancedSearch();
$this->search_sess = new Zend_Session_Namespace("search");
} }
public function indexAction() public function indexAction()
@ -46,6 +48,10 @@ class SearchController extends Zend_Controller_Action
// Form has not been submitted - displayed using layouts // Form has not been submitted - displayed using layouts
if (!$request->isPost()) { if (!$request->isPost()) {
unset($this->search_sess->md);
unset($this->search_sess->order);
$sub = new Application_Form_AdvancedSearchRow(1); $sub = new Application_Form_AdvancedSearchRow(1);
$form->addSubForm($sub, 'row_1'); $form->addSubForm($sub, 'row_1');
$form->getSubForm('row_1')->removeDecorator('DtDdWrapper'); $form->getSubForm('row_1')->removeDecorator('DtDdWrapper');
@ -62,11 +68,12 @@ class SearchController extends Zend_Controller_Action
return; return;
} }
// form was submitted, send back strings to json response. // form was submitted, send back strings to json response.
//$this->view->form = $form->__toString(); $info = $form->getValues();
$this->search_sess->md = $info;
$order = isset($this->search_sess->order) ? $this->search_sess->order : NULL;
$info = $form->getValues(); $this->view->files = StoredFile::searchFiles($info, $order);
$this->view->files = StoredFile::searchFiles($info);
$this->view->results = $this->view->render('library/update.phtml'); $this->view->results = $this->view->render('library/update.phtml');
unset($this->view->files); unset($this->view->files);
} }

View file

@ -1726,22 +1726,7 @@ class StoredFile {
return $CC_CONFIG['accessDir']."/$p_token.$p_ext"; return $CC_CONFIG['accessDir']."/$p_token.$p_ext";
} }
public static function searchFiles($md, $order=NULL)
public static function getFiles($query=NULL)
{
global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping;
$sql = "SELECT * FROM ".$CC_CONFIG['filesTable'];
if(!is_null($query)) {
$ob = " ORDER BY ".$g_metadata_xml_to_db_mapping[$query["category"]];
$sql = $sql . $ob . " " .$query["order"];
}
return $CC_DBC->getAll($sql);
}
public static function searchFiles($md)
{ {
global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping; global $CC_CONFIG, $CC_DBC, $g_metadata_xml_to_db_mapping;
@ -1776,8 +1761,15 @@ class StoredFile {
} }
} }
$where = " WHERE ". join(" AND ", $cond); if(count($cond) > 0) {
$sql = $sql . $where; $where = " WHERE ". join(" AND ", $cond);
$sql = $sql . $where;
}
if(!is_null($order)) {
$ob = " ORDER BY ".$g_metadata_xml_to_db_mapping[$order["category"]];
$sql = $sql . $ob . " " .$order["order"];
}
//echo $sql; //echo $sql;
return $CC_DBC->getAll($sql); return $CC_DBC->getAll($sql);

View file

@ -0,0 +1 @@
<br /><br /><center>View script for controller <b>Playlist</b> and script/action name <b>close</b></center>

View file

@ -22,6 +22,7 @@ function setLibraryContents(data){
} }
function setUpLibrary() { function setUpLibrary() {
$("#library_display tr:first-child span.title").data({'ob': 'dc:title', 'order' : 'asc'}); $("#library_display tr:first-child span.title").data({'ob': 'dc:title', 'order' : 'asc'});
$("#library_display tr:first-child span.artist").data({'ob': 'dc:creator', 'order' : 'desc'}); $("#library_display tr:first-child span.artist").data({'ob': 'dc:creator', 'order' : 'desc'});
$("#library_display tr:first-child span.album").data({'ob': 'dc:source', 'order' : 'asc'}); $("#library_display tr:first-child span.album").data({'ob': 'dc:source', 'order' : 'asc'});
@ -33,11 +34,6 @@ function setUpLibrary() {
ob = $(this).data('ob'), ob = $(this).data('ob'),
order = $(this).data('order'); order = $(this).data('order');
//append orderby category to url.
url = url + "/ob/" + ob;
//append asc or desc order.
url = url + "/order/" + order;
//toggle order for next click. //toggle order for next click.
if(order === 'asc') { if(order === 'asc') {
$(this).data('order', 'desc'); $(this).data('order', 'desc');
@ -46,7 +42,7 @@ function setUpLibrary() {
$(this).data('order', 'asc'); $(this).data('order', 'asc');
} }
$.post(url, setLibraryContents); $.post(url, {ob: ob, order: order}, setLibraryContents);
}); });
$("#library_display tr:not(:first-child)") $("#library_display tr:not(:first-child)")

View file

@ -0,0 +1,6 @@
$(document).ready(function() {
setUpLibrary();
setUpSPL();
});

View file

@ -0,0 +1,7 @@
$(document).ready(function() {
setUpLibrary();
setUpSearch();
setUpSPL();
});