<?xml version="1.0" encoding="UTF-8"?>
<!--
   Copyright 2016 Anyware Services

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
   -->
<!DOCTYPE workflow PUBLIC "-//OpenSymphony Group//DTD OSWorkflow 2.8//EN" "http://www.opensymphony.com/osworkflow/workflow_2_8.dtd">
<workflow>
    <initial-actions>
        <action id="0" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_ACTION_PROPOSE">
            <results>
                <unconditional-result old-status=" " status=" " step="1" />
            </results>
        </action>
    </initial-actions>
    
    <!-- +
         | COMMON ACTIONS
         + -->
    <common-actions>
        <action id="1" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_ACTION_REFUSE">
            <restrict-to>
                <conditions type="AND">
                    <condition type="avalon">
                        <arg name="role">org.ametys.plugins.workflow.component.CheckRightsCondition</arg>
                        <arg name="right">Forms_Default_Workflow_Rights_Refuse</arg>
                    </condition>
                </conditions>
            </restrict-to>
            <results>
                <unconditional-result old-status=" " status=" " step="2" />
            </results>
        </action>
        <action id="2" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_ACTION_ACCEPT">
            <restrict-to>
                <conditions type="AND">
                    <condition type="avalon">
                        <arg name="role">org.ametys.plugins.workflow.component.CheckRightsCondition</arg>
                        <arg name="right">Forms_Default_Workflow_Rights_Accept</arg>
                    </condition>
                </conditions>
            </restrict-to>
            <results>
                <unconditional-result old-status=" " status=" " step="3" />
            </results>
        </action>
        <action id="3" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_ACTION_NEED_COMPLEMENTS">
            <restrict-to>
                <conditions type="AND">
                    <condition type="avalon">
                        <arg name="role">org.ametys.plugins.workflow.component.CheckRightsCondition</arg>
                        <arg name="right">Forms_Default_Workflow_Rights_Further_Information</arg>
                    </condition>
                </conditions>
            </restrict-to>
            <results>
                <unconditional-result old-status=" " status=" " step="4" />
            </results>
            <post-functions>
                 <function type="avalon">
                   <arg name="role">org.ametys.plugins.forms.workflow.SendMailFunction</arg>
               </function>
            </post-functions>
        </action>
        <action id="4" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_ACTION_RESET">
            <restrict-to>
                <conditions type="AND">
                    <condition type="avalon">
                        <arg name="role">org.ametys.plugins.workflow.component.CheckRightsCondition</arg>
                        <arg name="right">Forms_Default_Workflow_Rights_Reset</arg>
                    </condition>
                </conditions>
            </restrict-to>
            <results>
                <unconditional-result old-status=" " status=" " step="1" />
            </results>
        </action>
    </common-actions>
    
    <steps>
        <step id="1" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_STATE_PROPOSED">
            <actions>
                <!-- Refuse Action -->
                <common-action id="1" />
                <!-- Accept Action -->
                <common-action id="2" />
                <!-- Complements request Action -->
                <common-action id="3" />
            </actions>
        </step>
        <step id="2" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_STATE_REFUSED">
            <actions>
                <!-- Reset Action -->
                <common-action id="4" />
            </actions>
        </step>
        <step id="3" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_STATE_ACCEPTED">
            <actions>
                <!-- Reset Action -->
                <common-action id="4" />
            </actions>
        </step>
        <step id="4" name="plugin.default-form-workflow:FORMS_DEFAULT_WORKFLOW_STATE_INCOMPLETE">
            <actions>
                <!-- Refuse Action -->
                <common-action id="1" />
                <!-- Accept Action -->
                <common-action id="2" />
                <!-- Further information request Action -->
                <common-action id="4" />
            </actions>
        </step>
    </steps>
</workflow>
