0

Is there a way to programmatically change the defaultViewID ?

I need to default my side bar view to one of 2 different views based on some condition when user opens up the side bar view from the snippet. Is there way to set view1 as default view when it it is first initialized and then change it to view2 afterwards.  I'm basically trying to send the user to a registration view if the user is accessing the application for the first time and once the user is registered I need to change the default view to the usual default view of the application.  

I can put the whole  KONtx.application.init inside a if  / else condition and set 2 different default view IDs, but the issue is after the registration is completed I want to change the default view ID dynamically, without the user having to stop and start the widget again. Please let me know if there is a way to achieve this.

by
5 Replies
  • I think you can handle the onActivateSnippet event in your snippet view and programmatically decide which view to load depending on whether the user has registered :

    In your snippet's initView you can register the handler as follows:

    this._handleActivateSnippet.subscribeTo(this, ['onActivateSnippet'], this);

    where _handleActivation may look like this:

    _handleActivation: function(event) {
        event.preventDefault();
        event.stopPropagation();
        if( API.hasUserRegistered() ) {
                log("Loading Main!");
            KONtx.application.setHostResultToViewId(event, 'view-Main');
        } else {
            log("Loading Registration page!");
            KONtx.application.setHostResultToViewId(event, 'view-Register');
            }
        }
    Thanks,
    Vivek
    QUOTE(SajuP @ 12 Nov 2011 10:23 PM)
    I need to default my side bar view to one of 2 different views based on some condition when user opens up the side bar view from the snippet. Is there way to set view1 as default view when it it is first initialized and then change it to view2 afterwards.  I'm basically trying to send the user to a registration view if the user is accessing the application for the first time and once the user is registered I need to change the default view to the usual default view of the application.  

    I can put the whole  KONtx.application.init inside a if  / else condition and set 2 different default view IDs, but the issue is after the registration is completed I want to change the default view ID dynamically, without the user having to stop and start the widget again. Please let me know if there is a way to achieve this.

    0
  • Ignore the typo: _handleActivation/_handleActivateSnippet are meant to be the same.

    QUOTE(Vivek Jani @ 13 Nov 2011 2:02 AM)
    I think you can handle the onActivateSnippet event in your snippet view and programmatically decide which view to load depending on whether the user has registered :

    In your snippet's initView you can register the handler as follows:

    this._handleActivateSnippet.subscribeTo(this, ['onActivateSnippet'], this);

    where _handleActivation may look like this:

    _handleActivation: function(event) {
        event.preventDefault();
        event.stopPropagation();
        if( API.hasUserRegistered() ) {
                log("Loading Main!");
            KONtx.application.setHostResultToViewId(event, 'view-Main');
        } else {
            log("Loading Registration page!");
            KONtx.application.setHostResultToViewId(event, 'view-Register');
            }
        }
    Thanks,
    Vivek
    QUOTE(SajuP @ 12 Nov 2011 10:23 PM)
    I need to default my side bar view to one of 2 different views based on some condition when user opens up the side bar view from the snippet. Is there way to set view1 as default view when it it is first initialized and then change it to view2 afterwards.  I'm basically trying to send the user to a registration view if the user is accessing the application for the first time and once the user is registered I need to change the default view to the usual default view of the application.  

    I can put the whole  KONtx.application.init inside a if  / else condition and set 2 different default view IDs, but the issue is after the registration is completed I want to change the default view ID dynamically, without the user having to stop and start the widget again. Please let me know if there is a way to achieve this.

    0
  • Thanks a lot Vivek, your suggestion will work just fine for my use case.
    0
  • Yahoo QA reported a defect for my widget related to default view ID. Here is my use case (currently I'm handling it using the code posted  above by Vivek).

    I have two views,   pre-registration-view  (home view before the widget is registered with the back end web application) and post-registration-view (home view after the widget is registered with the back end web application).

     Basically after the widget is installed and before it is registered using the Register option, I want to display the default view as pre-registration-view.  And after it is registered I always want to have the post-registration-view as the default view. Currently I'm handling it in the snippet activate event by checking if it is registered or not and load the appropriate view. This works fine for the normal flow of opening the side bar view from the snippet and appropriate view is displayed.

    The issue is when the back button (F10 on simulator) is pressed, irrespective of whether it is registered or not (obviously) whatever default view I had set in the init.js is displayed. For example if I had set the pre-registration-view as the default view, then after registration while on the post-registration-view if I press the back button it displays the pre-registration-view since it is the default view. And if I set the post-registration-view as the default view then before registration if I'm on the pre-registration-view back button will display the post-registration-view which is functionally incorrect.

    How can I handle this situation. As I understand from the above post, there is no API to change the default view.  Do I need to listen for an event on the back button and load the appropriate view based on the registration status, if that is the case , is there any documentation on how to implement the same. 
    0
  • You may handle the back button event on the second view(i.e the view that comes after the home view and from which you are coming back to the home view).

    Register it in the updateView and remember to de-register it in the hideView method.

    updateView: function(){
        this.backHandler = this.backBtnHandler.subscribeTo(KONtx.application, "onActivateBackButton", this);
    },

    hideView: function(){
        if(this.backHandler)
            this.backHandler.unsubscribeFrom(KONtx.application, "onActivateBackButton");
    },

    backBtnHandler: function(){
        event.preventDefault();
        event.stopPropagation();
        if(API.hasUserRegistered())
            KONtx.application.loadView("view-Main");
        else
            KONtx.application.loadView("view-Register");
    }

    Thanks,
    Vivek
    0

Recent Posts

in Design / Interaction - Yahoo! TV Widgets