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

@@ -91,7 +91,7 @@ class Controller_Admin_Charge extends Controller_TemplateDefault_Admin {
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
$("input[name=account_id]").autocomplete({
source: "'.URL::site('admin/account/autocomplete').'",
source: "'.URL::site('admin/account/ajaxlist').'",
minLength: 2,
change: function(event,ui) {
// Send the request and update sub category dropdown
@@ -100,7 +100,7 @@ class Controller_Admin_Charge extends Controller_TemplateDefault_Admin {
data: "aid="+$(this).val(),
dataType: "json",
cache: false,
url: "'.URL::site('admin/service/autolist').'",
url: "'.URL::site('admin/service/ajaxlist').'",
timeout: 2000,
error: function() {
alert("Failed to submit");
@@ -115,7 +115,7 @@ class Controller_Admin_Charge extends Controller_TemplateDefault_Admin {
// Fill sub category select
$.each(data, function(i, j){
var row = "<option value=\"" + j.value + "\">" + j.text + "</option>";
var row = "<option value=\"" + j.value + "\">" + j.label + "</option>";
$(row).appendTo("select[name=service_id]");
});
}

View File

@@ -577,7 +577,7 @@ class Model_Invoice extends ORMOSB {
* @todo This should be optimised a little to return only invoices to send, instead of looking for them.
*/
public function list_tosend() {
return ORM::factory('invoice')->where('status','=',1)->where_open()->where('print_status','is',NULL)->or_where('print_status','!=',1)->where_close();
return ORM::factory('invoice')->where_active()->where_open()->where('print_status','is',NULL)->or_where('print_status','!=',1)->where_close();
}
public function html() {

View File

@@ -16,15 +16,11 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
'addbulk'=>TRUE,
'list'=>TRUE,
'view'=>TRUE,
'autocomplete'=>FALSE,
'ajaxlist'=>FALSE,
'autoitemlist'=>FALSE,
);
public function action_autocomplete() {
// We are only available via an ajax call.
if (! Request::current()->is_ajax())
die();
public function action_ajaxlist() {
$return = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
@@ -155,7 +151,7 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
}
});
$("input[name=account_id]").autocomplete({
source: "'.URL::site('admin/payment/autocomplete').'",
source: "'.URL::site('admin/payment/ajaxlist').'",
minLength: 2,
change: function(event,ui) {
// Send the request and update sub category dropdown

View File

@@ -34,8 +34,7 @@ class Controller_Product_Category extends Controller_TemplateDefault {
*/
private function _get_categories() {
return ORM::factory('product_category')
->where('status','=',TRUE)
->find_all();
->list_active();
}
}
?>

View File

@@ -13,7 +13,7 @@
class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
// @todo This "module" menu items should belong in the module dir.
protected $secure_actions = array(
'autolist'=>FALSE, // @todo To Change
'ajaxlist'=>FALSE, // @todo To Change
'adslstat'=>TRUE,
'list'=>TRUE,
'listbycheckout'=>TRUE,
@@ -31,23 +31,17 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'view'=>TRUE,
);
public function action_autolist() {
public function action_ajaxlist() {
$return = array();
$s = ORM::factory('service')->where_active();
if (isset($_REQUEST['aid']))
$s = $s->where('account_id','=',$_REQUEST['aid']);
// @todo This should limit the results so that users dont see other users services.
foreach ($s->find_all() as $so)
array_push($return,array(
'value'=>$so->id,
'text'=>sprintf('%s: %s',$so->id,$so->service_name()),
));
$return += ORM::factory('service')->list_autocomplete(
isset($_REQUEST['term']) ? $_REQUEST['term'] : '',
'id',
isset($_REQUEST['aid']) ? array(array('account_id','=',$_REQUEST['aid'])) : array());
$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)));
}
/**
@@ -84,7 +78,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
// @todo This needs to be configurable
$go = ORM::factory('group',array('name'=>'Personal'));
foreach (ORM::factory('account')->where('status','=',1)->find_all() as $ao)
foreach (ORM::factory('account')->list_active() as $ao)
if ($ao->has_any('group',array($go)))
foreach ($ao->service->list_active() as $so)
if (! $so->service_billing->checkout_plugin_id)

View File

@@ -54,7 +54,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
// @todo This needs to be configurable
$go = ORM::factory('group',array('name'=>'Personal'));
foreach (ORM::factory('account')->where('status','=',1)->find_all() as $ao)
foreach (ORM::factory('account')->list_active() as $ao)
if ($ao->has_any('group',array($go)))
foreach ($this->filter($ao->service->list_active(),$this->ao->affiliate->id,'name()') as $so)
if (! $so->service_billing->checkout_plugin_id)

View File

@@ -143,6 +143,36 @@ class Model_Service extends ORMOSB {
/** LIST FUNCTIONS **/
/**
* Search for services matching a term
*/
public function list_autocomplete($term,$index='id',array $limit=array()) {
$return = array();
$this->clear();
$this->where_active();
$value = 'service_name()';
// Build our where clause
$this->where_open()
->where('id','like','%'.$term.'%')
->where_close();
foreach ($limit as $w) {
list($k,$s,$v) = $w;
$this->and_where($k,$s,$v);
}
foreach ($this->find_all() as $o)
$return[$o->$index] = array(
'value'=>$o->$index,
'label'=>sprintf('SVC %s: %s',$o->id,Table::resolve($o,$value)),
);
return $return;
}
public function list_bylistgroup($cat) {
$result = array();

View File

@@ -27,7 +27,7 @@ class Controller_User_Statement extends Controller_TemplateDefault_User {
$ta[$i]['payment'] = $o;
}
foreach ($this->ao->invoice->where('status','!=',0)->find_all() as $o) {
foreach ($this->ao->invoice->list_active() as $o) {
$i = count($ta);
$ta[$i]['time'] = $o->date_orig;
$ta[$i]['invoice'] = $o;