﻿//version:1.0
//published by:Microsoft
//company:http://www.microsoft.com
//description:OOB Listen Activity
//assembly:System.Workflow.Activities.dll

function ListenActivity(element) {
	this.element = element
	var innerBar=document.createElement("DIV")
	innerBar.className="bar"
	innerBar.style["width"]=100+"%"
	innerBar.style["heigth"]=28+"px"
	//innerBar.innerHTML = "<p>"+item.id+"</p>"
    innerBar.innerHTML = "<DIV id='"+element.id+"_id' class='idlabel'>"+element.id+"</DIV>"
    element.appendChild(innerBar)
	this.group = Quanticks.drag().createSimpleActivity(element, innerBar)
	this.Branches = new Array()
	this.Properties = new Array()
	this.RegisteredProperties = new Array()
	this.RegisteredProperties[0] = "Name"
	this.RegisteredProperties[1] = "Description"
	this.RegisteredProperties[2] = "Enabled"	
    //composite resize handling
	this.ActWidth = 360
	this.BlockWidth = 160
	this.noResizeFlag = false
	this.noBranchResizeFlag = false	
}

ListenActivity.GetToolboxIcon = function()
{
    return "http://netfxlive.com/images/listen.GIF";
}
    
ListenActivity.prototype = {
    Initialize : function()
    {
	    this.header = document.createElement("img")
	    this.header.src = "http://netfxlive.com/images/parahead.GIF"
	    this.header.setAttribute("width", "268");
	    this.header.setAttribute("height", "15");	    
	    this.element.appendChild(this.header)
	    this.table = document.createElement("table")
	    this.tablebody = document.createElement("tbody")
	    this.tablerow = document.createElement("tr")
        this.tablebody.appendChild(this.tablerow)
        this.table.appendChild(this.tablebody)
        this.element.appendChild(this.table)
	    this.table.setAttribute("border", "0");
        this.addBranch()
        this.addBranch()
        this.footer = document.createElement("img")
	    this.footer.src = "http://netfxlive.com/images/parafoot.GIF"
	    this.footer.setAttribute("width", "268");
	    this.footer.setAttribute("height", "15");	    
	    this.element.appendChild(this.footer)        
    },
    
	addBranch : function() {
        var cell = document.createElement("td");
		var branch=document.createElement("DIV")	
		branch.className="SequenceActivity"
		var branchConnector=document.createElement("DIV")
	    branchConnector.className="connector"
	    var innerImg=document.createElement("IMG")
	    innerImg.src="http://netfxlive.com/images/connector.gif"
        branchConnector.appendChild(innerImg)
	    connectors[connectors.length] = branchConnector
	    branch.appendChild(branchConnector)
	    cell.appendChild(branch)
	    this.tablerow.appendChild(cell);
	    cell.setAttribute("vAlign","top")
	    branch.onresize=BranchResize
	    branch.name = getNewId("EventDrivenActivity");       
  	    this.Branches[this.Branches.length] = branch;
	    return branch;  	    
	},

	removeBranch : function(branchToRemove) {
	},
	
    Serialize : function()
    {
        var activityFactory = Quanticks.activityFactory()
        var result = "";
        result += "<ListenActivity "
        for (var propi = 0;propi<this.RegisteredProperties.length;propi++)
        {
            if (this.RegisteredProperties[propi]=="Name")
                result += "x:";
            if (typeof this.Properties[this.RegisteredProperties[propi]] != "undefined" && this.Properties[this.RegisteredProperties[propi]]!="")
                result += this.RegisteredProperties[propi]+"=\""+this.Properties[this.RegisteredProperties[propi]]+"\" ";
        }
        result += ">\n"           
        for(var br=0;br<this.Branches.length;br++)
        {
            var branch = this.Branches[br]
            result += "<EventDrivenActivity x:Name=\""+branch.name+"\">\n"
            for(var ch=0;ch<branch.children.length;ch++)
            {
                var childActivity = activityFactory.getActivity(branch.children[ch])
                if (childActivity!=null)
                {
                    result += childActivity.Serialize()
                }
            }
            result += "</EventDrivenActivity>\n"
        }            
        result += "</ListenActivity>\n"
        return result
    },
    Deserialize: function(node,connector)
    {
	    this.header = document.createElement("img")
	    this.header.src = "http://netfxlive.com/images/parahead.GIF"
	    this.header.setAttribute("width", "268");
	    this.header.setAttribute("height", "15");
	    this.element.appendChild(this.header)
	    this.table = document.createElement("table")
	    this.tablebody = document.createElement("tbody")
	    this.tablerow = document.createElement("tr")
        this.tablebody.appendChild(this.tablerow)
        this.table.appendChild(this.tablebody)
        this.element.appendChild(this.table)
	    this.table.setAttribute("border", "0");
        
        for(var aa=0;aa<node.childNodes.length; aa++)
        {
            var newBranch = this.addBranch()
            for(var ab=node.childNodes[aa].childNodes.length-1; ab>=0; ab--)
            {
                addNode(node.childNodes[aa].childNodes[ab],newBranch); 
            }           
        }         
        this.footer = document.createElement("img")
	    this.footer.src = "http://netfxlive.com/images/parafoot.GIF"
	    this.footer.setAttribute("width", "268");
	    this.footer.setAttribute("height", "15");
	    this.element.appendChild(this.footer) 	          
    }    		
}


