Consistency updates for use of viewpath()

This commit is contained in:
Deon George 2011-12-21 12:39:21 +11:00
parent a40ce27a16
commit a893527d77
42 changed files with 125 additions and 125 deletions

View File

@ -262,6 +262,29 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
return sprintf('© %s',Config::SiteName());
}
/**
* Generate a view path to help View::factory() calls
*
* The purpose of this method is to ensure that we have a consistant
* layout for our view files, including those that are needed by
* plugins
*
* @param string Plugin Name (optional)
*/
public function viewpath($plugin='') {
$request = Request::current();
$path = '';
$path .= $request->controller();
if ($request->directory())
$path .= ($path ? '/' : '').$request->directory();
if ($plugin)
$path .= ($path ? '/' : '').$plugin;
$path .= ($path ? '/' : '').$request->action();;
return $path;
}
/**
* This action will render all the media related files for a page
* @return void

View File

@ -57,7 +57,7 @@ class Controller_User_Account extends Controller_TemplateDefault_User {
Block::add(array(
'title'=>_('Password Reset'),
'body'=>View::factory('account/password_reset')
'body'=>View::factory($this->viewpath())
->set('record',$this->ao),
));
}
@ -97,7 +97,7 @@ class Controller_User_Account extends Controller_TemplateDefault_User {
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Account Edit'),$this->ao->accnum(),$this->ao->name(TRUE)),
'body'=>View::factory('account/user/edit')
'body'=>View::factory($this->viewpath())
->set('record',$this->ao),
));
}

View File

@ -253,6 +253,12 @@ $(document).ready(function() {
}
public static function page($key) {
// We have preference for parameters passed to the action.
if (is_null($id = Request::current()->param('id'))) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post($key,'id');
if ($ids = Session::instance()->get('page_table_view'.$key)) {
$pag = new Pagination(array(
'total_items'=>count($ids),
@ -260,10 +266,12 @@ $(document).ready(function() {
));
return array($ids[$pag->current_first_item()-1],(string)$pag);
}
}
// If we get here, then there is no previous data to retrieve.
} else
return array(NULL,'');
return array($id,'');
}
}
?>

View File

@ -53,11 +53,11 @@ class Model_Account extends Model_Auth_UserDefault {
}
public function currency($name) {
return StaticListModule::form($name,'currency',$this->currency_id,'id','name',array());
return StaticList_Module::form($name,'currency',$this->currency_id,'id','name',array('status'=>'=:1'),FALSE,array('class'=>'form_button'));
}
public function country($name) {
return StaticListModule::form($name,'country',$this->country_id,'id','name',array());
return StaticList_Module::form($name,'country',$this->country_id,'id','name',array('active'=>'=:1'),FALSE,array('class'=>'form_button'));
}
public function language($name) {

View File

@ -104,21 +104,6 @@ abstract class ORMOSB extends ORM {
$model->$field = serialize($value);
}
/**
* Generate a view path to help View::factory() calls
*
* The purpose of this method is to ensure that we have a consistant
* layout for our view files, including those that are needed by
* plugins
*
* @param string Plugin Name (optional)
*/
public function viewpath($plugin='') {
$request = Request::current();
return $plugin ? sprintf('%s/%s/%s/%s',$request->controller(),$request->directory(),$plugin,$request->action()) : sprintf('%s/%s/%s',$request->controller(),$request->directory(),$request->action());
}
public function changed() {
return $this->_changed;
}

View File

@ -69,7 +69,7 @@ class Controller_Admin_Charge extends Controller_TemplateDefault_Admin {
}
$output .= Form::open();
$output .= View::factory('charge/admin/add');
$output .= View::factory($this->viewpath());
$output .= Form::submit('submit','submit');
$output .= Form::close();

View File

