2

Show or hide tabs based on organization tags (Web portal)

Original topic placed here https://support.zendesk.com/entries/175801-show-or-hide-tabs-based-on-organization . But this method based on OrganizationID and is not flexible. I'll show other way to control menu tabs, based on organization tags.

For example we need to show "Create new" and "My requests" tabs for organization without tag "expired". There are two ways:

  • Create single Custom HTML widget with script. This widget will hide tabs if organization *has *a tag "expired". But you can't place this widget to all pages e.g. forum post.

  • Create two widgets. Global CSS which will hide tabs for everyone and Custom HTML which will show tabs if organization hasn't a tag "expired".

I choose second way. Let's do it.

 

  1. Create Global CSS widget and place next code:

.tab_new

{

display:none;

}

.tab_requests

{

display:none;

}

 

  1. Create Custom HTML widget and place it to all pages.

<p> Show menu widget</p>

<script type="text/javascript" charset="utf-8">

Event.observe(document, 'widgets:load', function() {

new Ajax.Request('/users/current.json',

    {

    method:'GET',asynchronous: true,onSuccess: function(transport)

        {

        var obj = transport.responseText.evalJSON();

        org_id = obj['organization_id'];

        new Ajax.Request ('/organizations/'+org_id+'.json',

            {

            method:'GET',asynchronous: true,onSuccess: function(transport)

                {

                var obj = transport.responseText.evalJSON();

                tags = obj['current_tags'];

                    

                if (tags.search("expired")<0)
                    {
                    $j('.tab\_new').show();
                    $j('.tab\_requests').show();
                    };
                };
            });
        }
    });
        
});
</script>

 

39 comments

Please sign in to leave a comment.