<taskModel about="urn:cetask.wpi.edu:examples:Library" xmlns="http://ce.org/cea-2018">
  <!-- This is exercise done in CS 525U class, adapted from
       Chapter 10 of Interactive Design by Preece, Rogers & Sharp.
       See Library.pdf for graphical presentations of this model. -->

  <task id="CheckEmail">
    <input name="email" type="Email"/>

    <subtasks id="checking">
      <step name="read" task="ReadEmail"/>
      <step name="deal" task="DealWithEmail"/>
      <binding slot="$this.email" value="$read.email"/>
      <binding slot="$deal.email" value="$read.email"/>
    </subtasks>
  </task>
  
  <task id="ReadEmail">
  	<input name="email" type="Email"/>
  	
  	<subtasks id="reading">
      <step name="select" task="SelectEmail"/>
      <step name="open" task="OpenEmail"/>
      <binding slot="$this.email" value="$select.email"/>
      <binding slot="$open.email" value="$select.email"/>
      
    </subtasks>
  </task>
  
  <task id="SelectEmail">
  	<input name="email" type="Email"/>
  </task>
  
  <task id="OpenEmail">
  	<input name="email" type="Email"/>
  	<script>
        importClass(Packages.edu.wpi.cetask.guide.ICEInterface);
        ICEInterface.getICEInterface().openEmail();  // calling static java method directly
    </script>
  </task>
  
  <task id="DealWithEmail">
  	<input name="email" type="Email"/>
  	
  	<subtasks id="acting">
      <step name="act" task="ActOnEmail"/>
      <step name="finish" task="FinishWithEmail"/>
      <binding slot="$act.email" value="$this.email"/>
      <binding slot="$finish.email" value="$this.email"/>
    </subtasks>
    
    <subtasks id="finishing">
      <step name="finish" task="FinishWithEmail"/>
      <binding slot="$finish.email" value="$this.email"/>
    </subtasks>
    
  </task>
    
  <task id="ActOnEmail">
  	<input name="email" type="Email"/>
  	
  	<subtasks id="replying">
  	  <step name="reply" task="CreateReply"/>
      <step name="send" task="SendEmail"/>
      <binding slot="$reply.email" value="$this.email"/>
    </subtasks>
    
    <subtasks id="forwarding">
      <step name="forward" task="CreateForward"/>
      <step name="send" task="SendEmail"/>
      <binding slot="$forward.email" value="$this.email"/>
    </subtasks>
    
  </task>
  
  <task id="FinishWithEmail">
  	<input name="email" type="Email"/>
  	
  	<subtasks id="closing">
      <step name="close" task="CloseEmail"/>
      <binding slot="$close.email" value="$this.email"/>
    </subtasks>
    
    <subtasks id="deleting">
      <step name="delete" task="DeleteEmail"/>
      <binding slot="$delete.email" value="$this.email"/>
    </subtasks>
    
  </task>
  
  <task id="CreateReply">
  	<input name="email" type="Email"/>
  	<script> 
  		importClass(Packages.edu.wpi.cetask.guide.ICEInterface);
        ICEInterface.getICEInterface().replyEmail();  //create email
   	</script>
  </task>
  
  <task id="CreateForward">
  	<input name="email" type="Email"/>
  	<script> 
  		importClass(Packages.edu.wpi.cetask.guide.ICEInterface);
        ICEInterface.getICEInterface().forwardEmail();  //create forward
   	</script>
  </task>
  
  <task id="DeleteEmail">
  	<input name="email" type="Email"/>
  	<script> 
  		importClass(Packages.edu.wpi.cetask.guide.ICEInterface);
        ICEInterface.getICEInterface().deleteEmail();  //delete email
   	</script>
  </task>
  
  <task id="CloseEmail">
  	<input name="email" type="Email"/>
  	<script> 
  		importClass(Packages.edu.wpi.cetask.guide.ICEInterface);
        ICEInterface.getICEInterface().closeEmail();  //close email
   	</script>
  </task>
  
  <task id="WriteEmail">
    <!-- <input name="email" type="Email"/> -->

    <subtasks id="writing">
      <step name="create" task="CreateEmail"/>
      <step name="send" task="SendEmail"/>
    </subtasks>
  </task>
  
  <task id="CreateEmail">
  	<!-- <input name="email" type="Email"/> -->
  	<script> 
  		importClass(Packages.edu.wpi.cetask.guide.ICEInterface);
        ICEInterface.getICEInterface().newEmail();  //create new email
   	</script>
  </task>
  
  <task id="SendEmail">
  	<!--<input name="recipient" type="string"/>
  	<input name="subject" type="string"/>
  	<input name="message" type="string"/>-->
  	
  	<!-- subtasks id="fillInFields"  ordered="false">
  	
      <step name="recipient" task="FillInRecipient"/>
      <step name="subject" task="FillInSubject"/>
      <step name="message" task="FillInMessage"/>
      <binding slot="$recipient.recipient" value="$this.recipient"/>
      <binding slot="$subject.subject" value="$this.user"/>
      <binding slot="$message.message" value="$this.message"/>
      
    </subtasks-->
    
  	<script> 
  		importClass(Packages.edu.wpi.cetask.guide.ICEInterface);
        ICEInterface.getICEInterface().sendEmail();  //send new email
   	</script>
  </task>
  
  <!--task id="FillInRecipient">
  	<input name="recipient" type="string"/>
  </task>
  
  <task id="FillInSubject">
  	<input name="subject" type="string"/>
  </task>
  
  <task id="FillInMessage">
  	<input name="message" type="string"/>
  </task>-->

  <script init="true">
	
	// define Email class
 
    function Email (emailID) {
       this.emailID = emailID;
    }
    
    function User (username, password) {
       this.username = username;
       this.password = password;
    }
	
	Email.prototype.toString = function () { return this.emailID; }
	
	User.prototype.toString = function () { return this.username; }

  </script>

</taskModel>