<?xml version="1.0" encoding="UTF-8"?>
<process xmlns:blue="http://www.e-marson.com/bluelemon">

  <descriptor>
    <name>com/emarson/lemonade/examples/mobank/moaccount/HistoryDetailsScreen</name>
    <version>1.0</version>
    <description>
      The action which is invoked when a user selects any element from 
      the history list screen.
    </description>
    <vendor>E-MARSON</vendor>
  </descriptor>

  <path>
  
    <!-- ASSOCIATIONS --->
    
    <!-- association to HistoryScreen --->
    <action name="action for 'Back'">
      <type>general/bluelemon/code</type>
      <definition resultTo="goToHistoryScreen">
        <blue:call node="com/emarson/lemonade/examples/mobank/moaccount/HistoryScreen"
                         location="@com/emarson/lemonade/examples/mobank/moaccount"/>

      </definition>
    </action>
    
    <!-- INSTRUCTION --->

    <action name="show the transfer details">
      <type>general/bluelemon/code</type>
      <definition resultTo="screen">

        <!-- get the screen being shown on the screen --->
        <blue:call manager="GeneralManager" method="getCurrent"
                   toVariable="screenWithDates"
                   castTo="com/emarson/lemonade/bluelemon/midp1/List"/>


        <!-- get the index of the currently selected element --->
        <blue:call object="screenWithDates" method="getSelectedIndex"
                   toVariable="selectedIndex"/>

                  
        <!-- get the history dataset from the permanent memory ---> 
        <blue:get node="com/emarson/lemonade/examples/mobank/moaccount/HistoryData" 
                location="permanent" toVariable="historyDataset"/>

                
        <!-- 
          prepare the descriptor which describes this dataset; we will 
          use it more than once, so it's good to keep it as a variable
        --->
        
        <blue:call manager="UtilsManager" method="this"
                   toVariable="historyDatasetDescriptor">

          <blue:argument type="dataset">
            <blue:descriptor>
              <blue:field type="byte"/>
              <blue:field type="byte"/>
              <blue:field type="byte"/>
            </blue:descriptor>
            <blue:row>
              <!-- date --->
              <blue:field value="STRING_TYPE"/>
              <!-- ammount of monety transfered --->
              <blue:field value="INT_TYPE"/>
              <!-- target account number --->
              <blue:field value="STRING_TYPE"/>
            </blue:row>
          </blue:argument>
        </blue:call> 

        <!-- knowing the row, get the first column: date of the transfer... --->
        <blue:call manager="UtilsManager" method="getField"
                   toVariable="date">

          <blue:argument type="variable" name="historyDataset"/>
          <blue:argument type="variable" name="historyDatasetDescriptor"/>
          <blue:argument type="variable" name="selectedIndex"/>
          <blue:argument type="byte" value="0"/>
        </blue:call>
        
        <!-- ... and the second column: ammount of money transferred... --->
        <blue:call manager="UtilsManager" method="getField"
                   toVariable="ammount">

          <blue:argument type="variable" name="historyDataset"/>
          <blue:argument type="variable" name="historyDatasetDescriptor"/>
          <blue:argument type="variable" name="selectedIndex"/>
          <blue:argument type="byte" value="1"/>
        </blue:call>
        
        <!-- ... and the third one: target account number --->
        <blue:call manager="UtilsManager" method="getField"
                   toVariable="accountNo">

          <blue:argument type="variable" name="historyDataset"/>
          <blue:argument type="variable" name="historyDatasetDescriptor"/>
          <blue:argument type="variable" name="selectedIndex"/>
          <blue:argument type="byte" value="2"/>
        </blue:call>
        
        <!-- convert the numeric value of the ammount to String --->
        <blue:call manager="UtilsManager" method="numberToString"
                   toVariable="ammountAsString">

          <blue:argument type="variable" name="ammount"/>
        </blue:call>
        
        <!-- prepare the text to show --->
        <blue:call manager="UtilsManager" method="concat"
                   toVariable="text">

          <blue:argument type="String" value="On "/>
          <blue:argument type="variable" name="date"/>
          <blue:argument type="String" value=" you have transferred "/>
          <blue:argument type="variable" name="ammountAsString"/>
          <blue:argument type="String" value=" EUR to the account "/>
          <blue:argument type="variable" name="accountNo"/>
          <blue:argument type="String" value="."/>
        </blue:call>
        
        <!-- now just create the form to show this text --->
        <blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/Form"
                          toVariable="form"/>


        <blue:call object="form" method="initialize">
          <blue:argument type="String" value="History"/>
        </blue:call>

        <!-- show the text in this form --->        
        <blue:call object="form" method="appendString">
          <blue:argument type="variable" name="text"/>
        </blue:call>
        
        <!-- add an action which will allow to go back to the history screen --->
        <blue:call manager="UtilsManager" method="getActionCommand"
                   toVariable="command">

          <blue:argument type="String" value="Back"/>
          <blue:argument type="byte" value="ActionCommand.BACK"/>
          <blue:argument type="byte" value="0"/>
          <blue:argument type="byteArr" contextKey="goToHistoryScreen"/>
        </blue:call>

        <blue:call object="form" method="addCommand">
          <blue:argument type="variable" name="command"/>
        </blue:call>

        <!-- and show the form on the device --->
        <blue:call manager="GeneralManager" method="setCurrent">
          <blue:argument type="variable" name="form"/>
        </blue:call>

      </definition>
    </action>

    <finish name="done">
      <return>screen</return>
    </finish>

  </path>

</process>