none
html client usage of myapp.showscreen() function? RRS feed

  • Question

  • hi!

    i'm trying to create tile listview menu for my home_screen, so i've created a table where every row represents screen in my application, it has few fields like id, name, display name and icon, so now i have tiled menu instead of button menu on my home page. on item tap action i'm calling:

    var selitem = screen.details.properties.HTML_Menus.value.selectedItem.name;
    msls.application.showScreen(selitem);

    this works fine for screens which are browse type, but i don't know how to pass parameter inside for addEditScreens, so if i have addEditScreen, i want to pass if this is new item, or i'm editing existing one.. currently addEditScreen opens but it's in "disabled mode"..

    thanks!

    Kivito

      

    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Sunday, April 7, 2013 10:43 AM

Answers

  • Hi Kivito,

    It's totally possible. Here's a sample:

    myapp.BrowseCustomers.AddCustomerCustom_execute = function (screen) {
        myapp.showScreen("AddEditCustomer", null, {
            beforeShown: function (addEditScreen) {
                // Create the new entity here so that
                // accept/cancel behavior will work.
                // Otherwise when user cancel, the new
                // entity will not be discarded.
                var newCustomer = new myapp.Customer();
                addEditScreen.Customer = newCustomer;
            }
        });
    };

    Best regards,
    Huy Nguyen

    Monday, April 8, 2013 5:13 PM
  • Hi Kivito,

    Going fully dynamic is possible, but tricky code to write. But if you don't mind writing a switch block and updating that switch block when there is a new entity type, here's the sample code:

    myapp.BrowseCustomers.AddCustomerCustom_execute = function (screen) {
        var addEditScreenName,
            _EntityType,
            addEditScreenPropertyName;
    
        // Code to figure out addEditScreenName...
    
        switch (addEditScreenName) {
            case "AddEditCustomer":
                _EntityType = myapp.Customer;
                addEditScreenPropertyName = "Customer";
                break;
            case "AddEditOrder":
                _EntityType = myapp.Order;
                addEditScreenPropertyName = "Order";
                break;
            // Add new case statement when
            // need to handle new entity type
            default:
                return;
        }
    
        return myapp.showScreen(addEditScreenName, null, {
            beforeShown: function (addEditScreen) {
                var newEntity = new _EntityType();
                addEditScreen[addEditScreenPropertyName] = newEntity;
            }
        });
    };

    Best regards,
    Huy Nguyen
    Monday, April 8, 2013 8:35 PM

