Fixed breadcrumb, added submode()

This commit is contained in:
Deon George 2011-12-09 15:10:53 +11:00
parent 56c11507f4
commit 08eab4b5f9
13 changed files with 75 additions and 26 deletions

View File

@ -141,7 +141,7 @@ Route::set('default/media', 'media(/<file>)', array('file' => '.+'))
* Set the routes. Each route must have a minimum of a name, a URI and a set of * Set the routes. Each route must have a minimum of a name, a URI and a set of
* defaults for the URI. * defaults for the URI.
*/ */
Route::set('default', '(<controller>(/<action>(/<id>)))', array('id' => '[a-zA-Z0-9_.-]+')) Route::set('default', '<controller>(/<action>(/<id>))', array('id' => '[a-zA-Z0-9_.-]+'))
->defaults(array( ->defaults(array(
'controller' => 'welcome', 'controller' => 'welcome',
'action' => 'index', 'action' => 'index',

View File

@ -10,8 +10,7 @@
* @copyright (c) 2010 Deon George * @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_Admin_Welcome extends Controller_TemplateDefault { class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin {
protected $auth_required = TRUE;
public $secure_actions = array( public $secure_actions = array(
'index'=>TRUE, 'index'=>TRUE,
); );

View File

@ -39,9 +39,16 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
* @var array actions that require a valid user * @var array actions that require a valid user
*/ */
protected $secure_actions = array( protected $secure_actions = array(
'menu' => FALSE,
); );
public function __construct(Request $request, Response $response) {
// Our Menu's can run without method authentication by default.
if (! isset($this->secure_actions['menu']))
$this->secure_actions['menu'] = FALSE;
return parent::__construct($request,$response);
}
/** /**
* Check and see if this controller needs authentication * Check and see if this controller needs authentication
* *
@ -197,6 +204,10 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
// In case there any style sheets for this render. // In case there any style sheets for this render.
$this->response->bodyadd(Style::factory()); $this->response->bodyadd(Style::factory());
// Since we are ajax, we should re-render the breadcrumb
Session::instance()->set('breadcrumb',(string)Breadcrumb::factory());
$this->response->bodyadd(Script::add(array('type'=>'stdin','data'=>'$().ready($("#ajCONTROL").load("'.URL::site('welcome/breadcrumb').'",null,function(x,s,r) {}));')));
// In case there any javascript for this render. // In case there any javascript for this render.
$this->response->bodyadd(Script::factory()); $this->response->bodyadd(Script::factory());

View File

@ -101,7 +101,7 @@ $(function () {
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])), 'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
'state'=>$branch['state'], 'state'=>$branch['state'],
'data'=>array('title'=>$branch['name']), 'data'=>array('title'=>$branch['name']),
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('%s/menu',$branch['name'])) : $branch['attr_href']), 'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('user/%s/menu',$branch['name'])) : $branch['attr_href']),
) )
); );
} }

View File

@ -22,9 +22,19 @@ class Controller_TemplateDefault_User extends Controller_TemplateDefault {
parent::before(); parent::before();
$this->ao = ORM::factory('account',Auth::instance()->get_user()->id); $this->ao = Auth::instance()->get_user();
if (! $this->ao->loaded()) if (! $this->ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>Auth::instance()->get_user()->id)); throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>Auth::instance()->get_user()->id));
} }
public function after() {
$dc = 'welcome/index';
$m = sprintf('%s/%s',Request::current()->directory(),Request::current()->controller());
Breadcrumb::URL(Request::current()->directory(),sprintf('%s/%s',Request::current()->directory(),$dc),FALSE);
Breadcrumb::URL($m,method_exists($this,'action_menu') ? $m.'/menu' : sprintf('%s/%s',Request::current()->directory(),$dc),FALSE);
parent::after();
}
} }
?> ?>

View File

@ -10,8 +10,10 @@
* @copyright (c) 2010 Deon George * @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_User_Welcome extends Controller_TemplateDefault { class Controller_User_Welcome extends Controller_TemplateDefault_User {
protected $auth_required = TRUE; protected $secure_actions = array(
'index'=>FALSE,
);
public function action_index() { public function action_index() {
$ao = ORM::factory('account',Auth::instance()->get_user()->id); $ao = ORM::factory('account',Auth::instance()->get_user()->id);

View File

@ -37,5 +37,11 @@ class Controller_Welcome extends Controller_TemplateDefault {
)); ));
} }
} }
public function action_breadcrumb() {
$this->auto_render = FALSE;
$this->response->body(Session::instance()->get_once('breadcrumb'));
}
} }
?> ?>

View File

@ -14,8 +14,8 @@ class Country {
public static function icon($cid) { public static function icon($cid) {
// @todo alt character should be country specific // @todo alt character should be country specific
// @todo This doesnt correctly get the right 3 character country code - it should be obtained from a join with country/currency // @todo This doesnt correctly get the right 3 character country code - it should be obtained from a join with country/currency
return HTML::image(sprintf('media/img/country/%s.gif',StaticList_Module::record('country','two_code','id',$cid)),array('alt'=>'$','style'=>'border: 0px;')); return HTML::image(sprintf('media/img/country/%s.png',strtolower(StaticList_Module::record('country','two_code','id',$cid))),array('alt'=>'$','style'=>'border: 0px;'));
return sprintf('media/img/country/%s.gif',StaticList_Module::record('country','three_code','id',$cid)); return sprintf('media/img/country/%s.png',strtolower(StaticList_Module::record('country','three_code','id',$cid)));
} }
} }
?> ?>

View File

@ -23,17 +23,32 @@ class lnApp_Breadcrumb extends HTMLRender {
public static function set($path) { public static function set($path) {
if (is_string($path)) if (is_string($path))
static::$_data['path'] = explode('/',$path); static::$_data['path'] = explode('/',$path);
else elseif (is_array($path))
static::$_data['path'] = $path; static::$_data['path'] = $path;
else
throw new Kohana_Exception('Path is not a string, nor an array');
} }
/** /**
* Enable a friendly name to be used for a path * Enable a friendly name to be used for a path
*/ */
public static function name($path,$name) { public static function name($path,$name,$override=TRUE) {
if (isset(static::$_data['name'][$path]) AND ! $override)
return;
static::$_data['name'][$path] = $name; static::$_data['name'][$path] = $name;
} }
/**
* Enable specifying the URL for a path
*/
public static function URL($path,$url,$override=TRUE) {
if (isset(static::$_data['url'][$path]) AND ! $override)
return;
static::$_data['url'][$path] = $url;
}
/** /**
* Return an instance of this class * Return an instance of this class
* *
@ -47,7 +62,9 @@ class lnApp_Breadcrumb extends HTMLRender {
* Render this Breadcrumb * Render this Breadcrumb
*/ */
protected function render() { protected function render() {
$output = HTML::anchor('/',_('Home')); // @todo Make this into a view
$output = '<table class="pagecontrol"><tr><td class="none">';
$output .= HTML::anchor('/',_('Home'));
$data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path']; $data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path'];
@ -55,9 +72,14 @@ class lnApp_Breadcrumb extends HTMLRender {
$output .= static::$_spacer; $output .= static::$_spacer;
$p = join('/',array_slice($data,0,$k+1)); $p = join('/',array_slice($data,0,$k+1));
$output .= HTML::anchor($p,empty(static::$_data['name'][$p]) ? ucfirst($v) : static::$_data['name'][$p]); $output .= HTML::anchor(
(empty(static::$_data['url'][$p]) ? $p : static::$_data['url'][$p]),
(empty(static::$_data['name'][$p]) ? ucfirst($v) : static::$_data['name'][$p])
);
} }
$output .= '</td></tr></table>';
return $output; return $output;
} }
} }

View File

@ -62,6 +62,12 @@ abstract class lnApp_Config extends Kohana_Config {
return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()]; return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()];
} }
public static function submode() {
$submode = Kohana::Config('config.debug.submode');
return (isset($submode[Request::$client_ip])) ? $submode[Request::$client_ip] : FALSE;
}
public static function sitename() { public static function sitename() {
return Config::instance()->loadsite()->so->site_name; return Config::instance()->loadsite()->so->site_name;
} }

