2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class extends renders OSB menu tree.
|
|
|
|
*
|
|
|
|
* @package lnApp
|
|
|
|
* @subpackage Tree
|
|
|
|
* @category Controllers
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_lnApp_Tree extends Controller_Default {
|
|
|
|
/**
|
|
|
|
* @var string page media route as per [Route]
|
|
|
|
*/
|
2011-05-14 07:35:33 +00:00
|
|
|
protected static $jsmediaroute = 'default/media';
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
public function after() {
|
|
|
|
parent::after();
|
|
|
|
|
2011-05-14 07:35:33 +00:00
|
|
|
$this->response->headers('Content-Type','application/json');
|
|
|
|
$this->response->body(sprintf('[%s]',json_encode($this->output)));
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function js() {
|
2011-05-14 07:35:33 +00:00
|
|
|
$mediapath = Route::get(static::$jsmediaroute);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
return '
|
|
|
|
<div id="tree" class=""></div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function () {
|
|
|
|
$("#tree").jstree({
|
|
|
|
themes : {
|
|
|
|
"theme" : "default",
|
|
|
|
"url" : "'.URL::site($mediapath->uri(array('file'=>'css/jquery.jstree.css'))).'",
|
|
|
|
},
|
|
|
|
ui : {
|
|
|
|
"select_limit" : 1,
|
|
|
|
"select_node" : false,
|
|
|
|
},
|
|
|
|
cookies : {
|
|
|
|
"save_selected" : false,
|
|
|
|
},
|
|
|
|
json_data : {
|
|
|
|
"correct_state" : "true",
|
|
|
|
"progressive_render" : "true",
|
|
|
|
"ajax" : {
|
|
|
|
"url" : "'.URL::site('/tree/json').'",
|
|
|
|
"data" : function (n) {
|
|
|
|
return { id : n.attr ? n.attr("id") : "N_"+0 };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plugins : [ "themes", "json_data", "ui", "cookies" ],
|
|
|
|
});
|
|
|
|
|
|
|
|
// On selection
|
|
|
|
$("#tree").bind("select_node.jstree", function (e, data) {
|
|
|
|
if (a = data.rslt.obj.attr(\'id\').indexOf(\'_\')) {
|
|
|
|
id = data.rslt.obj.attr(\'id\').substr(a+1);
|
|
|
|
|
|
|
|
if (href = $("#N_"+id).attr("href"))
|
|
|
|
$("#ajBODY").load(href, function(r,s,x) {
|
|
|
|
if (s == "error") {
|
|
|
|
var msg = "Sorry but there was an error: ";
|
|
|
|
$("#ajBODY").html(msg + x.status + " " + x.statusText + r);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
else
|
|
|
|
alert("Unknown: "+id+" HREF:"+href);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the Tree Menu
|
|
|
|
*
|
|
|
|
* The incoming ID is either a Branch B_x or a Node N_x
|
|
|
|
* Where X is actually the module.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
public function action_json($id=null) {
|
2011-05-02 12:20:56 +00:00
|
|
|
#if (! Auth::instance()->logged_in()) {
|
2010-11-29 22:41:08 +00:00
|
|
|
if ($this->_auth_required()) {
|
|
|
|
$this->treedata = array('attr'=>array('id'=>'a_login'),
|
2011-05-02 12:20:56 +00:00
|
|
|
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'N_login','href'=>URL::site('/login'))));
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->treedata = array();
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
foreach ($data as $branch) {
|
|
|
|
array_push($this->treedata,array(
|
|
|
|
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
|
|
|
|
'state'=>$branch['state'],
|
|
|
|
'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']),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|