<?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">

  <secured attributes="ROLE_USER, ROLE_ADMIN"/>

  <on-start>
    <evaluate expression="profileFriendSubscribeAction.init"/>
  </on-start>

  <action-state id="decide">
    <evaluate expression="profileFriendSubscribeAction.decide"/>
    <transition on="done" to="friendAllow"/>
    <transition on="form" to="initMailForm"/>
  </action-state>

  <end-state id="friendAllow" view="externalRedirect:contextRelative:/profile/friendAllow.html?userCode=${flowScope.to.code}"/>

  <action-state id="initMailForm">
    <evaluate expression="profileFriendSubscribeAction.initMailForm"/>
    <transition on="success" to="mailSend"/>
  </action-state>

  <subflow-state id="mailSend" subflow="mail.create-sub-flow">
    <input name="mail" required="true"/>
    <input name="unmodifiableTo" required="true"/>
    <input name="pageTitleCode" required="true"/>
    <input name="pageDescriptionCode" required="true"/>
    <input name="formSubmitCode" required="true"/>
    <input name="statusCode" value="'200'"/>
    <output name="mail" required="true"/>
    <transition on="finish" to="subscribe"/>
  </subflow-state>

  <action-state id="subscribe">
    <evaluate expression="profileFriendSubscribeAction.subscribe"/>
    <transition to="finish"/>
  </action-state>

  <end-state id="finish" view="profile.FriendSubscribeSuccess"/>

</flow>