View File

@ -32,11 +32,7 @@
<tr class="pagecontrol"> <tr class="pagecontrol">
<td colspan="3"> <td colspan="3">
<div id="ajCONTROL"> <div id="ajCONTROL">
<table class="pagecontrol"> <?php echo $control; ?>
<tr>
<td class="none"><?php echo $control; ?></td>
</tr>
</table>
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -10,10 +10,6 @@
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_HostServer extends Controller { class Controller_HostServer extends Controller {
// protected $_control = array(
// array('Product Categories'=>'product_category'),
// );
public function action_plesk_addclienttest($id) { public function action_plesk_addclienttest($id) {
$ao = ORM::factory('account',$id); $ao = ORM::factory('account',$id);

View File

@ -28,10 +28,11 @@ class Controller_User_Invoice extends Controller_TemplateDefault_User {
25, 25,
array( array(
'id'=>array('label'=>'ID','url'=>'user/invoice/view/'), 'id'=>array('label'=>'ID','url'=>'user/invoice/view/'),
'date_orig'=>array('label'=>'Date'), 'date_orig'=>array('label'=>'Date Issued'),
'total_amt'=>array('label'=>'Total','class'=>'right'), 'due_date'=>array('label'=>'Date Due'),
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
'credit_amt'=>array('label'=>'Credits','class'=>'right'), 'credit_amt'=>array('label'=>'Credits','class'=>'right'),
'billed_amt'=>array('label'=>'Payments','class'=>'right'), 'payments_total(TRUE)'=>array('label'=>'Payments','class'=>'right'),
'due(TRUE)'=>array('label'=>'Still Due','class'=>'right'), 'due(TRUE)'=>array('label'=>'Still Due','class'=>'right'),
), ),
array( array(