
$(document).ready(function()
{$("#procDragTagList").accordion({collapsible:true,autoHeight:false});$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{'processId':"+processId+"}",url:_reposRoot+'/ProcessDefinition.asmx/GetStepHierarchy',success:function(data){loadedSteps(data);}});jQuery.extend(jQuery.expr[":"],{containsNoCase:function(a,i,m){return a.innerHTML.toUpperCase().indexOf((m[3]).toUpperCase())!=-1;}});$('#txtFilter').keypress(function(e){if(e.keyCode==13){$('#btnFilter').click();return false;}});});function filterChanged()
{var filterText=$('#txtFilter').val();$("#procDragTagList li").attr('flt','no');$("#procDragTagList li:not(:containsNoCase('"+filterText+"'))").attr('flt','yes');$("#procDragTagList li[flt='no']").css('display','');$("#procDragTagList li[flt='yes']").css('display','none');$("#procDragTagList h3").css('display','none');var visDiv=$("#procDragTagList div:has(li[flt='no'])");visDiv.each(function(i)
{var pNodes=$(this).prev();var lstHead=pNodes.eq(0);lstHead.css('display','');});$('#procDragTagList').accordion('activate',false);}
function loadedSteps(data)
{$("#processTree").tree({types:{"default":{renameable:false},"root":{draggable:false},"step0":{icon:{image:"../App_Themes/Default/Images/step0.png"}},"step1":{icon:{image:"../App_Themes/Default/Images/stepnoniter.png"}},"step3":{icon:{image:"../App_Themes/Default/Images/stepnoniter.png"}},"step5":{icon:{image:"../App_Themes/Default/Images/stepnoniter.png"}},"step7":{icon:{image:"../App_Themes/Default/Images/stepnoniter.png"}},"step9":{icon:{image:"../App_Themes/Default/Images/stepiter.png"}},"step11":{icon:{image:"../App_Themes/Default/Images/stepiter.png"}},"step13":{icon:{image:"../App_Themes/Default/Images/stepiter.png"}},"step15":{icon:{image:"../App_Themes/Default/Images/stepiter.png"}}},data:{type:"xml_flat",opts:{static:data.d}},ui:{dots:false},callback:{onmove:function(NODE,REF_NODE,TYPE,TREE_OBJ,RB){moveStep(NODE,REF_NODE,TYPE,TREE_OBJ,RB);}},plugins:{contextmenu:{items:{rename:false,create:false,toggleConcurrent:{label:"Toggle concurrent",icon:"",visible:function(NODE,TREE_OBJ){if(NODE.length!=1)return 0;if(TREE_OBJ.get_text(NODE)=="Child node 1")return-1;return 1;},action:function(NODE,TREE_OBJ){toggleType(NODE,TREE_OBJ,2);},separator_before:true},toggleOptional:{label:"Toggle optional",icon:"",visible:function(NODE,TREE_OBJ){if(NODE.length!=1)return 0;if(TREE_OBJ.get_text(NODE)=="Child node 1")return-1;return 1;},action:function(NODE,TREE_OBJ){toggleType(NODE,TREE_OBJ,4);},separator_before:false},toggleIterative:{label:"Toggle iterative",icon:"",visible:function(NODE,TREE_OBJ){if(NODE.length!=1)return 0;if(TREE_OBJ.get_text(NODE)=="Child node 1")return-1;return 1;},action:function(NODE,TREE_OBJ){toggleType(NODE,TREE_OBJ,8);},separator_before:false}}}}});$("#procDragList li").draggable({revert:true,helper:'clone',revertDuration:0,appendTo:'#procDragList'});$("#processTree li a").droppable({drop:function(event,ui){dropProcess(event,ui,this);}});}
function dropProcess(event,ui,dropped)
{var droppedProcessId=ui.draggable.attr('procid');var newNode=$.tree.reference('#processTree').create({attributes:{procid:droppedProcessId,steptype:1,rel:'step1'},data:ui.draggable.text()},dropped,'inside');var ontoProcessId=$(dropped).parent().attr('procid');$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{'processId':"+ontoProcessId+",'childProcessId':"+droppedProcessId+"}",url:_reposRoot+'/ProcessDefinition.asmx/AddChildStep',success:function(data){addedStep(data,newNode);}});$('a',newNode).droppable({drop:function(event,ui){dropProcess(event,ui,this);}});}
function addedStep(data,newNode)
{newNode.attr('stepid',data.d);}
function moveStep(NODE,REF_NODE,TYPE,TREE_OBJ,RB)
{var nd=$(NODE);var ndRef=$(REF_NODE);$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{"+"'movedStepId':"+nd.attr('stepid')+",'movedProcessId':"+nd.attr('procid')+","+"'movePos':'"+TYPE+"',"+"'relativeToStepId':"+ndRef.attr('stepid')+",'relativeToProcessId':"+ndRef.attr('procid')+"}",url:_reposRoot+'/ProcessDefinition.asmx/MoveStep'});}
function toggleType(NODE,TREE_OBJ,toggleVal)
{var curNode=$(NODE);var curType=parseInt(curNode.attr('steptype'));if(curType!=0)
{if((toggleVal&curType)==toggleVal)
curType=curType-toggleVal;else
curType=curType+toggleVal;curNode.attr('steptype',curType);curNode.attr('rel','step'+curType.toString());$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{'stepId':"+curNode.attr('stepid')+",'stepType':"+curType+"}",url:_reposRoot+'/ProcessDefinition.asmx/SetStepType'});}}