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() public function init()
{ {
/* Initialize action controller here */ $ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('get-hosts', 'json')
->initContext();
} }
public function indexAction() public function indexAction()
@ -32,9 +34,10 @@ class UserController extends Zend_Controller_Action
public function getHostsAction() 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(); $hosts = User::getHosts();
foreach ($hosts as $host) { foreach ($hosts as $host) {
$options[$host['id']] = $host['login']; $options[$host['value']] = $host['label'];
} }
//Add hosts selection //Add hosts selection

View file

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

View file

@ -38,13 +38,22 @@ function createDateInput(el, onSelect) {
function autoSelect(event, ui) { function autoSelect(event, ui) {
$("#hosts-"+ui.item.value).attr("checked", "checked"); $("#add_show_hosts-"+ui.item.value).attr("checked", "checked");
event.preventDefault(); event.preventDefault();
} }
function findHosts(request, callback) { 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);
});
} }