2

Is there a way to get the logo clickable when using the application layout? Most web sites go back to the home page when clicking the logo at the top, and my users are asking for this. Couldn't figure out how to it... I'm pretty sure it has to do with the submittedValue, but how do you set it for the logo? Or it may be something totally different, not sure.

I found this: onClick Event Banner in Application Layout but I am not sure I want to add some client side JavaScript to all pages. There must be a better way.

Community
  • 1
  • 1
Ben Dubuc
  • 523
  • 3
  • 14

1 Answers1

6

Add a class productLogoClass="applicationLogo" to your logo like shown here.

Add a client side onclick event for this class which executes a partial refresh on an empty panel. This panel has a rendered property which always returns true but executes additional code if partial refresh was executed by client side onclick event.

<xe:applicationLayout
    ...
    <xe:this.configuration>
        <xe:oneuiApplication
            productLogo="/logo.png"
            productLogoClass="applicationLogo">
            ...
        </xe:oneuiApplication>
    </xe:this.configuration>
</xe:applicationLayout>
<xp:eventHandler
    event="onClientLoad"
    submit="false">
    <xp:this.script><![CDATA[var applicationLogo = dojo.query('.applicationLogo')[0];
        applicationLogo.onclick = function() {
        XSP.partialRefreshGet("#{id:onClickApplicationLogo}", 
            {params: {'onClickApplicationLogo': true}})
        }
    ]]></xp:this.script>
</xp:eventHandler>
<xp:panel id="onClickApplicationLogo">
    <xp:this.rendered><![CDATA[#{javascript:
        if (param.onClickApplicationLogo) {
            print("onClick application icon");
            context.redirectToPage("Home.xsp");
        }
        return true;}]]>
    </xp:this.rendered>
</xp:panel>

In this example it writes "onClick application icon" to server console and redirects to "Home.xsp".

Community
  • 1
  • 1
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Knut, nice use of dojo! Question - couldn't you just keep it all in client-side script and just use window.location.href to move to the home page? – Howard Feb 23 '15 at 22:42
  • 4
    Yes, of course, but Ben asked explicitly for server side code execution so I assumed it shall be used for something else too. – Knut Herrmann Feb 23 '15 at 23:00
  • 1
    In fact, I wanted to know if it was possible, as I may need to track a lot of stats to analyze how people work in the application. Client side is reat, as it avoids a trip to the server, but if I need to create some sort of stat document when a user clicks on the logo, I need server side code to generate the stats document. As soon as the stats are not needed, it will be client side code, for sure. – Ben Dubuc Feb 24 '15 at 13:31