/*
 * Author       : lozc
 * Generated on : 23-Nov-2009 03:41:03
 * Version      : 3.0
 */
application "Rise and Shine"
{
    type = public
    allow html = true
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section Home
    {
        form  Survey
        {
            
            must  have  wakeup_time
            (
                displayname  =  "What time to you typically rise on a weekday morning?"
                type  =  picklist
                values  =  {"before dawn",   "morning",   "afternoon",   "night"}
                defaultvalue  =  "early morning"
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on success
                        {
                            t  =  Tally  [ID > 0];
                            if (input.wakeup_time  ==  "before dawn")
                            {
                                t.before_dawn = (t.before_dawn  +  1);
                            }
                            else if (input.wakeup_time  ==  "morning")
                            {
                                t.morning = (t.morning  +  1);
                            }
                            else if (input.wakeup_time  ==  "afternoon")
                            {
                                t.afternoon = (t.afternoon  +  1);
                            }
                            else if (input.wakeup_time  ==  "night")
                            {
                                t.night = (t.night  +  1);
                            }
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Tally_View
        {
            displayname = "Tally View"
            show  all  rows  from  Tally 
            (
                before_dawn as "Before Dawn"
                afternoon as "Afternoon"
                night as "Night"
                morning as "Morning"
            )
            options
            (
                display rows = 100
            )
        }

    }

    section "HIDDEN"
    {
        displayname = "___HIDDEN"
        hide = true
        form  Tally
        {
            
            must  have  before_dawn
            (
                displayname  =  "Before Dawn"
                type  =  number
                defaultvalue  =  0
                width  =  20
            )

            must  have  morning
            (
                displayname  =  "Morning"
                type  =  number
                defaultvalue  =  0
                width  =  20
            )

            must  have  afternoon
            (
                displayname  =  "Afternoon"
                type  =  number
                defaultvalue  =  0
                width  =  20
            )

            must  have  night
            (
                displayname  =  "Night"
                type  =  number
                defaultvalue  =  0
                width  =  20
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on validate
                        {
                            if (count(Tally[(ID is not null)])  >  0)
                            {
                                alert "No more than one record is allowed in this form.  Please edit or delete the existing values if you need to reset it.";
                                cancel submit;
                            }
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  Survey_View
        {
            displayname = "Survey View"
            show  all  rows  from  Survey 
            (
                wakeup_time as "What time to you general get out of bed in the morning?"
            )
            filters 
            (
                wakeup_time
            )
            options
            (
                display rows = 100
            )
        }

    }

}
