<taskModel about="urn:cetask.wpi.edu:examples:eBay" xmlns="http://ce.org/cea-2018">
  <!-- This is the task model for EZ Listing Page. -->

  <task id="CreateListingPage">
    <subtasks id="creating" ordered="false">
      <step name="add" task="AddArt"/>
      <step name="format" task="FormatPage" minOccurs="0"/>
    </subtasks>
  </task>

  <task id="AddArt">
    <subtasks id="art" ordered="false">
      <step name="server" task="AddServer" minOccurs="1"/>
      <step name="main" task="AddMainPicture" minOccurs="1" requires="server"/>
      <step name="alternate" task="AddAlternatePicture" minOccurs="0" maxOccurs="3" requires="server"/>
      <step name="describe" task="DescribeArt" minOccurs="1"/>
      <step name="give" task="GiveDetails" minOccurs="1"/>
    </subtasks>
  </task>

  <task id="AddServer">
    <!-- succeeds if default_picture_server has been overridden -->
    <postcondition sufficient="true"> default_picture_server.overridden(); </postcondition>

    <subtasks id="server" ordered="false">
      <step name="name" task="GiveServerName"/>
      <step name="user" task="GiveServerUser"/>
      <step name="pass" task="GiveServerPass"/>
      <step name="dir" task="GiveServerDir"/>
    </subtasks>
  </task>

  <task id="GiveServerName">
    <input name="name" type="string"/>

    <!-- succeeds if name has been specified -->
    <postcondition> $this.name != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> default_picture_server.setName($this.name); </script>
  </task>
  
  <task id="GiveServerUser">
    <input name="user" type="string"/>

    <!-- succeeds if user has been specified -->
    <postcondition> $this.user != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> default_picture_server.setUser($this.user); </script>
  </task>
  
  <task id="GiveServerPass">
    <input name="pass" type="string"/>

    <!-- succeeds if pass has been specified -->
    <postcondition> $this.pass != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> default_picture_server.setPass($this.pass); </script>
  </task>
  
  <task id="GiveServerDir">
    <input name="dir" type="string"/>

    <!-- succeeds if dir has been specified -->
    <postcondition> $this.dir != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> default_picture_server.setDir($this.dir); </script>
  </task>

  <!-- The main picture may be split up into one or more images. -->

  <task id="AddMainPicture">
    <subtasks id="picture">
      <step name="image" task="AddImage" minOccurs="1" maxOccurs="7"/>
      <step name="orient" task="OrientPicture" minOccurs="0"/>
    </subtasks>
  </task>

  <!-- There may be 0 or more alternate pictures. -->

  <task id="AddAlternatePicture">
    <subtasks id="picture">
      <step name="image" task="AddImage" minOccurs="1" maxOccurs="7"/>
      <step name="orient" task="OrientPicture" minOccurs="0"/>
    </subtasks>
  </task>
  
  <task id="AddImage">
    <subtasks id="image">
      <step name="choose" task="ChooseImageFile"/>
      <step name="describe" task="DescribeImage" minOccurs="0"/>
    </subtasks>
  </task>
  
  <task id="ChooseImageFile">
    <input name="image" type="Image"/>

    <!-- succeeds if image has been specified -->
    <postcondition> $this.image != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_image[0].setImage($this.image); </script>
  </task>
  
  <task id="DescribeImage">
    <input name="description" type="string"/>
    
    <!-- proceeds if description has been specified -->
    <postcondition> $this.description != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_image[0].setAlt($this.description); </script>
  </task>
  
  <task id="OrientPicture">
    <subtasks id="orientation" ordered="false">
      <step name="direction" task="GiveDirection"/>
      <step name="spacing" task="GiveSpacing" minOccurs="0"/>
    </subtasks>
  </task>
  
  <task id="GiveDirection">
    <input name="direction" type="string"/>

    <!-- succeeds if direction has been specified -->
    <postcondition> $this.direction != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_orientation.setDirection($this.direction); </script>
  </task>
  
  <task id="GiveSpacing">
    <input name="spacing" type="number"/>

    <!-- succeeds if spacing has been specified -->
    <postcondition> $this.spacing != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_orientation.setSpacing($this.spacing); </script>
  </task>
  
  <task id="DescribeArt">
    <input name="description" type="Description"/>
    
    <!-- succeeds if description has been specified -->
    <postcondition> $this.description != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_description.setDescription($this.description); </script>
  </task>

  <task id="GiveDetails">
    <subtasks id="detail" ordered="false">
      <step name="artist" task="GiveArtistName"/>
      <step name="title" task="GiveArtTitle"/>
      <step name="style" task="GiveArtStyle"/>
      <step name="date" task="GiveArtCreatedDate"/>
      <step name="size" task="GiveArtSize"/>
      <step name="medium" task="GiveArtMedium"/>
    </subtasks>
  </task>
  
  <task id="GiveArtistName">
		<input name="artist" type="string"/>
		
    <!-- succeeds if artist has been specified -->
    <postcondition> $this.artist != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_details.setArtist($this.artist); </script>
  </task>
  
  <task id="GiveArtTitle">
		<input name="title" type="string"/>
		
    <!-- succeeds if title has been specified -->
    <postcondition> $this.title != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_details.setTitle($this.title); </script>
  </task>
  
  <task id="GiveArtStyle">
		<input name="style" type="string"/>
		
    <!-- succeeds if style has been specified -->
    <postcondition> $this.style != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_details.setStyle($this.style); </script>
  </task>
  
  <task id="GiveArtCreatedDate">
		<input name="date" type="string"/>
		
    <!-- succeeds if date has been specified -->
    <postcondition> $this.date != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_details.setDate($this.date); </script>
  </task>
  
  <task id="GiveArtSize">
		<input name="size" type="string"/>
		
    <!-- succeeds if size has been specified -->
    <postcondition> $this.size != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_details.setSize($this.size); </script>
  </task>
  
  <task id="GiveArtMedium">
		<input name="medium" type="string"/>
		
    <!-- succeeds if medium has been specified -->
    <postcondition> $this.medium != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> art_details.setMedium($this.medium); </script>
  </task>
  
  <task id="FormatPage">
    <subtasks id="format" ordered="false">
      <step name="background" task="SelectBackgroundColor" minOccurs="0" maxOccurs="1"/>
      <step name="text" task="SelectTextColor" minOccurs="0" maxOccurs="1"/>
    </subtasks>
    
    <subtasks id="css">
      <step name="select" task="SelectCSS"/>
      <!-- only applicable if format subtasks failed -->
      <applicable> $this.success == false </applicable>
    </subtasks>
  </task>

  <task id="SelectCSS">
		<input name="css" type="CSS"/>
		
    <!-- succeeds if css has been specified -->
    <postcondition> $this.css != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> cascading_style_sheet.setCSS($this.css); </script>
  </task>

  <task id="SelectBackgroundColor">
		<input name="backgroundColor" type="string"/>
		
    <!-- succeeds if backgroundColor has been specified -->
    <postcondition> $this.backgroundColor != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> background_color.setValue($this.backgroundColor); </script>
  </task>
  
  <task id="SelectTextColor">
		<input name="textColor" type="string"/>

    <!-- succeeds if textColor has been specified -->
    <postcondition> $this.textColor != undefined </postcondition>
    <!-- grounding script so system can execute this task -->
    <script> text_color.setValue($this.textColor); </script>
  </task>

  <script init="true">

    // define the Server class
    
    function Server(name, user, pass, dir)
    {
       // initialize the member variables for this instance
       this.name = name; // DNS or IP
       this.user = user;
       this.pass = pass;
       this.dir = dir;
       
       this.mask = 0000;
      
       // initialize the member function references 
       // for the class prototype
       if (typeof(_server_prototype_called) == 'undefined')
       {
          _server_prototype_called = true;
          Server.prototype.setName = setName;
          Server.prototype.setUser = setUser;
          Server.prototype.setPass = setPass;
          Server.prototype.setDir = setDir;
          Server.prototype.overridden = overridden;
          Server.prototype.toString = toString;
       }
      
       // define a Server's methods
       function setName(name)
       {
          this.name = name;
          this.mask += 1;
       }
       
       function setUser(user)
       {
          this.user = user;
          this.mask += 10;
       }
       
       function setPass(pass)
       {
          this.pass = pass;
          this.mask += 100;
       }
       
       function setDir(dir)
       {
          this.dir = dir;
          this.mask += 1000;
       }
       
       function overridden()
       {
          if (this.mask == 1111)
          {
             return true;
          }
          return false;
       }

       function toString()
       {
          return this.name;
       }
    }

    // define the Image class

    function Image(alt_tag)
    {
       // initialize the member variables for this instance
       this.image = null;
       this.alt_tag = alt_tag;
      
       // initialize the member function references 
       // for the class prototype
       if (typeof(_image_prototype_called) == 'undefined')
       {
          _image_prototype_called = true;
          Image.prototype.setImage = setImage;
          Image.prototype.setAlt = setAlt;
          Image.prototype.toString = toString;
       }
      
       // define an Image's methods
       function setImage(image)
       {
          this.image = image;
       }

       function setAlt(alt_tag)
       {
          this.alt_tag = alt_tag;
       }
      
       function toString()
       {
          return this.alt_tag;
       }
    }

    // define the Description class
 
    function Description (text)
    {
       // initialize the member variables for this instance
       this.text = text;
       
       // initialize the member function references 
       // for the class prototype
       if (typeof(_description_prototype_called) == 'undefined')
       {
          _description_prototype_called = true;
          Description.prototype.setDescription = setDescription;
          Description.prototype.toString = toString;
       }
      
       // define a Description's methods
       function setDescription(text)
       {
          this.text = text;
       }
      
       function toString()
       {
          return this.text;
       }
    }
    
    // define the Orientation class
 
    function Orientation (direction, spacing) {
       // initialize the member variables for this instance
       this.direction = direction;
       this.spacing = spacing;
       
       // initialize the member function references 
       // for the class prototype
       if (typeof(_orientation_prototype_called) == 'undefined')
       {
          _orientation_prototype_called = true;
          Orientation.prototype.setDirection = setDirection;
          Orientation.prototype.setSpacing = setSpacing;
          Orientation.prototype.toString = toString;
       }
      
       // define an Orientation's methods
       function setDirection(direction)
       {
          this.direction = direction;
       }
       
       function setSpacing(spacing)
       {
          this.spacing = spacing;
       }
      
       function toString()
       {
          return this.direction + this.spacing;
       }
    }
    
    // define the CSS class
 
    function CSS (CSS) {
       // initialize the member variables for this instance
       this.CSS = CSS;
       
       // initialize the member function references 
       // for the class prototype
       if (typeof(_css_prototype_called) == 'undefined')
       {
          _css_prototype_called = true;
          Orientation.prototype.setCSS = setCSS;
          Orientation.prototype.toString = toString;
       }
      
       // define a CSS's methods
       function setCSS(direction)
       {
          this.direction = direction;
       }
      
       function toString()
       {
          return this.CSS;
       }
    }
    
    // define the Details class
    
    function Details(artist, title, style, date, size, medium)
    {
       // initialize the member variables for this instance
       this.artist = artist;
       this.title = title;
       this.style = style;
       this.date = date;
       this.size = size;
       this.medium = medium;
      
       // initialize the member function references 
       // for the class prototype
       if (typeof(_image_prototype_called) == 'undefined')
       {
          _image_prototype_called = true;
          Details.prototype.setArtist = setArtist;
          Details.prototype.setTitle = setTitle;
          Details.prototype.setStyle = setStyle;
          Details.prototype.setDate = setDate;
          Details.prototype.setSize = setSize;
          Details.prototype.setMedium = setMedium;
          Details.prototype.toString = toString;
       }
      
       // define a Details's methods
       function setArtist(artist)
       {
          this.artist = artist;
       }
       
       function setTitle(title)
       {
          this.title = title;
       }
       
       function setStyle(style)
       {
          this.style = style;
       }
       
       function setDate(date)
       {
          this.date = date;
       }
       
       function setSize(size)
       {
          this.size = size;
       }
       
       function setMedium(medium)
       {
          this.medium = medium;
       }
      
       function toString()
       {
          return this.artist + this.title + this.style + this.date + this.size + this.medium;
       }
    }
    
    // define the Color class
    
    function Color(name, value)
    {
       // initialize the member variables for this instance
       this.name = name;
       this.value = value;
      
       // initialize the member function references 
       // for the class prototype
       if (typeof(_color_prototype_called) == 'undefined')
       {
          _color_prototype_called = true;
          Color.prototype.toString = setColor;
          Color.prototype.toString = setName;
          Color.prototype.toString = setValue;
          Color.prototype.toString = toString;
       }

       // define a Color's methods
       function setColor(name, value)
       {
          this.name = name;
          this.value = value;
       }
       
       function setName(name)
       {
          this.name = name;
       }

       function setValue(value)
       {
          this.value = value;
       }

       function toString()
       {
          if (this.name == 'undefined')
          {
             return "undefined";
          }
          else
          {
             return this.name;
          }
       }
    }

    // model of the domain
    
    var default_picture_server = new Server("ccc.wpi.edu", "dobosz", "secret", "/");
    
    var main_picture_orientation = new Orientation("LeftToRight", 10);

    var art_image1 = new Image("An image"),
        art_image2 = new Image("An image"),
        art_image3 = new Image("An image"),
        art_image4 = new Image("An image"),
        art_image5 = new Image("An image"),
        art_image6 = new Image("An image"),
        art_image7 = new Image("An image");

    /*var art_images = [
        { art_image1 },
        { art_image2 },
        { art_image3 },
        { art_image4 },
        { art_image5 },
        { art_image6 },
        { art_image7 } ];*/
    
    var art_description = new Description("This is an original painting created and signed by the artist Magdalena Dobosz in February of 2008. The painting was created using high quality materials and is protected by varnish. It continues around the staple-free edges (staples are on the back), and it is ready to hang. The painting is one of a kind and comes with a signed certificate of authenticity.");
    
    var art_details = new Details("Magdalena Dobosz", "Hovering Hummingbirds #2", "Fresco", "February of 2008", "15 x 30 Inches", "Acrylic");
    
    var background_color = new Color("black", "000000");
    
    var text_color = new Color("white", "FFFFFF");

  </script>

</taskModel>