All replies

  • Hi, Kivito

    just like

    myapp.showScreen("AddEdittblview", [screen.tblviews.selectedItem]);

    should work


    Sergey Vdovin

    Sunday, April 7, 2013 9:35 PM
  • hi Sergey!

    unfortunately i didn't get it working.. :(

    i want to pass new object to create depending on screen i call.. i guess i need something like myapp.showScreen("screen_name", ["new_object_for_screen"]);.. but maybe it's not intended to work that way..

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, April 8, 2013 9:34 AM
  • Hi, Kivito!

    Do not give up!

    try out this:

     myapp.showScreen("AddEdittblview", [screen.tblviews.addNew()]);


    Sergey Vdovin

    Monday, April 8, 2013 11:09 AM
  • for different entities you have to use corresponding AddNew() methods of the DataWorkspace

    Sergey Vdovin


    Monday, April 8, 2013 1:45 PM
  • thanks Sergey, i've tried with that but i'm getting popup on same screen to save changes and nothing happens.. like i said, this works for "browse screen" type, but for "add/edit" it is little more of work to do.. must be some other catch..

    Kivito

     

    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, April 8, 2013 3:42 PM
  • search for the error. the code is working (i suggest you can try with a new test project).

    about the dialog - in my application i save the new item before edit like this (and there is no save dialog as a result):

    var newItem = screen.tblviews.addNew();
        myapp.applyChanges().then(function () {
            myapp.showScreen("AddEdittblview", [newItem]);
        });
    actually my real code is more complex as far as i use triggers to calculate different aggregated values (with the instead of triggers for views have not found an appropriate working solution) - so there are different refreshes (thank to Huy again) and other elements but this code i use in a test project and it s working (as well as the previous).



    Sergey Vdovin

    Monday, April 8, 2013 3:55 PM
  • Hi Kivito,

    To Add a new item there's a little bit more code to write. You will need to specify the beforeShown function as an option for the showScreen method. For example:

    myapp.Registrations.CustomAddRegistration_execute = function (screen) {
        myapp.showAddEditRegistration(null, {
            beforeShown: function (addEditScreen) {
                // Create the new entity in the add / edit screen before shown
                // instead of the current screen so that the accept / cancel
                // behavior will work.
                var newRegistration = screen.RegistrationsByUserAndDate.addNew();
                addEditScreen.Registration = newRegistration;
            },
            afterClosed: function () {            
            }
        });
    };
    

    Also there's the optional afterClosed function which can be useful in cerntain scenarios.

    Best regards,
    Huy Nguyen

    • Proposed as answer by ADefwebserver Monday, April 8, 2013 4:29 PM
    Monday, April 8, 2013 4:24 PM
  • i guess it's not working (in my case) cause you already have that "visual collection" on screen, i have only string value of "display_name" in completely unrelated table, which can be passed as parameter for name of the screen to open:

    myapp.showScreen("displayName");

    but i dont have object to pass in, like you in:

    var newItem = screen.tblviews.addNew();

    cause myapp.showScreen("displayName", [myapp.details.dataworkspace.applicationData.myEntity.addNew()]); have issues.. and also i must somehow determine which type of object/entity goes in only by string (like showScreen("addCustomer", "Customers");).. so maybe it's possible, but practical?

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, April 8, 2013 4:26 PM
  • hi Huy, didn't see your answer before.. im asking about dynamically calling screens, i have table which serves as menu, i found that method myapp.showScreen(....) accepts string parameter for screen name, but i dont know how can (or can I) call addEditScreen with showScreen(..) syntax.. so myapp.showScreen("myScreen") works for "browse screens", but not for addEditScreens, my intention is to have something like

    myapp.showScreen("addEditOrder", new order);

    myapp.showScreen("addEditCustomer", new customer);

    is this possible? thanks!

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, April 8, 2013 4:39 PM
  • Hi Kivito,

    It's totally possible. Here's a sample:

    myapp.BrowseCustomers.AddCustomerCustom_execute = function (screen) {
        myapp.showScreen("AddEditCustomer", null, {
            beforeShown: function (addEditScreen) {
                // Create the new entity here so that
                // accept/cancel behavior will work.
                // Otherwise when user cancel, the new
                // entity will not be discarded.
                var newCustomer = new myapp.Customer();
                addEditScreen.Customer = newCustomer;
            }
        });
    };

    Best regards,
    Huy Nguyen

    Monday, April 8, 2013 5:13 PM
  • thanks Huy!

    this works great! just additional question: can calling screen ("addEditScreen" in this case) determine itself or by parameter, which type of object should it create? this is maybe wrong formulated question so if i have (look for comments in code):

    myapp.BrowseCustomers.AddCustomerCustom_execute = function (screen) {
        myapp.showScreen("AddEditCustomer", null, { //what if i call "addEditOrder" screen?
            beforeShown: function (addEditScreen) {
                
                var newCustomer = new myapp.Customer(); //can i make this calls also dynamic
                addEditScreen.Customer = newCustomer;   //to add order in this case?
            }
        });
    };

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, April 8, 2013 8:24 PM
  • Hi Kivito,

    Going fully dynamic is possible, but tricky code to write. But if you don't mind writing a switch block and updating that switch block when there is a new entity type, here's the sample code:

    myapp.BrowseCustomers.AddCustomerCustom_execute = function (screen) {
        var addEditScreenName,
            _EntityType,
            addEditScreenPropertyName;
    
        // Code to figure out addEditScreenName...
    
        switch (addEditScreenName) {
            case "AddEditCustomer":
                _EntityType = myapp.Customer;
                addEditScreenPropertyName = "Customer";
                break;
            case "AddEditOrder":
                _EntityType = myapp.Order;
                addEditScreenPropertyName = "Order";
                break;
            // Add new case statement when
            // need to handle new entity type
            default:
                return;
        }
    
        return myapp.showScreen(addEditScreenName, null, {
            beforeShown: function (addEditScreen) {
                var newEntity = new _EntityType();
                addEditScreen[addEditScreenPropertyName] = newEntity;
            }
        });
    };

    Best regards,
    Huy Nguyen
    Monday, April 8, 2013 8:35 PM
  • what to say except thanks? man, you rock! it works great!

    cheers!

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, April 8, 2013 9:35 PM
  • Hi Kivito,

    I tried your code below and for some reason it is not working for me:
    var selitem = screen.details.properties.HTML_Menus.value.selectedItem.name;
    msls.application.showScreen(selitem);

    Can you please share the complete function you got under the 'tap event'?

    I'm interested in creating a main menu and open the correct screen based on user selection.

    Appreciate your help.

    Thanks,

    CMXUSER

    Monday, July 29, 2013 1:28 AM
  • I used the code above and I'm not getting any errors, However, the add/edit screen doesn't come up?

    any ideas would be most welcomed, thanks

    Monday, September 2, 2013 8:30 PM
  • I figured this out, I had some code in the screen created event, I removed the code and the solution above worked perfectly

    Cheers

    Dominic

    Monday, September 2, 2013 11:45 PM
  • Hello, 

    I'm trying to use the above code, but cannot seem to get a value into "addEditScreenName" no matter what I do... How do I get the clicked screen name to go into this variable?

    Thanks!

    --Jon

    Thursday, January 2, 2014 6:09 PM