none
Is there any application wide initialization method in LightSwitch html client so I can add some cached states? RRS feed

  • Question

  • I have a LightSwitch html clien application that has some information to shared among all screens. Is there any methods in Javascript client side in which I can fire the query, save the results so it can used by other screens. Otherwise I have to write the query in every screens which is not optima for mobile application. 

    Note: these queries are lightswitch queries I designed through LightSwitch


    jl

    Thursday, August 22, 2013 4:58 AM

Answers

  • Hi Joe,

    One possible place to do so is in the default.htm page, where the application is launched.

        <script type="text/javascript">
            $(document).ready(function () {
                msls._run()
                .then(function succeed() {
                    // Do initialize work
                }, function failure(error) {
                    alert(error);
                });
            });
        </script>

    Another place is the created method for your Home screen. Since it's JavaScript and you can add random properties to objects, you can do the initialization work and cache the state there as well.

    myapp.BrowseOrders.created = function (screen) {
        // Do initialization work
        myapp.myState = {};
    };

    Best regards,
    Huy
    • Marked as answer by Joe Lee Tuesday, July 1, 2014 10:36 PM
    Friday, August 23, 2013 11:58 PM

All replies

  • Hi Joe,

    One possible place to do so is in the default.htm page, where the application is launched.

        <script type="text/javascript">
            $(document).ready(function () {
                msls._run()
                .then(function succeed() {
                    // Do initialize work
                }, function failure(error) {
                    alert(error);
                });
            });
        </script>

    Another place is the created method for your Home screen. Since it's JavaScript and you can add random properties to objects, you can do the initialization work and cache the state there as well.

    myapp.BrowseOrders.created = function (screen) {
        // Do initialization work
        myapp.myState = {};
    };

    Best regards,
    Huy
    • Marked as answer by Joe Lee Tuesday, July 1, 2014 10:36 PM
    Friday, August 23, 2013 11:58 PM
  • Hi Huy,

    Thanks for the reply. It would have resolved my issues if it there were a way to clear the LightSwitch html client navigation history. I have posted a question here: http://social.msdn.microsoft.com/Forums/vstudio/en-US/ae874adc-f6e6-411c-975f-52b73c5c8822/how-to-clear-lightswitch-html-client-navigation-history

    I have an LS html app that navigate 6 pages away from home page. Once the user reaches the last page and finished task, he has to press 6 times the Back button (at the top left corner that LS automatically added) to go to home page. I have provided a go Home button on some of the pages. The problem is that the LS will automatically add the Back button at the top left corner on Home page. Once a user is at home, go back does not make any sense.

    My temporary solution  is using location.reload(). It will clear the cache that you suggested.

    The other problem with location.reload() is that you can only have one root page. Application normally have multiple root pages( might be presented as tabs on Home page).  Once user landed on one of these root pages, ideally you want to clear the navigation history.

    I really appreciate if you can provide some insight on how to resolve these issues. 

    The application we develop is a real one with real clients. The out of box LS way to present the UI sometimes just cannot pass the user experience test.


    jl

    Saturday, August 24, 2013 12:23 AM
  • Hello Huy,
    I have a similar problem and was glad to find your post!

    I would like to pull in some data regardless of the screen that is loaded upfront. In case the user opens the application via a bookmark pointing to a certain screen, I cannot put the logic in a screen created event.

    Is it possible to access a DataWorkspace inside the succeed() function?

    I have tried this:

    myapp.activeDataWorkspace

    ..but this is not available if there is no screen loaded.

    This also fails:

    var dataWorkspace = new myapp.DataWorkspace();

    Is there any other way?

    Thanks a lot!

    - Andreas

    Tuesday, July 1, 2014 12:11 PM
  • Is it possible to access a DataWorkspace inside the succeed() function?

    Hi Andreas,

    In order to do this you can use msls.application.activeDataWorkspace instead of myapp.activeDataWorkspace.

    Whilst I'm guessing you've already resolved this, as it's an area I've just been working in I thought the solution may come in handy for someone else.

    HTH

    Monday, January 5, 2015 11:05 AM