
var isDirty=false;var isSaving=false;var msg='You haven\'t saved your changes. Click OK to continue without saving or Cancel to go back and save your changes.';$(document).ready(function(){jQuery.extend(jQuery.expr[":"],{containsNoCase:function(a,i,m){return a.innerHTML.toUpperCase().indexOf((m[3]).toUpperCase())!=-1;}});jQuery.extend(jQuery.expr[":"],{matchesNoCase:function(a,i,m){return a.innerHTML.toUpperCase()==(m[3]).toUpperCase();}});$(':input').change(function(){isDirty=true;});$('textarea').keyup(function(){isDirty=true;});$('.stcheck').click(function(){$(this).toggleClass('stchecked');filterChanged();});window.onbeforeunload=function(){if(!isSaving&&(isDirty||tinyMCE.get('ctl00_ctl00_ContentBody_ContentMain_hBody_hBody_ed').isDirty()||tinyMCE.get('ctl00_ctl00_ContentBody_ContentMain_htmlDesc_htmlDesc_ed').isDirty())){return msg;}};$('.bpmnLoading').show();$('#steps').hide();$("#tabs").tabs({show:function(ev,ui){onShowProcessTab(ev,ui);}});$("#stepDialog").dialog({autoOpen:false,modal:true,resizable:false,width:620});$('#stepDialog').dialog('option','buttons',{"Cancel":function(){$(this).dialog("close");chart.diagram.clearSymbolSelection();currentlyEditting=null;},"OK":onEdittedStep});$('#txtFilter').keypress(function(e){if(e.keyCode==13){$('#btnFilter').click();return false;}});$("#procDragTagList").accordion({collapsible:true,autoHeight:false,active:-1});$("#procDragList li").draggable({revert:true,helper:'clone',revertDuration:0,appendTo:'#procDragList',start:function(event,ui){startDragging();},stop:function(event,ui){stopDragging();},drag:function(event,ui){symbolDrag($(this),event,ui);}});$("#processPlaceholder").draggable({revert:true,handle:'#addPlaceholder',revertDuration:0,appendTo:'#procDragList',start:function(event,ui){startPlaceholderDragging(ui);startDragging();},stop:function(event,ui){stopPlaceholderDragging(ui);stopDragging();},drag:function(event,ui){symbolDrag($(this),event,ui);}});$("#addParallelGateway").draggable({revert:true,helper:'clone',revertDuration:0,appendTo:'#procDragList',start:function(event,ui){startDragging();},stop:function(event,ui){stopDragging();},drag:function(event,ui){symbolDrag($(this),event,ui);}});$("#addInclusiveGateway").draggable({revert:true,helper:'clone',revertDuration:0,appendTo:'#procDragList',start:function(event,ui){startDragging();},stop:function(event,ui){stopDragging();},drag:function(event,ui){symbolDrag($(this),event,ui);}});$("#addTag").click(addTagClick);$('#newTag #newTagName').blur(addedTag);$('#newTag #newTagName').keypress(function(e){if(e.keyCode==13){addedTag();return false;}});$('.assignTags input').click(function(){$(this).parent().toggleClass("checkedTag");});if(isDirectMode!=undefined&&isDirectMode==0){$('#postEditDescToggle').click(toggleEditDesc);addLinkProperties('.postEditor');$("#dlgLinkProperties").dialog({autoOpen:false,modal:true,resizable:false,width:800,minHeight:500});$('#dlgLinkProperties').dialog('option','buttons',{"Close":onOKLinkProperties});$('#ifLinkProperties').load(function(){var frameDoc=this.contentWindow?this.contentWindow.document:this.contentDocument?this.contentDocument:this.document;$(this).height($("body",frameDoc).height());});$('.templateSections h2').contents().wrap("<a href='#'></a>");$('.templateSections h2').each(function(){var h2=$(this).attr('data-hasContent','true');var elesUntilH2=$(this).nextUntil('h2');if($(elesUntilH2).length>0)
$(elesUntilH2).wrapAll("<div class='section'><div class='content'></div></div>");else
$(this).after("<div class='section'><div class='content'><p></p></div></div>");addHeadingDataClasses($(this));});$('.templateSections .section').prepend("<span class='editBar'><span title='Edit section' class='edit blueIcon ui-icon ui-icon-pencil'></span><span class='delete blueIcon ui-icon ui-icon-close' title='Delete section'></span></span>");$('.templateSections h2').each(function(){$(this).nextUntil('h2').andSelf().wrapAll("<div></div>");});var currentInsertPosition=$('.templateSections > div:first');$('#templateHtml h2').each(function(index){var templateHeading=$(this).text().trim();var selectorHeading=".templateSections > div > h2:contains('"+templateHeading+"')";if($(selectorHeading).length>0){var currentHeading=$(selectorHeading);currentHeading.attr('data-direction',$(this).attr('data-direction'));currentHeading.attr('data-multiplicity',$(this).attr('data-multiplicity'));currentHeading.attr('data-linktypeid',$(this).attr('data-linktypeid'));currentHeading.attr('data-linktypename',$(this).attr('data-linktypename'));addHeadingDataClasses(currentHeading);currentInsertPosition=$(selectorHeading).parent('div');currentInsertPosition.find('.section .content').prepend('<blockquote class=\'tutorialText\'>'+$(this).nextUntil('h2','blockquote:first').text()+'</blockquote>');}
else{var newItem=[{sectionName:templateHeading,tutorialText:$(this).nextUntil('h2','blockquote:first').text(),direction:$(this).attr('data-direction'),multiplicity:$(this).attr('data-multiplicity'),linktypeid:$(this).attr('data-linktypeid'),linktypename:$(this).attr('data-linktypename'),sectionContent:$(this).nextUntil('h2','*:not(blockquote:first)').html()}];var secToAdd=$("#sectionTemplate").tmpl(newItem);if(index==0){if(currentInsertPosition.length==0)
secToAdd.appendTo('.templateSections');else
secToAdd.insertBefore(currentInsertPosition);}
else
secToAdd.insertAfter(currentInsertPosition);addHeadingDataClasses(secToAdd.children('h2').addClass('emptySection'));currentInsertPosition=$(".templateSections > div > h2:contains('"+templateHeading+"')").parent('div');}});$('.templateSections h2').each(function(){$("<i title='Edit section' class='edit ui-icon-pencil headerEditor'></i>").appendTo($(this));});$('h2.dd_head i.edit').live('click',function(ev){var thisH2=$(this).closest('h2');$('.section .edit',thisH2.parent()).click();});$(".templateSections").accordion({header:"> div > h2",active:false,collapsible:true,autoHeight:false,ignoreClass:'edit'}).sortable({axis:"y",handle:"h2"});$(".templateSections > div > h2").bind('click.accordion',function(){var k=0;});$(".templateSections div .section .editBar .edit").live('click',function(){editingSection=$(this).closest(':data(sortable-item)');editingSection.find('.pdGenerated').remove();$('#sectionName').text(editingSection.find('h2 > a').text());var h2=editingSection.find('h2');_linktypename=h2.attr('data-linktypename');_linktypeid=h2.attr('data-linktypeid');var editor=tinyMCE.get('ctl00_ctl00_ContentBody_ContentMain_htmlSectionEdit_htmlSectionEdit_ed');var htmlContent=editingSection.find('div.section > div.content > *:not(blockquote.tutorialText)').outerHTML();editor.setContent(htmlContent);var mpeId="ctl00_ctl00_ContentBody_ContentMain_btn_test_ModalPopupExtender";$find(mpeId).show();});$(".templateSections div .section .editBar .delete").live('click',function(){var parent=$(this).closest(':data(sortable-item)');var head=parent.find('h2');parent.find('div.section > div.content > *:not(blockquote.tutorialText)').remove();$(head).removeAttr('data-hasContent');});$('#editorWrapper').hide();$('#templateHtml').hide();}
else{$('.templateBody').hide();$('#ctl00_ctl00_ContentBody_ContentOptions_ulEditDirect').hide();}
$('#btnPromoteToProcess').live('click',function(){$(this).hide();promoteStep();})
$("#btnLayoutDiagram").click(layoutDiagram);$(window).resize(function(){resizeStepSection();});resizeStepSection();$(window).scroll(function(){resizeStepSection();});});var _passItem=null;function resizeStepSection()
{var stepsDiv=$('#steps');var stepsCell=$('#tblCellSteps');var win=$(window);var divWidth=Math.max(stepsCell.width()-20,100);var stepTop=stepsCell.offset().top;var scrollTop=win.scrollTop();var setTop=Math.max(stepTop-scrollTop,0);var winHeight=win.height();var divHeight=Math.max(winHeight-setTop,100);var winHeight=win.height();var body=document.body,html=document.documentElement;var docHeight=Math.max(body.scrollHeight,body.offsetHeight,html.clientHeight,html.scrollHeight,html.offsetHeight);if(scrollTop+divHeight>docHeight-100)
{divHeight=Math.max(docHeight-scrollTop-100,100);}
stepsDiv.css({height:divHeight+"px",width:divWidth+'px',top:setTop+'px'});$('#cellProcContainer').css({minHeight:divHeight+stepTop+'px'});}
function symbolDrag(pthis,event,ui)
{var helper=$(ui.helper);var canvasRect=$('#steps');var canvasPos=$('#steps').offset();if(ui.offset.left>canvasPos.left&&ui.offset.left<(canvasPos.left+canvasRect.width()-helper.width()-20)&&ui.offset.top>canvasPos.top&&ui.offset.top<(canvasPos.top+canvasRect.height()-helper.height()-20))
{pthis.trigger('mouseup');event.preventDefault();if(_passItem!=null){_passItem.symbol.events[0].f.call(_passItem.symbol,event);_passItem=null;}}}
function onShowProcessTab(ev,ui){if($(ui.tab).hasClass('stepsTab')){loadSteps();resizeStepSection();}}
function addHeadingDataClasses(cleanH2){var hdd=cleanH2.attr('data-direction');if(hdd==undefined){hdd='';}
var hdm=cleanH2.attr('data-multiplicity');if(hdm==undefined){hdm='';}
cleanH2.removeClass('hdd_in');cleanH2.removeClass('hdd_out');cleanH2.removeClass('hdd_inout');cleanH2.removeClass('hdm_0__1');cleanH2.removeClass('hdm_0__n');cleanH2.removeClass('hdm_1__1');cleanH2.removeClass('hdm_1__n');cleanH2.addClass('hdd_'+hdd.replace(/\W/g,'_'));cleanH2.addClass('hdm_'+hdm.replace(/\W/g,'_'));cleanH2.addClass('dd_head');}
var editingSection;function UpdateLinkFromDlg(){var editor=tinyMCE.get('ctl00_ctl00_ContentBody_ContentMain_htmlSectionEdit_htmlSectionEdit_ed');var editedHtml=editor.getContent().trim();var firstTag=editedHtml.indexOf('<');if(editedHtml.length>0&&firstTag!=0){editedHtml='<p>'+editedHtml.substring(0,firstTag)+'</p>'+editedHtml.substring(firstTag,editedHtml.length);}
editingSection.find('div.section > div.content').html(editedHtml);editingSection.find('h2').attr('data-hasContent','true');isDirty=true;var mpeId="ctl00_ctl00_ContentBody_ContentMain_btn_test_ModalPopupExtender";$find(mpeId).hide();addLinkProperties('.postEditor');}
function toggleEditDesc(){var editor=tinyMCE.get('ctl00_ctl00_ContentBody_ContentMain_htmlDesc_htmlDesc_ed');if($('#postEditorDescView').is(':visible')){$('#postEditorDescView .pdGenerated').remove();editor.setContent($('#postEditorDescView').html());}
else{var allHtml=editor.getContent();$('#postEditorDescView').html(allHtml);addLinkProperties('#postEditorDescView');}
$('#postEditorDescView').toggle();$('#postEditorDescEdit').toggle();}
function getRandomNumber(range){return Math.floor(Math.random()*range);}
function getRandomChar(){var chars="0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ";return chars.substr(getRandomNumber(62),1);}
function randomID(size){var str="";for(var i=0;i<size;i++){str+=getRandomChar();}
return str;}
function addLinkProperties(rootDiv){$(rootDiv+' .pdGenerated').remove();var checkLnks=[];$(rootDiv+" a[href]").each(function(){if(!($(this).attr('data-uid')))
$(this).attr('data-uid',randomID(20));var thisLink={uid:$(this).attr('data-uid'),href:$(this).attr('href'),icon:$(this).attr('data-icon'),isExcluded:$(this).attr('data-exclude'),displayProperties:$(this).attr('data-display'),isOptional:$(this).attr('data-optional')};checkLnks[checkLnks.length]=thisLink;});$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({processId:processId,processLinks:checkLnks}),url:_reposRoot+'/ProcessDefinition.asmx/GetProcessLinkData',success:function(data){onGotLinkData(data);}});}
function onGotLinkData(data){for(var i=0;i<data.d.length;i++){if(data.d[i].ProcessId!=null){var thisLink=$(".postEditor a[data-uid='"+data.d[i].UId+"']");var thisLinkButton=$("<span class='pdGenerated linkMetric' toProcId='"+data.d[i].ProcessId+"'></span>").insertAfter(thisLink);thisLinkButton.click(function(){enterLinkProperties($(this));});if(data.d[i].IconUrl!=null)
$("<span class='pdGenerated'>"+data.d[i].IconUrl+"&nbsp;</span>").insertBefore(thisLink);if(data.d[i].PropertiesHtml.length>0){$("<div class='pdGenerated linkProperties'>"+data.d[i].PropertiesHtml+"</div>").insertAfter(thisLinkButton);}}}}
var curLink;function enterLinkProperties(itm){var toProcId=$(itm).attr("toProcId");curLink=$(itm).prev('a');var linkType=0;var propValues="&uId="+curLink.attr('data-uid');if(curLink.attr('data-exclude')=='true')
linkType+=1;if(curLink.attr('data-display')=='false')
linkType+=2;if(curLink.attr('data-optional')=='true')
linkType+=4;propValues+='&linkType='+linkType;if(curLink.attr('data-icon'))
propValues+='&icon='+curLink.attr('data-icon');$('#ifLinkProperties').attr('src',rootDir+"/metadataloading.htm");$('#ifLinkProperties').attr('src',rootDir+"/LinkProperties.aspx?fromProcessId="+processId+"&toProcessId="+toProcId+propValues+"&t="+cBypass());$('#dlgLinkProperties').dialog('open');}
function onOKLinkProperties(){$(curLink).removeAttr('data-exclude');$(curLink).removeAttr('data-display');$(curLink).removeAttr('data-optional');$(curLink).removeAttr('data-icon');if($('#ifLinkProperties').contents().find('#isExcludedLink').is(':checked'))
curLink.attr('data-exclude','true');if($('#ifLinkProperties').contents().find('#hideProperties').is(':checked'))
curLink.attr('data-display','false');if($('#ifLinkProperties').contents().find('#isOptionalLink').is(':checked'))
curLink.attr('data-optional','true');var iconVal=$('#ifLinkProperties').contents().find('#ddDisplayIcon option:selected').val();curLink.attr('data-icon',iconVal);$(this).dialog("close");addLinkProperties('.postEditor');isDirty=true;}
function saveContent(){$('.btnSave a').text('Saving...');if(isDirectMode!=undefined&&isDirectMode==0){if($('#postEditorDescEdit').is(':visible'))
{toggleEditDesc();}
$('.postEditor .linkMetric').remove();var allHtml=$('#postEditorDescView').html();$('.templateSections > div').each(function(){var h2=$(this).find('h2');if(h2.attr('data-hasContent')=='true'){var cleanH2=$('<h2 class="dd_head"><span>'+$(this).find('h2 > a').text()+'</span></h2>');$(cleanH2).attr('data-direction',$(h2).attr('data-direction'));$(cleanH2).attr('data-multiplicity',$(h2).attr('data-multiplicity'));$(cleanH2).attr('data-linktypeid',$(h2).attr('data-linktypeid'));$(cleanH2).attr('data-linktypename',$(h2).attr('data-linktypename'));addHeadingDataClasses($(cleanH2));allHtml+=$(cleanH2).outerHTML();allHtml+=$(this).find('div.section > div.content > *:not(blockquote.tutorialText)').outerHTML();}});editor=tinyMCE.get('ctl00_ctl00_ContentBody_ContentMain_hBody_hBody_ed');editor.setContent(allHtml);}}
jQuery.fn.outerHTML=function(){return $('<div></div>').append(this.clone()).html();}
function addTagClick()
{$('#newTag #newTagNameSp').css('display','');$('#newTag #addTag').css('display','none');$('#newTag #newTagName').focus();}
function addedTag()
{var val=$.trim($('#newTag #newTagName').val());if(val.length!=0)
{var existing=$(".assignTags div span:matchesNoCase('"+val+"')");if(existing.length==0)
{var newT=$("<div class='checkedTag'><input type='checkbox' checked='checked'/><span>"+val+"</span></div>");newT.insertBefore('#newTag').effect('pulsate',{times:1},500);$("input",newT).change(function(){$(this).parent().toggleClass("checkedTag");});}
else
{$('input',existing.parent()).attr("checked","true");existing.parent().effect('pulsate',{times:1},500).addClass('checkedTag');}}
$('#newTag #newTagNameSp').css('display','none');$('#newTag #addTag').css('display','');$('#newTag #newTagName').val("");isDirty=true;}
function startPlaceholderDragging(ui)
{$('#placeholderDragging').text($('#txtPlaceholder').val());$('#placeholderDragging').css('display','');$('#txtPlaceholder').css('display','none');$('#processPlaceholder').addClass('phDragging');}
function stopPlaceholderDragging(ui)
{$('#placeholderDragging').css('display','none');$('#txtPlaceholder').css('display','');$('#processPlaceholder').removeClass('phDragging');}
function startDragging()
{$('#steps .stepDiv').css('visibility','visible');}
function stopDragging()
{$('#steps .stepDiv:first').css('visibility','hidden');$('#steps .stepDiv:last').css('visibility','hidden');}
function filterChanged()
{var filterText=$('#txtFilter').val();var procOnly=($('#chkStepUseProcOnly').hasClass('stchecked'))&&(reposProcTypeId!=null);var ftFilter=$('#chkStepUseFtSearch').hasClass('stchecked');if(ftFilter){$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({q:filterText,limit:9999,timestamp:''}),url:_reposRoot+'/ProcessDefinition.asmx/GetProcesses',success:function(data){$("#procDragTagList li").attr('flt','yes');for(var i=0;i<data.d.length;i++)
{var itm=$("#procDragTagList li.pid_"+data.d[i].ProcessId).attr('flt','no');if(procOnly){itm.not('.ptid_'+reposProcTypeId).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','');});showHideSearchResults(filterText);$('#procDragTagList').accordion('activate',false);}});}
else{$("#procDragTagList li").attr('flt','no');$("#procDragTagList li:not(:containsNoCase('"+filterText+"'))").attr('flt','yes');if(procOnly){$('#procDragTagList li').not('.ptid_'+reposProcTypeId).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','');});showHideSearchResults(filterText);$('#procDragTagList').accordion('activate',false);}}
function showHideSearchResults(filterText)
{if(filterText==''){$("#procDragTagList h3.ui-accordion-header.tagProcListSearchResults").css('display','none');$("#procDragTagList div.ui-accordion-content.tagProcListSearchResults").css('display','none');}
else{$("#procDragTagList h3.ui-accordion-header:not(.tagProcListSearchResults)").css('display','none');$("#procDragTagList div.ui-accordion-content:not(.tagProcListSearchResults)").css('display','none');$("#procDragTagList h3.ui-accordion-header.tagProcListSearchResults").css('display','block');$("#procDragTagList div.ui-accordion-content.tagProcListSearchResults").css('display','block');}}
function getStepName(stepName,isOptional,isIterative,prettyPostTitle,altGroup)
{var additionalSpans="";if(isIterative)
{additionalSpans+="<span class='ui-icon ui-icon-refresh' title='Iterative step'></span>";}
if(isOptional)
{additionalSpans+="<span class='ui-icon ui-icon-help' title='Optional step'></span>";}
if(altGroup!=null){additionalSpans+="<span class='ui-icon ui-icon-shuffle' title='Alternative group: "+altGroup+"'></span>";}
var postLink="";var promoteToProcess="";if(prettyPostTitle!=null)
{postLink=" href='"+_reposRoot+"/"+prettyPostTitle+"'  target='_blank'";}
else
{promoteToProcess="<span class='promote ui-icon ui-icon-arrowthick-1-n' title='Promote to process'></span>";}
return"<span class='processDragHandle ui-icon ui-icon-arrow-4-diag' title='Move process'></span>"+additionalSpans+"<a"+postLink+"><span class='stepNameVal'>"+htmlEncode(stepName)+"</span></a><span class='stepBar'><span class='edit blueIcon ui-icon ui-icon-pencil' title='Edit step'></span>"+promoteToProcess+"<span class='delete blueIcon ui-icon ui-icon-close' title='Delete step'></span></span>";}
function getStepHtml(step)
{var additionalClass="";if(step.isIterative)
{additionalClass+=" stepIter";}
if(step.isOptional)
{additionalClass+=" stepOpt";}
var procAttr="";var placeholderClass=" stepPlaceholder";if(step.processId!=null)
{procAttr+=" processId='"+step.processId+"'";additionalClass+=" stepLink";placeholderClass="";}
if(step.prettyPostTitle!=null)
{procAttr+=" prettyPostTitle='"+step.prettyPostTitle+"'";}
var ret="<div class='step"+additionalClass+"'"+procAttr+"><div class='stepWrapper'>";ret+="<div class='stepName"+placeholderClass+"'>"+getStepName(step.name,step.isOptional,step.isIterative,step.prettyPostTitle,step.altGroup)+"</div>";ret+="<div class='stepNotes'>"+htmlEncode(step.description)+"</div>";ret+="</div></div>";return ret;}
function getDividerHtml()
{return"<div class='stepDiv'><div class='divDropTarget'></div></div>";}
function loadSteps()
{if(!chart){$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{'processId':"+processId+"}",url:_reposRoot+'/ProcessDefinition.asmx/GetSteps',success:function(data){loadedSteps(data);}});}}
function appendGroup(appendTo)
{var container=$("<div class='stepContainer'></div>");appendTo.append(container);var grp=$("<div class='stepGroup'></div>");container.append(grp);return grp;}
var stepModel;function getStepModel(stepGuid){for(var i=0;i<stepModel.length;i++){var step=stepModel[i];if(step.stepGuid==stepGuid)
return step;}
return null;}
var chart;function loadedSteps(data)
{$('.bpmnLoading').hide();$('#steps').show();stepModel=data.d;var stepDefnText="";var stepFlowText="";var stepPosText="";var direction="V";var currentRow=0;var currentCol=0;var concCount=0;var inSplitId=null;var inOptionId=null;var splitAr=[];var lastJoinId=null;var inOptionalYesFlow,inOptionalNoFlow;for(var i=0;i<data.d.length;i++){var step=data.d[i];if(inOptionId!=null&&splitAr.length>0){concCount=0;inOptionId=null;for(var sp=0;sp<splitAr.length;sp++){stepFlowText+=splitAr[sp]+step.stepGuid+"\n";}
splitAr=[];}
if(step.isStartNode){stepDefnText+=step.stepGuid+"=>start:\n";stepFlowText=step.stepGuid+"(right)->";var posText=step.stepGuid+"("+(currentRow++)+", 1)\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;}
else if(step.isStopNode){stepDefnText+=step.stepGuid+"=>end:\n";if(lastJoinId)
stepFlowText+=lastJoinId+"(first, bottom)->";stepFlowText+=step.stepGuid;if(inOptionalNoFlow){stepFlowText+=(inOptionalNoFlow+"(no)->"+step.stepGuid);inOptionalNoFlow=null;}
var posText=step.stepGuid+"("+currentRow+", 1)\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;}
else if(step.isParallelGateway||step.isParallelJoin){if(step.isParallelJoin){stepDefnText+=step.stepGuid+"=>join:-\n";concCount=0;inSplitId=null;for(var sp=0;sp<splitAr.length;sp++){stepFlowText+=splitAr[sp]+step.stepGuid+"\n";}
splitAr=[];lastJoinId=step.stepGuid;++currentRow;currentCol=0;}
else{stepDefnText+=step.stepGuid+"=>split:-\n";concCount=1;inSplitId=step.stepGuid;if(lastJoinId){stepFlowText+=lastJoinId+"(first, bottom)->"+step.stepGuid+"->";lastJoinId=null;}else{stepFlowText+=step.stepGuid+"\n";}
currentCol=-1;}
var posText=step.stepGuid+"("+(currentRow++)+", 1)\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;if(inOptionalNoFlow){stepFlowText+=(inOptionalNoFlow+"(no)->"+step.stepGuid+"->");inOptionalNoFlow=null;}}
else if(step.isExclusiveGateway){stepDefnText+=step.stepGuid+"=>xor:.\n";var posText=step.stepGuid+"("+currentRow+", "+(++currentCol)+")\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;}
else if(step.name){var stepname;stepname=wordwrap(step.name,Math.max(20,step.name.length/4),"\n",true);stepDefnText+=step.stepGuid+"=>activity:"+stepname+"\n";if(inOptionalYesFlow){stepFlowText+=(inOptionalYesFlow+"(yes, right)->"+step.stepGuid+"->");inOptionalYesFlow=null;var posText=step.stepGuid+"("+currentRow+", "+(currentCol++)+")\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;}
else if(inOptionalNoFlow){stepFlowText+=(inOptionalNoFlow+"(no)->"+step.stepGuid+"->");inOptionalNoFlow=null;var posTText=step.stepGuid+"("+currentRow+", "+currentCol+")\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;}
if(step.isOptional&&false){stepDefnText+=step.stepGuid+"_option=>xor:.\n";var posText=step.stepGuid+"_option("+currentRow+", "+(++currentCol)+")\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;}
if(concCount==1){if(step.isOptional){if(inSplitId!=null){splitAr.push(inSplitId+"(first, right)->"+step.stepGuid+"_option(yes, right)->"+step.stepGuid+"->");splitAr.push(inSplitId+"(first, right)->"+step.stepGuid+"_option(no, bottom)->");}
else{splitAr.push(step.stepGuid+"_option(yes, right)->"+step.stepGuid+"->");splitAr.push(step.stepGuid+"_option(no, bottom)->");}}else{splitAr.push(inSplitId+"(first, right)->"+step.stepGuid+"->");}
concCount=2;}
else if(concCount==2){if(step.isOptional){splitAr.push(inSplitId+"(second, right)->"+step.stepGuid+"_option(yes, right)->"+step.stepGuid+"->");splitAr.push(inSplitId+"(second, right)->"+step.stepGuid+"_option(no, bottom)->");}else{splitAr.push(inSplitId+"(second, right)->"+step.stepGuid+"->");}
concCount=3;}
else if(concCount==3){splitAr.push(inSplitId+"(third, right)->"+step.stepGuid+"->");concCount=0;}
else{if(lastJoinId){stepFlowText+=lastJoinId+"(first, bottom)->";stepFlowText+=step.stepGuid+"->";lastJoinId=null;}
else
stepFlowText+=step.stepGuid+"->";}
if(inSplitId==null){currentCol=0;var posText=step.stepGuid+"("+(currentRow++)+", "+(++currentCol)+")\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;}
else{var posText=step.stepGuid+"("+currentRow+", "+(++currentCol)+")\n";if(step.bpmnJson!=undefined)
posText=step.stepGuid+"("+step.bpmnJson+")\n"
stepPosText+=posText;}}
if(i==0||step.isConcurrent)
{}
else
{}}
stepFlowText="";for(var i=0;i<data.d.length;i++){var step=data.d[i];if(step.Predecessors!=null&&step.Predecessors.length>0){for(var p=0;p<step.Predecessors.length;p++){var pred=step.Predecessors[p];var flowInfo="->";if(pred.text!=null&&pred.text.trim().length>0)
flowInfo="("+pred.text.toLowerCase()+")->";stepFlowText+=pred.fromId+flowInfo+step.stepGuid+"\n";}}}
stepDefnText+="\n"+stepFlowText+"\n"+stepPosText;var cd=document.getElementById("code");cd.value=stepDefnText;var btn=document.getElementById("run");(btn.onclick=function(){var code=cd.value;if(chart){chart.clean();}
snapPoints=[];chart=bpmndiag.parse(code);chart.setCallbacks({onEditSymbol:editStep,onGetSymbolAttrib:getStepAttrib,onDeleteSymbol:deleteStep,onCreatedActivity:addSymbolAttributes,getTooltip:getTooltip,onAddedParallelGateway:onAddedParallelGateway,});chart.drawSVG('steps',{'line-width':2,'line-length':35,'text-margin':10,'font-size':14,'font':'normal','font-family':'Helvetica','font-weight':'normal','font-color':'black','line-color':'black','element-color':'black','fill':'white','yes-text':'yes','no-text':'no','arrow-end':'block-wide-long','symbols':{'start':{'element-color':'#399324','fill':'forestgreen','fill-opacity':'0.5','line-width':'1.5','radius':40},'end':{'element-color':'#9E2F3C','fill':'darkred','fill-opacity':'0.5','line-width':'3','radius':40},'activity':{'element-color':'#00669E','fill':'#D6F2FC','line-width':'1'},'join':{'element-color':'#DBCB62','fill':'#FFED6B','line-width':'1'},'split':{'element-color':'#DBCB62','fill':'#FFED6B','line-width':'1'},'xor':{'element-color':'#DBCB62','fill':'#FFED6B','line-width':'1'}},'symbolstate':{'past':{'fill':'#CCCCCC','font-size':12},'current':{'fill':'yellow','font-color':'red','font-weight':'bold'},'future':{'fill':'#FFFF99'},'request':{'fill':'blue'},'invalid':{'fill':'#444444'},'approved':{'fill':'#58C4A3','font-size':12,'yes-text':'APPROVED','no-text':'n/a'},'rejected':{'fill':'#C45879','font-size':12,'yes-text':'n/a','no-text':'REJECTED'}}});})();canvas=document.getElementById('steps');canvas.addEventListener('mousedown',function(event){lastDownTarget=event.target;},false);document.addEventListener('keydown',function(event){chart.diagram.keydown(event);},false);document.addEventListener('keyup',function(event){chart.diagram.keyup(event);},false);$('#steps').droppable
({accept:'.step,li,#processPlaceholder,.parallelGateway,.inclusiveGateway',hoverClass:'hoverDropTarget',tolerance:'pointer',drop:function(event,ui){dropItem(event,ui,$(this));}});$('<div class="layingOut" id="layingOut" style="display:none;position: fixed;top: 0px;bottom: 0px;left: 0px;right: 0px;background-color: #fff;opacity: .7;text-align:left;padding:200px 0px 0px 80px;font-size:30px;">Calculating layout...</div>').appendTo('#steps');if(stepModel&&stepModel.length&&stepModel.length>0)
{if(!stepModel[0].bpmnJson)
{layoutDiagram();}}}
function onAddedParallelGateway(symbol,isGateway)
{newStep={description:'',isOptional:false,isIterative:false,isParallelGateway:isGateway,isParallelJoin:!isGateway,name:'',processId:null,prettyPostTitle:"",stepGuid:symbol.key};stepModel.push(newStep);}
function getTooltip(symbol)
{if(symbol.symbolType=='activity')
{var step=getStepModel(symbol.key);if(step)
{if(step.description)
{if($.trim(step.description).length>0)
{return step.description;}}}}
if(symbol.symbolType=='xor'){var step=getStepModel(symbol.key);if(step){var ret='';if(step.name){if($.trim(step.name).length>0&&step.name!='.'){ret=step.name;}}
if(step.description){if($.trim(step.description).length>0){if(ret.length>0)
{ret+='\n';}
ret+=step.description;}}
if(ret.length>0)
{return ret;}}}
return null;}
function addSymbolAttributes(activity)
{if(activity.symbolType=='activity')
{var step=getStepModel(activity.key);if(step)
{$(activity.symbol.node).attr("processid",step.processId);if(activity.symbol.children)
{for(var i=0;i<activity.symbol.children.length;i++)
{$(activity.symbol.children[i].node).attr("processid",step.processId);}}
if(step.processId==null){}}}}
function dropItem(event,ui,dropTarget)
{if($(ui.draggable).hasClass('step'))
dropStep(event,ui,dropTarget);else if($(ui.draggable).hasClass('phDragging'))
dropPlaceholder(event,ui,dropTarget);else if($(ui.draggable).hasClass('parallelGateway'))
dropGateway(event,ui,dropTarget,'parallel');else if($(ui.draggable).hasClass('inclusiveGateway'))
dropGateway(event,ui,dropTarget,'inclusive');else
dropProcess(event,ui,dropTarget);}
function dropPlaceholder(event,ui,dropTarget)
{var pos=ui.draggable.offset(),dPos=dropTarget.offset();var newStep={name:$('#placeholderDragging',ui.draggable).text(),description:'',isOptional:false,isIterative:false,processId:null,stepGuid:guid()};stepModel.push(newStep);var scrollTop=$('#steps').scrollTop();_passItem=chart.addSymbol("activity",$('#placeholderDragging',ui.draggable).text(),newStep.stepGuid,{x:pos.left-dPos.left+(ui.draggable.width())-20,y:pos.top-dPos.top+scrollTop+(ui.draggable.height())-20});isDirty=true;}
function guid(){function s4(){return Math.floor((1+Math.random())*0x10000).toString(16).substring(1);}
return s4()+s4()+'-'+s4()+'-'+s4()+'-'+
s4()+'-'+s4()+s4()+s4();}
function dropProcess(event,ui,dropTarget)
{var pos=ui.offset,dPos=dropTarget.offset();var newStep={name:$(ui.draggable).text(),description:'',isOptional:false,isIterative:false,processId:$(ui.draggable).attr("procid"),prettyPostTitle:$(ui.draggable).attr("prettytitle"),stepGuid:guid()};stepModel.push(newStep);var scrollTop=$('#steps').scrollTop();_passItem=chart.addSymbol("activity",$(ui.draggable).text(),newStep.stepGuid,{x:pos.left-dPos.left+(ui.draggable.width())-20,y:pos.top-dPos.top+scrollTop+(ui.draggable.height())-20});isDirty=true;}
function dropGateway(event,ui,dropTarget,gatewayType){var pos=ui.offset,dPos=dropTarget.offset();var newStep=null;var scrollTop=$('#steps').scrollTop();if(gatewayType=="inclusive"){newStep={name:$(ui.draggable).text(),description:'',isOptional:false,isIterative:false,isExclusiveGateway:true,name:'.',processId:null,prettyPostTitle:"",stepGuid:guid()};_passItem=chart.addSymbol("xor",".",newStep.stepGuid,{x:pos.left-dPos.left,y:pos.top+scrollTop-dPos.top});}
if(gatewayType=="parallel"){newStep={name:$(ui.draggable).text(),description:'',isOptional:false,isIterative:false,isExclusiveGateway:false,isParallelGateway:true,isParallelJoin:false,name:'-',processId:null,prettyPostTitle:"",stepGuid:guid()};_passItem=chart.addSymbol("split","-",newStep.stepGuid,{x:pos.left-dPos.left,y:pos.top+scrollTop-dPos.top});}
if(newStep)
{stepModel.push(newStep);isDirty=true;}}
function dropStep(event,ui,dropTarget)
{if(dropTarget.hasClass('stepDiv'))
{var container=$("<div class='stepContainer'></div>");dropTarget.before(container);var grp=$("<div class='stepGroup'></div>");container.append(grp);grp.append(ui.draggable);}
else
{$('.stepGroup',dropTarget).append(ui.draggable);}
ui.draggable.css('left','0px');ui.draggable.css('top','0px');applyStyles();isDirty=true;}
var currentlyEditting;function editStep(stepGuid){var step=getStepModel(stepGuid);if(step==null)
return;if(step.isParallelJoin||step.isParallelGateway||step.isStartNode||step.isStopNode)
return;var stepName=$.trim(step.name);if(stepName=='.')
{stepName='';}
$('#stepDialogComponent').show();if(step.isExclusiveGateway)
{$('#stepDialogComponent').hide();}
currentlyEditting=step;$('#stepName').val(stepName);$('#stepDesc').val(step.description);$('#isIterativeStep').prop('checked',step.isIterative);$('#btnPromoteToProcess').hide();if(!step.processId)
{$('#btnPromoteToProcess').show();}
$('#stepDialog').dialog('open');}
function getStepAttrib(stepGuid,attribName){var step=getStepModel(stepGuid);if(step!=null){if(attribName=='isComplex'){return(step.processId);}
else if(attribName=='isLoop'){return(step.isIterative);}}
return null;}
function deleteStep(stepGuid){for(var i=0;i<stepModel.length;i++){var step=stepModel[i];if(step.stepGuid==stepGuid){stepModel.splice(i,1);break;}}
isDirty=true;}
function onEdittedStep(){var stepName=$.trim($('#stepName').val());if(stepName.length==0)
{stepName='.';}
currentlyEditting.name=stepName;currentlyEditting.description=$('#stepDesc').val();if(!currentlyEditting.isExclusiveGateway)
{currentlyEditting.isIterative=$('#isIterativeStep').attr("checked")=="checked";}
$(this).dialog("close");currentlyEditting.name=wordwrap(currentlyEditting.name,Math.max(20,currentlyEditting.name.length/4),"\n",true);chart.diagram.updateSelectedSymbol(currentlyEditting.name,currentlyEditting.isIterative);chart.diagram.clearSymbolSelection();currentlyEditting=null;isDirty=true;}
function promoteStep(){var step=currentlyEditting;var stepName=currentlyEditting.name;$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({newProcessName:stepName}),url:_reposRoot+'/ProcessDefinition.asmx/CreateProcess',success:function(data){onCreatedProcess(data,step,stepName);}});}
function onCreatedProcess(data,step,stepName)
{step.processId=data.d.ProcessId;step.prettyPostTitle=data.d.PrettyUrl;chart.diagram.updateIsComplex(true);isDirty=true;}
function saveSteps()
{$('.btnSave a').text('Saving...');var sTags=[];var selTags=$(".assignTags .checkedTag input:checked");for(var i=0;i<selTags.length;i++)
{var checkedTag=selTags.eq(i);sTags[sTags.length]=$('span',checkedTag.parent()).text();}
var dSendTags={processId:processId,tags:sTags};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSendTags),url:_reposRoot+'/ProcessDefinition.asmx/SaveTags'});if(chart==undefined)
{isSaving=true;return;}
for(var stepIdx=0;stepIdx<stepModel.length;stepIdx++){stepModel[stepIdx].Predecessors=[];}
var input=chart.getFlowDefinition();var lines=[];var prevBreak=0;for(var i0=1,i0len=input.length;i0<i0len;i0++){if(input[i0]==='\n'&&input[i0-1]!=='\\'){var line0=input.substring(prevBreak,i0);prevBreak=i0+1;lines.push(line0.replace(/\\\n/g,'\n'));}}
if(prevBreak<input.length){lines.push(input.substr(prevBreak));}
while(lines.length>0){var line=lines.splice(0,1)[0];if(line.indexOf('->')>=0){var flowSymbols=line.split('->');if(flowSymbols.length===2){var sourceStepId=flowSymbols[0];var predText='';var destStepId=flowSymbols[1];if(sourceStepId.indexOf('(')>0&&sourceStepId.indexOf(')')>0){var startIndex=sourceStepId.indexOf('(')+1;var endIndex=sourceStepId.indexOf(')');if(startIndex>=0&&endIndex>=0){predText=sourceStepId.substring(startIndex,endIndex);sourceStepId=sourceStepId.substring(0,startIndex-1);}}
var destStep=getStepModel(destStepId);var sourceStep=getStepModel(sourceStepId);if(destStep!=undefined&&sourceStep!=undefined){var pred={fromId:sourceStepId,text:predText};destStep.Predecessors.push(pred);}}}}
var posDefn=chart.getPositionDefinition();for(var posIdx=0;posIdx<posDefn.length;posIdx++){var pos=posDefn[posIdx];var step=getStepModel(pos.id);step.bpmnJson=JSON.stringify(pos);}
for(var i=0;i<stepModel.length;i++)
{delete stepModel[i].__type;}
var dSend={processId:processId,steps:stepModel};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/SaveSteps',async:false});var allElements=chart.diagram.paper.set();var bot=chart.diagram.paper.bottom;while(bot){if(bot&&bot.type!="path")
allElements.push(bot);bot=bot.next;}
var allBB=allElements.getBBox();allElements.translate(-allBB.x+5,-allBB.y+5);bot=chart.diagram.paper.bottom;while(bot){if(bot&&bot.type=="path")
bot.translate(-allBB.x+5,-allBB.y+5);bot=bot.next;}
chart.diagram.paper.setSize(allBB.width+10,allBB.height+10);var stepsContainer=$('#steps');var diagSvg=stepsContainer.html();var dParams={processId:processId,diagSvg:diagSvg};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dParams),url:_reposRoot+'/ProcessDefinition.asmx/SetProcessStepDiagramSvg',async:false});isSaving=true;}
function applyStyles()
{$('div.stepDiv').remove();var stepDivs=$('#steps .stepGroup');for(var j=stepDivs.length-1;j>=0;j--)
{var containedSteps=$('.step',stepDivs.eq(j));stepDivs.eq(j).removeClass('stepConcurrent');if(containedSteps.length==0)
{stepDivs.eq(j).parent().remove();}
else if(containedSteps.length>1)
{stepDivs.eq(j).addClass('stepConcurrent');}}
$('#steps .stepContainer').before($(getDividerHtml()));$('#steps').append($(getDividerHtml()));$('#steps .stepDiv:first').css('visibility','hidden');$('#steps .stepDiv:last').css('visibility','hidden');$('#steps .stepContainer').droppable
({accept:'.step,li,#processPlaceholder',hoverClass:'hoverDropTarget',tolerance:'pointer',drop:function(event,ui){dropItem(event,ui,$(this));}});$('#steps .stepDiv').droppable
({accept:'.step,li,#processPlaceholder',hoverClass:'hoverDropTarget',tolerance:'pointer',drop:function(event,ui){dropItem(event,ui,$(this));}});}
function htmlEncode(str)
{return str.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");}
function htmlDecode(str)
{return str.replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&amp;/g,"&");}
function layoutDiagram(){$('#layingOut').show();for(var stepIdx=0;stepIdx<stepModel.length;stepIdx++){stepModel[stepIdx].Predecessors=[];}
var input=chart.getFlowDefinition();var lines=[];var prevBreak=0;for(var i0=1,i0len=input.length;i0<i0len;i0++){if(input[i0]==='\n'&&input[i0-1]!=='\\'){var line0=input.substring(prevBreak,i0);prevBreak=i0+1;lines.push(line0.replace(/\\\n/g,'\n'));}}
if(prevBreak<input.length){lines.push(input.substr(prevBreak));}
while(lines.length>0){var line=lines.splice(0,1)[0];if(line.indexOf('->')>=0){var flowSymbols=line.split('->');if(flowSymbols.length===2){var sourceStepId=flowSymbols[0];var predText='';var destStepId=flowSymbols[1];if(sourceStepId.indexOf('(')>0&&sourceStepId.indexOf(')')>0){var startIndex=sourceStepId.indexOf('(')+1;var endIndex=sourceStepId.indexOf(')');if(startIndex>=0&&endIndex>=0){predText=sourceStepId.substring(startIndex,endIndex);sourceStepId=sourceStepId.substring(0,startIndex-1);}}
var destStep=getStepModel(destStepId);var sourceStep=getStepModel(sourceStepId);if(destStep!=undefined&&sourceStep!=undefined){var pred={fromId:sourceStepId,text:predText};destStep.Predecessors.push(pred);}}}}
var posDefn=chart.getPositionDefinition();for(var posIdx=0;posIdx<posDefn.length;posIdx++){var pos=posDefn[posIdx];var step=getStepModel(pos.id);step.bpmnJson=JSON.stringify(pos);}
for(var i=0;i<stepModel.length;i++){delete stepModel[i].__type;}
var dSend={processId:processId,steps:stepModel};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/LayoutSteps',success:function(data){chart.diagram.layoutDiagram(data.d);$('#layingOut').hide();}});isDirty=true;}