[FIXED] Keep same view when user change different site or different date


(kpham.p) #1

Hi guys,

So when user change date or site, Piwik keep goes back to the first View (e.g daskboard). Its actually make me goes nuts when I’m currently viewing Visitors->Times, Change to different site I have to click on Visiters->Times again.

Just a quick fix; I’ve made a little change to the /plugins/CoreHome/templates/menu.js to keep track of my last view using cookie. But in the hope that Piwik would have a better solution in next release.

Thanks,
Kpham.p

function menu()

menu.prototype =
{    
....
....    
    onClickLI: function ()
    {
    ....
    ....
        //Add both the parent ID and the actual click ID 
        document.cookie="LastView="+$(this).parents("li:first").attr("id")+","+this.id;
                
        return false;
        
    },
....
....
    loadFirstSection: function()
    {
        var self=this;
        
        //Add Ids to all of li.
        $("ul.nav").find("li").each( function(i){
            $(this).attr({ id: 'menu_liID_' + ++i });
        });
        
        
        /* If user is changing the date, or site we'll try to update the cookie.*/
        var LastView = menu.prototype.getCookie("LastView");
         
        if (LastView != null)
        {
            var liIDs = LastView.split(",");
            
            var my_ParentID;
            
            (liIDs[0]) ? my_ParentID = liIDs[0] : my_ParentID = liIDs[1];
                    
            $("#"+liIDs[1]).click();
            $("#"+my_ParentID).each(function(){
                        $("#"+liIDs[0]).showSuperfishUl(); 
                    });
            
            menu.prototype.requestedNewSite = null;
        }
        else //Default
        {
            $('li:first', self.param.superfish)
                    .click()
                    .each(function(){
                        $(this).showSuperfishUl(); 
            });
        }
    },
    
    getCookie: function (cookie_name)
    {
        var self=this;
        var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

        if ( results )
            return ( unescape ( results[2] ) );
        else
            return null;
        
    },
}
....
....
});