adding autocomplete from backend source into add show page.

This commit is contained in:
naomiaro 2011-01-25 23:14:35 -05:00
parent c109fb5f01
commit a607951ed9
4 changed files with 37 additions and 27 deletions

View file

@ -5,7 +5,9 @@ class UserController extends Zend_Controller_Action
public function init()
{
/* Initialize action controller here */
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('get-hosts', 'json')
->initContext();
}
public function indexAction()
@ -32,9 +34,10 @@ class UserController extends Zend_Controller_Action
public function getHostsAction()
{
$this->view->hosts = User::getHosts();
}
$search = $this->_getParam('term');
$this->view->hosts = User::getHosts($search);
}
}

View file

@ -15,7 +15,7 @@ class Application_Form_AddShowWho extends Zend_Form_SubForm
$hosts = User::getHosts();
foreach ($hosts as $host) {
$options[$host['id']] = $host['login'];
$options[$host['value']] = $host['label'];
}
//Add hosts selection

View file

@ -39,16 +39,14 @@ class User {
}
public static function getUsers($type=NULL, $search=NULL) {
public static function getUsers($type, $search=NULL) {
global $CC_DBC;
$sql;
$sql_gen = "SELECT id, login FROM cc_subjs ";
$sql_gen = "SELECT id AS value, login AS label FROM cc_subjs ";
$sql = $sql_gen;
if(!is_null($type)){
if(is_array($type)) {
for($i=0; $i<count($type); $i++) {
$type[$i] = "type = '{$type[$i]}'";
@ -59,19 +57,19 @@ class User {
$sql_type = "type = {$type}";
}
$sql = $sql_gen ." WHERE ". $sql_type;
}
if(!is_null($search)) {
$like = "login ILIKE '{$search}'";
}
$sql = $sql_gen ." WHERE (". $sql_type.")";
$sql = $sql . " ORDER BY login";
if(!is_null($search)) {
$like = "login ILIKE '%{$search}%'";
$sql = $sql . " AND ".$like." ORDER BY login";
}
return $CC_DBC->GetAll($sql);
}
public static function getHosts() {
return User::getUsers(array('H', 'A'));
public static function getHosts($search=NULL) {
return User::getUsers(array('H', 'A'), $search);
}
}

View file

@ -38,13 +38,22 @@ function createDateInput(el, onSelect) {
function autoSelect(event, ui) {
$("#hosts-"+ui.item.value).attr("checked", "checked");
$("#add_show_hosts-"+ui.item.value).attr("checked", "checked");
event.preventDefault();
}
function findHosts(request, callback) {
var search = request.term;
var search, url;
url = "/User/get-hosts";
search = request.term;
$.post(url,
{format: "json", term: search},
function(json) {
callback(json.hosts);
});
}