diff --git a/application/controllers/LibraryController.php b/application/controllers/LibraryController.php index 281b33385..595435d76 100644 --- a/application/controllers/LibraryController.php +++ b/application/controllers/LibraryController.php @@ -4,14 +4,10 @@ class LibraryController extends Zend_Controller_Action { protected $pl_sess = null; + protected $search_sess = null; public function init() { - if(!Zend_Auth::getInstance()->hasIdentity()) - { - $this->_redirect('login/index'); - } - $ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext->addActionContext('contents', 'json') ->addActionContext('delete', 'json') @@ -30,12 +26,21 @@ class LibraryController extends Zend_Controller_Action $this->view->headScript()->appendFile('/js/datatables/js/jquery.dataTables.js','text/javascript'); $this->view->headScript()->appendFile('/js/qtip/jquery.qtip-1.0.0.min.js','text/javascript'); $this->view->headScript()->appendFile('/js/airtime/library/library.js','text/javascript'); + $this->view->headScript()->appendFile('/js/airtime/library/advancedsearch.js','text/javascript'); $this->view->headLink()->appendStylesheet('/css/media_library.css'); $this->view->headLink()->appendStylesheet('/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->view->md = $this->search_sess->md; $this->_helper->actionStack('index', 'playlist'); } diff --git a/application/controllers/SearchController.php b/application/controllers/SearchController.php index 93f3d40c5..d0792b58e 100644 --- a/application/controllers/SearchController.php +++ b/application/controllers/SearchController.php @@ -28,14 +28,11 @@ class SearchController extends Zend_Controller_Action public function init() { - if(!Zend_Auth::getInstance()->hasIdentity()) - { - $this->_redirect('login/index'); - } - $ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext->addActionContext('newfield', 'json') ->addActionContext('newgroup', 'json') + ->addActionContext('index', 'json') + ->addActionContext('display', 'json') ->initContext(); $this->search_sess = new Zend_Session_Namespace("search"); @@ -43,54 +40,24 @@ class SearchController extends Zend_Controller_Action public function indexAction() { - $this->_helper->layout->setLayout('search'); + $data = $this->_getParam('data'); + $form = new Application_Form_AdvancedSearch(); + + // Form has been submitted + $form->preValidation($data); + + //if (!$form->isValid($data)) { + //$this->view->form = $form->__toString(); + //return; + //} - $this->view->headScript()->appendFile('/js/contextmenu/jjmenu.js','text/javascript'); - $this->view->headLink()->appendStylesheet('/css/contextmenu.css'); - - $this->_helper->actionStack('contents', 'library'); - $this->_helper->actionStack('display', 'search'); - $this->_helper->actionStack('index', 'playlist'); + // valid form was submitted set as search criteria. + $this->search_sess->md = $data; } public function displayAction() { - $this->view->headScript()->appendFile('/js/airtime/library/advancedsearch.js','text/javascript'); - $this->view->headLink()->appendStylesheet('/css/library_search.css'); - - $this->_helper->viewRenderer->setResponseSegment('search'); - - $request = $this->getRequest(); - - $form = new Application_Form_AdvancedSearch(); - $this->view->form = $form; - - // Form has not been submitted - displayed using layouts - if (!$request->isPost()) { - - $form->addGroup(1, 1); - - $this->search_sess->next_group = 2; - $this->search_sess->next_row[1] = 2; - - return; - } - - $this->view->md = $request->getPost(); - - // Form has been submitted - $form->preValidation($request->getPost()); - if (!$form->isValid($request->getPost())) { - return; - } - - // valid form was submitted set as search criteria. - $this->view->md = $form->getValues(); - $this->search_sess->md = $form->getValues(); - - //make sure to start on first page of new results. - unset($this->search_sess->page); } public function newfieldAction() @@ -113,8 +80,6 @@ class SearchController extends Zend_Controller_Action $this->search_sess->next_group = $group_id + 1; $this->search_sess->next_row[$group_id] = 2; } - - } diff --git a/application/forms/AdvancedSearch.php b/application/forms/AdvancedSearch.php index f8fae8705..ff074718b 100644 --- a/application/forms/AdvancedSearch.php +++ b/application/forms/AdvancedSearch.php @@ -14,7 +14,7 @@ class Application_Form_AdvancedSearch extends Zend_Form $this->getElement('search_add_group')->removeDecorator('DtDdWrapper'); // Add the submit button - $this->addElement('submit', 'search_submit', array( + $this->addElement('button', 'search_submit', array( 'ignore' => true, 'label' => 'Submit', 'order' => '-1' diff --git a/application/forms/AdvancedSearchGroup.php b/application/forms/AdvancedSearchGroup.php index 5a5541673..e2571885f 100644 --- a/application/forms/AdvancedSearchGroup.php +++ b/application/forms/AdvancedSearchGroup.php @@ -11,6 +11,14 @@ class Application_Form_AdvancedSearchGroup extends Zend_Form_SubForm 'order' => '-2' )); $this->getElement('search_add_row')->removeDecorator('DtDdWrapper'); + + // Add the add button + $this->addElement('button', 'search_remove_group', array( + 'ignore' => true, + 'label' => 'Remove', + 'order' => '-1' + )); + $this->getElement('search_remove_group')->removeDecorator('DtDdWrapper'); } public function addRow($row_id, $data=null) { diff --git a/application/views/scripts/library/index.phtml b/application/views/scripts/library/index.phtml index ddcdd9120..7f0cb9169 100644 --- a/application/views/scripts/library/index.phtml +++ b/application/views/scripts/library/index.phtml @@ -19,5 +19,8 @@
- Some Text + +
md); ?>
diff --git a/application/views/scripts/search/display.phtml b/application/views/scripts/search/display.phtml index a527a6ec8..e0b36e6d7 100644 --- a/application/views/scripts/search/display.phtml +++ b/application/views/scripts/search/display.phtml @@ -1,6 +1,5 @@ form->setAction($this->url()); echo $this->form; echo var_dump($this->md); ?> diff --git a/public/js/airtime/library/advancedsearch.js b/public/js/airtime/library/advancedsearch.js index cff0065c9..c8152f75c 100644 --- a/public/js/airtime/library/advancedsearch.js +++ b/public/js/airtime/library/advancedsearch.js @@ -3,7 +3,7 @@ function addRemove(el) { id = $(el).attr("id").split("_").pop(); - span = $('Remove').click(function(){ + span = $('Remove').click(function(){ $(this).parent().parent().remove(); }); @@ -20,27 +20,45 @@ function ajaxAddRow() { $.post(url, {group: group_id}, function(json) { var newRow = $(json.html).find("#fieldset-row_"+json.row); + addRemove(newRow); $("#fieldset-group_"+group_id+" dl:first").append(newRow); }); } +function removeGroup() { + $(this).parent().parent().remove(); +} + function ajaxAddGroup() { var url = '/Search/newgroup/format/json'; $.post(url, function(json) { - - $(".zend_form").append(json.html); - $('[id$="search_add_row"]').click(ajaxAddRow); + + var group = $(json.html); + addRemove(group); + group.find('[id$="search_add_row"]').click(ajaxAddRow); + group.find('[id$="search_remove_group"]').click(removeGroup); + $(".zend_form").append(group); }); } +function advancedSearchSubmit() { + var data = $("#advancedSearch form").serializeArray(); + + $.post("/Search/index", {format: "json", data: data}, function(json){ + var x; + }); +} + $(document).ready(function() { $("#search_add_group").click(ajaxAddGroup); + $("#search_submit").click(advancedSearchSubmit); $('[id$="search_add_row"]').click(ajaxAddRow); + $('[id$="search_remove_group"]').click(removeGroup); $('[id^="fieldset-row_"]').each(function(i, el){ addRemove(el);