@ -50,12 +50,13 @@ class Controller_Admin_Email extends Controller_TemplateDefault_Admin {
$eto = ORM::factory('email_template');
$output = '';
$output .= View::factory('email/admin/template/list_head');
// @todo Change this to use Table::
$output .= View::factory($this->viewpath().'/head');
foreach ($eto->find_all() as $et) {
$output .= View::factory('email/admin/template/list_body')
$output .= View::factory($this->viewpath().'/body')
->set('template',$et);
}
$output .= View::factory('email/admin/template/list_foot');
$output .= View::factory($this->viewpath().'/foot');
Block::add(array(
'title'=>_('Available Email Templates'),
@ -85,8 +86,8 @@ class Controller_Admin_Email extends Controller_TemplateDefault_Admin {
}
$output .= Form::open();
$output .= View::factory('email/admin/template/add');
$output .= View::factory('email/admin/template/translate/add');
$output .= View::factory($this->viewpath());
$output .= View::factory($this->viewpath().'/translate');
$output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';
$output .= Form::close();
@ -99,6 +100,7 @@ class Controller_Admin_Email extends Controller_TemplateDefault_Admin {
/**
* Edit Template Definition
* @todo Change this into an add_view function like payment()
*/
public function action_templateedit($id) {
$eto = ORM::factory('email_template',$id);
@ -122,11 +124,11 @@ class Controller_Admin_Email extends Controller_TemplateDefault_Admin {
$output .= Form::open();
$output .= View::factory('email/admin/template/edit')
$output .= View::factory($this->viewpath())
->set('template',$eto);
foreach ($eto->email_template_translate->find_all() as $to) {
$output .= View::factory('email/admin/template/translate/edit')
$output .= View::factory($this->viewpath().'/translate')
->set('translate',$to);
SystemMessage::add(array(

View File

@ -39,17 +39,7 @@ class Controller_User_Email extends Controller_TemplateDefault_User {
}
public function action_view() {
$output = '';
if (! $id = $this->request->param('id')) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post('email_view','id');
list($id,$output) = Table::page('email_view');
} else {
$id = $this->request->param('id');
}
list($id,$output) = Table::page(__METHOD__);
$elo = ORM::factory('email_log',$id);
@ -58,7 +48,7 @@ class Controller_User_Email extends Controller_TemplateDefault_User {
return FALSE;
}
$output .= View::factory('email/user/view')
$output .= View::factory($this->viewpath())
->set('elo',$elo);
Block::add(array(

View File

@ -39,7 +39,7 @@ class Controller_Admin_Export extends Controller_TemplateDefault_Admin {
}
$output .= Form::open();
$output .= View::factory('export/admin/map/add')
$output .= View::factory($this->viewpath())
->set('eo',$eo);
$output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';

View File

@ -47,17 +47,7 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
* View an Invoice
*/
public function action_view() {
$output = '';
if (! $id = $this->request->param('id')) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post('invoice_view','id');
list($id,$output) = Table::page('invoice_view');
} else {
$id = $this->request->param('id');
}
list($id,$output) = Table::page(__METHOD__);
$io = ORM::factory('invoice',$id);
@ -66,7 +56,7 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
return FALSE;
}
$output .= View::factory('invoice/user/view')
$output .= View::factory($this->viewpath())
->set('mediapath',Route::get('default/media'))
->set('io',$io);

View File

@ -515,7 +515,7 @@ class Model_Invoice extends ORMOSB {
$css .= 'tr.even { background-color: #F6F6F8; }';
$css .= '</style>';
$output = View::factory('invoice/user/email')
$output = View::factory($this->viwepath())
->set('mediapath',Route::get('default/media'))
->set('io',$this);

View File

@ -14,6 +14,7 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'add'=>TRUE,
'list'=>TRUE,
'view'=>TRUE,
'autocomplete'=>FALSE,
'autoitemlist'=>FALSE,
);
@ -40,24 +41,24 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
if (! Request::current()->is_ajax() OR ! isset($_REQUEST['key']) OR ! trim($_REQUEST['key']))
die();
$output = View::factory('payment/admin/item/list_head');
$output = View::factory($this->viewpath().'/head');
$this->auto_render = FALSE;
$i = 0;
if (isset($_REQUEST['pid']))
foreach (ORM::factory('payment_item')->where('payment_id','=',$_REQUEST['pid'])->find_all() as $pio)
$output .= View::factory('payment/admin/item/list_body')
$output .= View::factory($this->viewpath().'/body')
->set('trc',$i++%2 ? 'odd' : 'even')
->set('pio',$pio)
->set('io',$pio->invoice);
foreach (ORM::factory('account',$_REQUEST['key'])->invoices_due() as $io)
$output .= View::factory('payment/admin/item/list_body')
$output .= View::factory($this->viewpath().'/body')
->set('trc',$i++%2 ? 'odd' : 'even')
->set('io',$io);
// @todo Need the JS to add up the payment allocation before submission
$output .= View::factory('payment/admin/item/list_foot')
$output .= View::factory($this->viewpath().'/foot')
->set('trc',$i++%2 ? 'odd' : 'even');
$this->response->body($output);
@ -73,7 +74,7 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
ORM::factory('payment')->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'admin/payment/add/'),
'id'=>array('label'=>'ID','url'=>'admin/payment/view/'),
'date_payment'=>array('label'=>'Date'),
'account->accnum()'=>array('class'=>'right'),
'account->name()'=>array('label'=>'Account'),
@ -85,24 +86,12 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'admin/payment/add',
'form'=>'admin/payment/view',
)),
));
}
public function action_add() {
$output = '';
if (! $id = $this->request->param('id')) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post('payment_view','id');
list($id,$output) = Table::page('payment_view');
} else {
$id = $this->request->param('id');
}
private function add_view($id=NULL,$output='') {
$po = ORM::factory('payment',$id);
if ($_POST) {
@ -128,7 +117,7 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
}
$output .= Form::open();
$output .= View::factory('payment/admin/add')
$output .= View::factory('payment/admin/add_view')
->set('po',$po);;
$output .= Form::submit('submit','submit',array('class'=>'form_button'));
$output .= Form::close();
@ -195,9 +184,22 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
));
}
return $output;
}
public function action_add() {
Block::add(array(
'title'=>_('Add Payments Received'),
'body'=>$output,
'body'=>$this->add_view(),
));
}
public function action_view() {
list($id,$output) = Table::page(__METHOD__);
Block::add(array(
'title'=>sprintf('%s: %s',_('View Payments Received'),$id),
'body'=>$this->add_view($id,$output),
));
}
}

