<?xml version="1.0" encoding="UTF-8"?>
<flow
    xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow
                        http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
    parent="common-transitions, addManagedDomain"
    abstract="true">

    <input
        name="itemType"
        value="flowScope.itemType"
        type="gov.va.med.pharmacy.peps.common.vo.EntityType" />

    <input
        name="item"
        value="flowScope.item"
        type="gov.va.med.pharmacy.peps.common.vo.ManagedItemVo" />

    <subflow-state
        id="savePartial"
        subflow="savePartial">
        <on-entry>
            <!-- Make sure that any input from the fields on the page get saved before we move on to the savePartial flow. -->
            <evaluate expression="springWebFlowActionAdapter">
                <attribute
                    name="actionName"
                    value="managedItem" />
                <attribute
                    name="actionMethod"
                    value="input" />
            </evaluate>
        </on-entry>
        <input
            name="itemId"
            value="flowScope.itemId"
            type="string" />
        <input
            name="itemType"
            value="flowScope.itemType"
            type="gov.va.med.pharmacy.peps.common.vo.EntityType" />
        <input
            name="item"
            value="flowScope.item"
            type="gov.va.med.pharmacy.peps.common.vo.ManagedItemVo" />
        <transition
            on="end"
            to="end" />
        <transition
            on="cancel"
            to="${flowScope.previousViewState}" />
    </subflow-state>

    <subflow-state
        id="selectParent"
        subflow="selectParent">
        <on-entry>
            <!-- Make sure that any input from the fields on the page get saved before we move on to the selectParent flow. -->
            <evaluate expression="springWebFlowActionAdapter">
                <attribute
                    name="actionName"
                    value="managedItem" />
                <attribute
                    name="actionMethod"
                    value="input" />
            </evaluate>
        </on-entry>
        <input
            name="item"
            value="flowScope.item"
            type="gov.va.med.pharmacy.peps.common.vo.ManagedItemVo" />
        <transition
            on="end"
            to="${flowScope.previousViewState}">
            <set
                name="flowScope.item"
                value="currentEvent.attributes.item" />
        </transition>
    </subflow-state>

    <action-state id="submitAdd">
        <evaluate expression="springWebFlowActionAdapter">
            <attribute
                name="actionName"
                value="managedItem" />
            <attribute
                name="actionMethod"
                value="submitAdd" />
        </evaluate>
        <transition
            on="success"
            to="end" />
        <transition
            on="warn"
            to="warning" />
    </action-state>

    <view-state
        id="warning"
        view="confirm.modifications">
        <on-render>
            <evaluate expression="springWebFlowActionAdapter">
                <attribute
                    name="actionName"
                    value="managedItem" />
                <attribute
                    name="actionMethod"
                    value="render" />
            </evaluate>
<!--             <evaluate expression="managedItemCommand.render()"></evaluate> -->
        </on-render>
        <transition
            on="ok"
            to="end" />
    </view-state>
    <end-state id="cancel" />

    <end-state id="end">
        <output
            name="item"
            value="flowScope.item"
            type="gov.va.med.pharmacy.peps.common.vo.ManagedItemVo" />
        <output
            name="itemId"
            value="flowScope.itemId"
            type="string" />
        <output
            name="itemType"
            value="flowScope.itemType"
            type="gov.va.med.pharmacy.peps.common.vo.EntityType" />
    </end-state>

    <global-transitions>
        <transition
            on="cancel"
            to="cancel" />
        <transition
            on="previous"
            to="${flowScope.previousViewState}" />
        <transition
            on="proposedAdd"
            to="end" />
        <transition
            on="savePartial"
            to="savePartial" />
        <transition
            on="selectParent"
            to="selectParent" />
        <transition
            on="submit"
            to="submitAdd" />
    </global-transitions>
</flow>