/*
 * Author       : mattbclark
 * Generated on : 24-Nov-2009 13:31:12
 * Version      : 3.0
 */
application "Copy of DynamicPicklistExample"
{
    type = public
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section Home
    {
        form  Country
        {
            
            Country
            (
                type  =  text
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Country_View
        {
            displayname = "Country View"
            show  all  rows  from  Country 
            (
                Country
            )
            options
            (
                display rows = 100
            )
        }

        form  CountryAndStates
        {
            
            CountryName
            (
                type  =  picklist
                values  =  Country.Country
                sortorder  =  ascending
            )

            State
            (
                type  =  text
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  CountryAndStates_View
        {
            displayname = "CountryAndStates View"
            show  all  rows  from  CountryAndStates 
            (
                CountryName
                State
            )
            filters 
            (
                CountryName
            )
            options
            (
                display rows = 100
            )
        }

        form  Main
        {
            
            Location
            (
                type  =  picklist
                values  =  Country.Country
                on user input
                {
                    if (input.Location  !=  "-Select-")
                    {
                        for each dat in CountryAndStates  [CountryName == input.Location]
                        {
                            States:ui.add(dat.State);
                        }
                    }
                    else
                    {
                        for each dat1 in CountryAndStates  [ID != 0]
                        {
                            States:ui.add(dat1.State);
                        }
                    }
                }
            )

            States
            (
                type  =  picklist
                values  =  CountryAndStates.State
                sortorder  =  ascending
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Main_View
        {
            displayname = "Main View"
            show  all  rows  from  Main 
            (
                Location
                States
            )
            filters 
            (
                Location
                States
            )
            options
            (
                display rows = 100
            )
        }

    }

}
