Ok, I'm really, really close now.
I have modified my module.js file so that M.block_private_files.init_reload now looks like this:
M.block_private_files.init_reload = function(Y, url, htmlid){
var handleSuccess = function(o) {
div.innerHTML = o.responseText;
//div.innerHTML = "<li>JARL!!!</li>";
};
var handleFailure = function(o) {
/*failure handler code*/
}
var callback = {
success:handleSuccess,
failure:handleFailure
};
var button = Y.one("#refreshEJSAppFBBut");
button.on("click", function (e) {
div = Y.YUI2.util.Dom.get(htmlid);
Y.use('yui2-connection', function(Y) {
Y.YUI2.util.Connect.asyncRequest('GET', url, callback);
});
});
};
And I modified the render_private_files_tree function inside the renderer.php file:
public function render_private_files_tree(private_files_tree $tree) {
$module = array('name'=>'private_files', 'fullpath'=>'/blocks/private_files/module.js', 'requires'=>array('yui2-treeview'));
if (empty($tree->dir['subdirs']) && empty($tree->dir['files'])) {
$html = $this->output->box(get_string('nofilesavailable', 'repository'));
} else {
$htmlid = 'private_files_tree_'.uniqid();
$url = 'http://localhost/blocks/private_files/tree_update.php?htmlid='+$htmlid;
$this->page->requires->js_init_call('M.block_ejsapp_file_browser.init_tree', array(false, $htmlid));
$this->page->requires->js_init_call('M.block_private_files.init_reload', array($url, $htmlid));
$html = '<div id="'.$htmlid.'">';
$html .= $this->htmllize_tree($tree, $tree->dir);
$html .= '</div>';
}
return $html;
}
This way, whatever I echo now in tree_update.php will be shown inside the private files block.
However, I still do not know how to call from php for a new refreshed file tree structure. I guess I could do it using the htmllize_tree() function inside the renderer.php file but since its an internal function of a class I'm not sure how to proceed.
At this stage, I just need to be able to call this function (htmllize_tree()) from my own php file (tree_update.php) and then echo the result. If I can do that, the rest of my problem is solved
Any help here?
PS. I hope these messages could be of any use to other people who starts working with AJAX and Moodle, just like me.