View File

@ -26,7 +26,7 @@ class Controller_Product extends Controller_TemplateDefault {
Block::add(array(
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
'body'=>View::factory('product/category/view')
'body'=>View::factory($this->viewpath().'/view')
->set('results',$this->_get_category($cat->id))
->set('cat',$cat->id),
));
@ -63,7 +63,7 @@ class Controller_Product extends Controller_TemplateDefault {
Block::add(array(
'title'=>$po->product_translate->find()->description_short,
'body'=>View::factory('product/view')
'body'=>View::factory($this->viewpath())
->set('record',$po),
));
}

View File

@ -15,6 +15,10 @@ class Controller_Product_Category extends Controller_TemplateDefault {
* By default show a menu of available categories
*/
public function action_index() {
Request::current()->redirect('product_category/list');
}
public function action_list() {
Block::add(array(
'title'=>_('Product Categories'),
'body'=>View::factory('product/category/list')

View File

@ -62,7 +62,7 @@ echo Form::open('cart/add');
<!-- @todo If CURRENCY's value is not active in the DB, then the wrong flag is shown, as StaticList_Module::form() only returns active values -->
<!-- @todo Currency is not used in the cart? -->
<?php $CURRENCY_ISO='AUD'; $CURRENCY=6; $COUNTRY=61?>
<td class="body"><?php echo StaticList_Module::form('currency','currency',$CURRENCY,'id','name',array('status'=>'=:1'));?> <?php echo Country::icon($COUNTRY);?></td>
<td class="body"><?php echo StaticList_Module::form('currency','currency',$CURRENCY,'id','name',array('status'=>'=:1'),FALSE,array('class'=>'form_button'));?> <?php echo Country::icon($COUNTRY);?></td>
</tr>
<tr>
<td class="body"><b>Price Type</b></td>

View File

@ -360,7 +360,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
$i = $j = 0;
$total = 0;
$summary = '';
$output = View::factory('service/admin/list/adslbilling_head');
$output = View::factory($this->viewpath().'/head');
$output .= '<table class="box-left">';
foreach ($aso->services(TRUE) as $so) {
$po = $so->plugin()->product();
@ -377,7 +377,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
// Record the the exception if the cost is not expected
if (round($po->adsl_supplier_plan->base_cost+$po->adsl_supplier_plan->tax(),2) != $uploaded['amount']) {
$summary .= View::factory('service/admin/list/adslbilling_summary')
$summary .= View::factory($this->viewpath().'/summary')
->set('service',$so)
->set('plan',$po)
->set('planoverride',$so->plugin()->provided_adsl_plan_id ? TRUE : FALSE)
@ -398,7 +398,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
$total += $uploaded['amount'];
$output .= View::factory('service/admin/list/adslbilling_body')
$output .= View::factory($this->viewpath().'/body')
->set('service',$so)
->set('plan',$po)
->set('planoverride',$so->plugin()->provided_adsl_plan_id ? TRUE : FALSE)
@ -409,7 +409,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
->set('i',$i++%2);
}
$output .= View::factory('service/admin/list/adslbilling_foot')
$output .= View::factory($this->viewpath().'/foot')
->set('total',$total);
$output .= '</table>';
@ -417,7 +417,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
// Summary Report of remaining CSV items.
if (! empty($csv))
foreach ($csv as $service => $item) {
$summary .= View::factory('service/admin/list/adslbilling_summary_exception')
$summary .= View::factory($this->viewpath().'/summary_exception')
->set('service',$service)
->set('item',$item)
->set('i',$j++%2);

View File

@ -41,18 +41,7 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
}
public function action_view() {
$output = '';
// Check if we are a table view
if (! $id = $this->request->param('id')) {
if (isset($_POST['id']) AND is_array($_POST['id']))
Table::post('service_view','id');
list($id,$output) = Table::page('service_view');
} else {
$id = $this->request->param('id');
}
list($id,$output) = Table::page(__METHOD__);
$so = ORM::factory('service',$id);
@ -61,7 +50,7 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
return FALSE;
}
$output .= View::factory('service/user/view')
$output .= View::factory($this->viewpath())
->set('so',$so);
Block::add(array(

View File

@ -37,7 +37,8 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
}
public function action_update() {
$id = $this->request->param('id');
list($id,$output) = Table::page(__METHOD__);
$so = ORM::factory('ssl_ca',$id);
if (! $so->loaded())
@ -48,11 +49,13 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
throw new Kohana_Exception('Failed to save updates to plugin data for record :record',array(':record'=>$so->id()));
}
$output .= View::factory($this->viewpath())
->set('so',$so)
->set('mediapath',Route::get('default/media'));
Block::add(array(
'title'=>sprintf('%s %s:%s',_('Update SSL Service'),$so->id,$so->display('sign_cert')),
'body'=>View::factory('ssl/admin/update')
->set('so',$so)
->set('mediapath',Route::get('default/media'))
'body'=>$output,
));
}
}

View File

@ -59,7 +59,7 @@ class Controller_User_Statement extends Controller_TemplateDefault_User {
));
$output = (string)$pag;
$output .= View::factory('statement/user/show_head');
$output .= View::factory($this->viewpath().'/head');
$i = 0;
foreach ($ta as $k => $v) {
@ -68,12 +68,12 @@ class Controller_User_Statement extends Controller_TemplateDefault_User {
elseif ($i > $pag->current_last_item())
break;
$output .= View::factory('statement/user/show_body')
$output .= View::factory($this->viewpath().'/body')
->set('o',$v)
->set('trc',$i%2 ? 'odd' : 'even');
}
$output .= View::factory('statement/user/show_foot');
$output .= View::factory($this->viewpath().'/foot');
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Transactions For'),$this->ao->accnum(),$this->ao->name(TRUE)),

View File

@ -25,7 +25,7 @@ class Controller_StaticPage extends Controller_TemplateDefault {
Block::add(array(
'title'=>$sp->staticpage_translate->find()->title,
'body'=>View::factory('staticpage/view')
'body'=>View::factory($this->viewpath())
->set('record',$sp),
));
}

View File

@ -15,6 +15,10 @@ class Controller_StaticPage_Category extends Controller_TemplateDefault {
* By default show a menu of available categories
*/
public function action_index() {
Request::current()->redirect('staticpage_category/list');
}
public function action_list() {
Block::add(array(
'title'=>_('Site Index Categories'),
'body'=>View::factory('staticpage/category/list')