none
Programatically Select Home Screen HTML

    Question

  • In the HTML client, is there way that would allow me to programmatically select which screen I want to appear as the home screen? I have three different types of users and, based on their permissions or data in the database, I would like to redirect them to their own view of the application. I've thought about just having a blank home screen and doing the logic there, but that would allow the user to navigate back to a blank screen.

    Thanks

    Jay


    Jay Turpin

    Monday, June 24, 2013 3:28 PM

Answers

  • In the default.htm, the bit that actually launches the home screen is:

           $(document).ready(function () {
                msls._run()
                .then(null, function failure(error) {
                    alert(error);
                });
            });

    The _run function takes a parameter of the screenId.  So you can call msls._run("HomeAdmin") to launch a screen named "HomeAdmin" instead of the normal home screen.

    Now, since the user isn't yet logged in to Lightswitch when this code is run, you may not be able to put all the appropriate logic to determine which screen to launch.  However, you can combine the two approaches...

    1. Suppose you have three different classes of user, "Limited", "Normal", and "Admin".  And you have three home screens, "HomeLimited", "HomeNormal", and "HomeAdmin"

    2. You set up a blank "Home" screen that is the default home screen for the app.  It has logic that determines, based on permissions/database info which screen to redirect to.  It then redirects to "http://yourwebsite.com/HTMLClient/default.htm?home=HomeAdmin" for admin users... or "home=HomeLimited" for limited users, etc.

    3. In the default.htm you have some javascript which parses the url to get the "home=" parameter and calls msls._run with the appropriate screenId.

    4. In your HomeAdmin, HomeLimited, and HomeNormal screens, you have some code which verifies that the user has appropriate privileges to use the screen.


    My Blog: dotnetlore.com Twitter: @DotNetLore


    Monday, June 24, 2013 10:01 PM

All replies

  • In the default.htm, the bit that actually launches the home screen is:

           $(document).ready(function () {
                msls._run()
                .then(null, function failure(error) {
                    alert(error);
                });
            });

    The _run function takes a parameter of the screenId.  So you can call msls._run("HomeAdmin") to launch a screen named "HomeAdmin" instead of the normal home screen.

    Now, since the user isn't yet logged in to Lightswitch when this code is run, you may not be able to put all the appropriate logic to determine which screen to launch.  However, you can combine the two approaches...

    1. Suppose you have three different classes of user, "Limited", "Normal", and "Admin".  And you have three home screens, "HomeLimited", "HomeNormal", and "HomeAdmin"

    2. You set up a blank "Home" screen that is the default home screen for the app.  It has logic that determines, based on permissions/database info which screen to redirect to.  It then redirects to "http://yourwebsite.com/HTMLClient/default.htm?home=HomeAdmin" for admin users... or "home=HomeLimited" for limited users, etc.

    3. In the default.htm you have some javascript which parses the url to get the "home=" parameter and calls msls._run with the appropriate screenId.

    4. In your HomeAdmin, HomeLimited, and HomeNormal screens, you have some code which verifies that the user has appropriate privileges to use the screen.


    My Blog: dotnetlore.com Twitter: @DotNetLore


    Monday, June 24, 2013 10:01 PM
  • Excellent! I think that solution will work. Thanks!

    Jay Turpin

    Thursday, June 27, 2013 2:31 PM
  • Depending upon the complexity of each Home Screen, an alternate approach might work by hiding control groups within the default home screen based upon permissions.

    Beth Massi demonstrates, both a simple and robust approach, in achieving this here: LightSwitch Tip: A Simple Way to Check User Permissions from the HTML Client

    And more robustly here: Using LightSwitch ServerApplicationContext and WebAPI to Get User Permissions

    Cheers,

    Roger

    Sunday, July 7, 2013 9:45 AM
  • Hello Jewel-

    When I am trying to use msls._run("HomeAdmin") , no HomeAdmin display will open after login where I can manage user permissions. Can you please elaborate little bit more how can I manage user roles and permissions in lightswitchHTML client.

    Thanks & Regards

    Harsh

    Sunday, September 15, 2013 9:01 PM
  • Hello Jewel-

    When I am trying to use msls._run("HomeAdmin") , no HomeAdmin display will open after login where I can manage user permissions. Can you please elaborate little bit more how can I manage user roles and permissions in lightswitchHTML client.

    Thanks & Regards

    Harsh

    This question thread, and my answer, is about how to programatically select which screen a LightSwitch HTML app uses for its home screen.

    You are asking a different question - you're asking about how to manage user permissions from a LightSwitch HTML Client.  You'll be more likely to get some help if you post a separate thread on that topic.

    At present, LightSwitch has built-in support for managing user permissions from the Desktop (Silverlight) Client, but not from the HTML Client.  Beth Massi has an article about this here: http://blogs.msdn.com/b/bethmassi/archive/2013/06/25/how-to-assign-users-roles-and-permissions-to-a-lightswitch-html-mobile-client.aspx

    If using the Silverlight Client for the user permission management is not an option for you, then you'll unfortunately need to create your own screen to do this.  You may find this thread helpful: http://social.msdn.microsoft.com/Forums/vstudio/en-US/b7c75b3e-277a-4a6b-9a19-460dc27feeab/administration-tab-using-html-client-application


    • Edited by J Lamb Tuesday, September 17, 2013 5:33 PM
    Tuesday, September 17, 2013 5:23 PM
  • Hi Jewel, 

    This is not working properly since LS implemented a new URL format, at least I am having a hard time with it. 

    I tried navigating to the desired page inside an if statement, in myapp.Start.created, being Start the name of the home screen:

    $.getJSON("../api/UserPermissions/", function (data) {
                myapp.permissions = data;
                if (myapp.permissions["LightSwitchApplication:SomePerm"]) {
                    myapp.showScreenX();
                }
                else {
                    myapp.showScreenY();
                }
    });


    or,

    $.getJSON("../api/UserPermissions/", function (data) {
                myapp.permissions = data;
                if (myapp.permissions["LightSwitchApplication:SomePerm"]) {
                    msls._run("ScreenX")
                    .then(null, function failure(error) {
                        alert(error);
                    });
                }
                else {
                    msls._run("ScreenY")
                    .then(null, function failure(error) {
                        alert(error);
                    });
                }
    });

    but I'm getting the error after a few back and forth navigations:

    "Cannot perform this action while a navigation is in progress"

    Any suggestions on how to select the home screen using code?


    Nicolás Lope de Barrios
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.


    Monday, September 1, 2014 11:00 PM