More use of list_active(), setup ajax actions that are check to be ajax

This commit is contained in:
Deon George
2012-10-07 15:15:34 +11:00
parent 4220ade8ac
commit 878c159e3a
19 changed files with 137 additions and 130 deletions

View File

@@ -12,44 +12,20 @@
*/
class Controller_Admin_Account extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'autocomplete'=>FALSE, // @todo To Change
'ajaxlist'=>FALSE, // @todo To Change
'list'=>TRUE,
'listlog'=>TRUE,
);
public function action_autocomplete() {
public function action_ajaxlist() {
$return = array();
$a = ORM::factory('account')->where('status','=',1);
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
$t = $_REQUEST['term'];
// @todo - Implement different search criteria, eg: @ by email, space for first/last, etc
if (FALSE) {
// All search
} else {
$a = $a
->where_open()
->where('first_name','like','%'.$t.'%')
->or_where('last_name','like','%'.$t.'%')
->or_where('company','like','%'.$t.'%')
->or_where('email','like','%'.$t.'%')
->where_close();
}
}
// @todo The results should be limited so that users dont see what they shouldnt.
foreach ($a->find_all() as $ao)
array_push($return,array(
'id'=>$ao->id,
'label'=>sprintf('%s (%s)',$ao->name(),$ao->email),
'value'=>$ao->id,
));
if (isset($_REQUEST['term']) AND trim($_REQUEST['term']))
$return += ORM::factory('account')->list_autocomplete($_REQUEST['term']);
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode($return));
$this->response->body(json_encode(array_values($return)));
}
/**