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() {
|
2011-05-14 07:35:33 +00:00
|
|
|
$this->response->headers('Content-Type','application/json');
|
2011-10-14 05:44:12 +00:00
|
|
|
$this->response->body(json_encode($this->output));
|
2011-08-27 06:33:46 +00:00
|
|
|
|
|
|
|
parent::after();
|
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">
|
2011-10-14 05:44:12 +00:00
|
|
|
<!--
|
2010-11-29 22:41:08 +00:00
|
|
|
$(function () {
|
|
|
|
$("#tree").jstree({
|
|
|
|
themes : {
|
2011-10-07 00:57:59 +00:00
|
|
|
"theme" : "classic",
|
2010-11-29 22:41:08 +00:00
|
|
|
},
|
|
|
|
ui : {
|
|
|
|
"select_limit" : 1,
|
|
|
|
"select_node" : false,
|
|
|
|
},
|
|
|
|
cookies : {
|
|
|
|
"save_selected" : false,
|
2011-10-14 05:44:12 +00:00
|
|
|
"cookie_options" : { path : "'.URL::site().'" }
|
2010-11-29 22:41:08 +00:00
|
|
|
},
|
|
|
|
json_data : {
|
|
|
|
"correct_state" : "true",
|
|
|
|
"progressive_render" : "true",
|
|
|
|
"ajax" : {
|
2011-10-07 00:57:59 +00:00
|
|
|
"url" : "'.URL::site('tree/json').'",
|
2010-11-29 22:41:08 +00:00
|
|
|
"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);
|
|
|
|
|
2011-10-07 00:57:59 +00:00
|
|
|
if (href = $("#N_"+id).attr("href")) {
|
2011-10-14 05:44:12 +00:00
|
|
|
$("#ajBODY").empty().html("<img src=\"'.URL::site('media/img/ajax-progress.gif').'\" alt=\"Loading...\" />");
|
2010-11-29 22:41:08 +00:00
|
|
|
$("#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);
|
|
|
|
}
|
|
|
|
});
|
2011-10-07 00:57:59 +00:00
|
|
|
} else
|
2010-11-29 22:41:08 +00:00
|
|
|
alert("Unknown: "+id+" HREF:"+href);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-10-14 05:44:12 +00:00
|
|
|
// -->
|
2010-11-29 22:41:08 +00:00
|
|
|
</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.
|
|
|
|
*
|
2011-09-24 13:13:38 +00:00
|
|
|
* @param array $data Tree data passed in by inherited methods
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
2011-09-24 13:13:38 +00:00
|
|
|
public function action_json(array $data=array()) {
|
2011-07-13 22:59:32 +00:00
|
|
|
if ($this->_auth_required() AND ! Auth::instance()->logged_in()) {
|
|
|
|
$this->output = array('attr'=>array('id'=>'a_login'),
|
2011-10-07 00:57:59 +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;
|
|
|
|
}
|
|
|
|
|
2011-07-13 22:59:32 +00:00
|
|
|
$this->output = array();
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
foreach ($data as $branch) {
|
2011-07-13 22:59:32 +00:00
|
|
|
array_push($this->output,array(
|
2010-11-29 22:41:08 +00:00
|
|
|
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
|
|
|
|
'state'=>$branch['state'],
|
|
|
|
'data'=>array('title'=>$branch['name']),
|
2011-10-07 00:57:59 +00:00
|
|
|
'attr'=>array('id'=>sprintf('N_%s',$branch['id']),'href'=>empty($branch['attr_href']) ? URL::site(sprintf('%s/menu',$branch['name'])) : $branch['attr_href']),
|
2010-11-29 22:41:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|