Refreshing the autonav ONLY

Permalink
Is it possible to do?

My goal is to do an ajax login (or action method, exit) and then update the autonav to reflect the newly available pages in the autonav to the logged-in user while keeping the page's existing content from being lost in a page refresh.

Initially, I thought I could grab the autonav block controller, render it (using a template) and then use js to manipulate the DOM with the result. But - obviously - BlockView rendering does not return results but rather prints them.

Any thoughts on how best to do this?

Ricalsin
 
Ricalsin replied on at Permalink Reply
Ricalsin
<bump>
JohntheFish replied on at Permalink Reply
JohntheFish
You could use my Blocks by Ajax addon to load the autonav, then a small snippet of JavaScript to trigger a 'blocks_by_ajax' event whenever you want a reload, so trigger it from the completion of your login.

http://www.concrete5.org/marketplace/addons/blocks-by-ajax/...

There is not a Blocks By Ajax template for Autonav, so you could put it in a stack or develop a new template, which is usually a simple case of adding wrapping code to an existing template.

http://www.c5magic.co.uk/add-ons/blocks-ajax/developing-templates/...
http://www.concrete5.org/marketplace/addons/templates-for-blocks-by...
Ricalsin replied on at Permalink Reply
Ricalsin
Hello John and thanks for the links. I always appreciate your contributions to the C5 marketplace and the forums.

I went with coding an action method within a page controller; turning on php's output buffering and capturing the output of calling/setting/rendering the autonav blocktype controller into a variable which I then used to rewrite the dom with js.
cherrycake replied on at Permalink Reply
cherrycake
a somewhat dirty way of achieving this would be to make an ajax call to the existing page when the user is logged in and filter out the dom elements you want to update and just replace the old ones with the new ones.

such as:
function loggedInComplete() {
  $.load('#topNav', document.location.href + ' #topNav', function(){
      console.log('autonav updated')
  });
}


the above method uses jquery's load method, first argument being the element to load html into, second being the url with a space separator and then a selector filter which tells jquery to only use the html found inside #topNav from the respose.
Ricalsin replied on at Permalink Reply
Ricalsin
Thank you for your thoughts. I went with an approach outlined in my response to JohnTheFish (above). I found that by re-running the code that hard-codes the autonav, then rendering the template again produces the original C5 output for the autonav block - only this time using the captured output within my own script to rewrite the autonav div after exiting the controller action method.