
var _loadEvent=0;var isDirty=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();}});window.onbeforeunload=function(){if(isDirty){return msg;}};$('#txtFilter').keypress(function(e){if(e.keyCode==13){$('#btnFilter').click();return false;}});$("#procDragTagList").accordion({collapsible:true,autoHeight:false});$("#procDragList li").draggable({revert:true,helper:'clone',revertDuration:0,appendTo:'#tasks ol',connectToSortable:'#tasks ol',start:function(event,ui)
{startDragging();},stop:function(event,ui)
{stopDragging();}});$("#taskPlaceholder").draggable({revert:true,helper:'clone',handle:'#addPlaceholder',revertDuration:0,appendTo:'#tasks ol',connectToSortable:'#tasks ol',start:function(event,ui)
{startPlaceholderDragging(ui);startDragging();},stop:function(event,ui)
{stopPlaceholderDragging(ui);stopDragging();}});$("#tasks ol").sortable({placeholder:'ui-state-highlight',update:function(ev,ui){onSortUpdated(ev,ui);},change:function(ev,ui){onSortChange(ev,ui);},handle:'b'});$("#tasks ol").disableSelection();$("#tasks ol li").hover(function(){$(".editTaskButtons span",this).fadeIn('fast')},function(){$(".editTaskButtons span",this).fadeOut('fast')});$("#tasks ol li .editTaskButtons").css('display','');$("#tasks ol li .editTaskButtons span").fadeOut(0);$("#tasks ol li .editTaskButtons .ui-icon-arrowstop-1-e").live('click',function(){toConcurrent($(this));});$("#tasks ol li .editTaskButtons .ui-icon-arrowstop-1-w").live('click',function(){toNonConcurrent($(this));});$("#tasks ol li .editTaskButtons .ui-icon-pencil").live('click',function(){stepProperties($(this));});$("#tasks ol li .editTaskButtons .ui-icon-trash").live('click',function(){onDelete($(this).parent().parent());});$("#tasks ol li .taskIdentifiers .ui-icon-refresh").click(function(){onAddIterations($(this).parent().parent());});$("#tasks ol li .taskIdentifiers .ui-icon-shuffle").click(function(){onChooseAlternative($(this).parent().parent());});$("#dlgProperties").dialog({autoOpen:false,modal:true,resizable:false,width:550});$('#dlgProperties').dialog('option','buttons',{"Cancel":function(){$(this).dialog("close");},"OK":onChangeStep});$("#dlgNewIterations").dialog({autoOpen:false,modal:true,resizable:false,width:550});$('#dlgNewIterations').dialog('option','buttons',{"Cancel":function(){$(this).dialog("close");},"OK":onAddedIterations});$('#dlgRemovalReason').dialog({autoOpen:false,modal:true,resizable:false,width:550});$('#dlgRemovalReason').dialog('option','buttons',{"Cancel":function(){$(this).dialog("close");},"OK":onAddedRemovalReason});$("#dlgChooseAlternative").dialog({autoOpen:false,modal:true,resizable:false,width:550});$('#dlgChooseAlternative').dialog('option','buttons',{"Cancel":function(){$(this).dialog("close");},"OK":onAlternativeChosen});$('#btnSave').click(function(){onSave();});$('#btnCancel').click(function(){window.location.href=_reposRoot+'/'+pPostTitle+'/Task/'+taskId;});updateStepNumbers();});function toNonConcurrent(ele)
{ele.parent().parent().attr('isconc','False');ele.removeClass('ui-icon-arrowstop-1-w');ele.addClass('ui-icon-arrowstop-1-e');isDirty=true;updateStepNumbers();}
function toConcurrent(ele)
{ele.parent().parent().attr('isconc','True');ele.removeClass('ui-icon-arrowstop-1-e');ele.addClass('ui-icon-arrowstop-1-w');isDirty=true;updateStepNumbers();}
function startPlaceholderDragging(ui)
{$('#placeholderDragging').text($('#txtPlaceholder').val());$('#placeholderDragging').css('display','');$('#txtPlaceholder').css('display','none');}
function stopPlaceholderDragging(ui)
{$('#placeholderDragging').css('display','none');$('#txtPlaceholder').css('display','');isDirty=true;}
function onSortChange(ev,ui)
{updateStepNumbers();}
function onSortUpdated(ev,ui)
{var addedItemText=null;if($(ui.item).attr('data-dragId')=='taskPlaceholder')
{addedItemText=$('#txtPlaceholder').val();}
if($(ui.item).attr('prettytitle')!=''&&$(ui.item).attr('prettytitle')!=null)
{addedItemText="<a href='#'>"+$(ui.item).text()+"</a>";}
if(addedItemText!=null)
{$(ui.item).removeAttr('id');$(ui.item).removeAttr('class');$(ui.item).removeAttr('style');$(ui.item).removeAttr('prettytitle');$(ui.item).attr('isconc','False');$(ui.item).attr('isiter','False');$(ui.item).attr('iterguid','');$(ui.item).html('<b>'+addedItemText+'</b><span class="editTaskButtons"><span class="ui-icon-arrowstop-1-e"></span><span class="ui-icon-pencil"></span><span class="ui-icon-trash"></span></span><div><i></i></div>');$(ui.item).hover(function(){$(".editTaskButtons span",this).fadeIn('fast')},function(){$(".editTaskButtons span",this).fadeOut('fast')});}
isDirty=true;updateStepNumbers();}
function updateStepNumbers()
{var nStepNum=1;$('#tasks ol li:not(.ui-sortable-helper)').each(function(i)
{if($(this).attr('isconc')=='True'||$(this).attr('isremoved')=='True')
{$(this).css('marginTop','8px');$(this).css('borderTopStyle','none');$(this).css('listStyleType','none');$(this).get(0).removeAttribute('value');}
else
{if(nStepNum!=1)
{$(this).css('marginTop','18px');$(this).css('borderTopStyle','solid');}
$(this).css('listStyleType','');$(this).attr('value',nStepNum);nStepNum++;}});}
function startDragging()
{updateStepNumbers();}
function stopDragging()
{}
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);}
var curProp;function stepProperties(ele)
{curProp=ele.parent().parent();$('#txtName').val($('b',curProp).text());$('#txtDescription').val($('i',curProp).text());$('#dlgProperties').dialog('open');}
function onChangeStep()
{if($('b a',curProp).length>0)
$('b a',curProp).text($('#txtName').val());else
$('b',curProp).text($('#txtName').val());$('i',curProp).text($('#txtDescription').val());$(this).dialog("close");isDirty=true;}
var removing;function onDelete(ele)
{if(ele.attr('taskid')==null||ele.attr('taskid')=='')
{ele.remove();}
else
{if(ele.attr('isremoved')=='True')
{ele.removeClass('removedTask');ele.removeAttr('isremoved');}
else
{removing=ele;$('#txtRemovalReason').val($('.removalReason',ele).text());$('#dlgRemovalReason').dialog('open');}}
isDirty=true;updateStepNumbers();}
function onAddedRemovalReason()
{removing.addClass('removedTask');removing.attr('isremoved','True');$('.removalReason',removing).text($('#txtRemovalReason').val());$(this).dialog("close");updateStepNumbers();}
var iterTask;function onAddIterations(ele)
{iterTask=ele;$('#txtNewIter').val('');$('#dlgNewIterations').dialog('open');}
function onAddedIterations()
{var iterText=$.trim($('#txtNewIter').val());var iters=iterText.split('\n');for(i=iters.length-1;i>=0;i--)
{var iter=$.trim(iters[i]);if(iter.length!=0)
{addIter(iter);}}
isDirty=true;updateStepNumbers();$(this).dialog("close");}
function addIter(iterName)
{var newItem=iterTask.clone();if($('b a',newItem).length>0)
$('b a',newItem).text(iterName);else
$('b',newItem).text(iterName);newItem.removeClass('removedTask');newItem.removeAttr('isremoved');newItem.css('textDecoration','');$('.taskIdentifiers',newItem).remove();newItem.attr('isconc','False');newItem.attr('isiter','False');newItem.removeAttr('taskid');newItem.attr('iterguid',iterTask.attr('taskid'));newItem.attr('altGrp',iterTask.attr('altGrp'));newItem.insertAfter(iterTask);newItem.hover(function(){$(".editTaskButtons span",this).fadeIn('fast')},function(){$(".editTaskButtons span",this).fadeOut('fast')});}
var altTask;function onChooseAlternative(ele)
{altTask=ele;var dParams={taskGuid:altTask.attr('taskid'),altGroup:altTask.attr('altGrp')};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dParams),url:_reposRoot+'/ProcessDefinition.asmx/GetTaskAlternatives',success:function(alternatives){onGetTaskAlternatives(alternatives);}});}
function onGetTaskAlternatives(alternatives){var options='';for(var i=0;i<alternatives.d.length;i++){options+='<option value="'+alternatives.d[i].ProcessId+'">'+alternatives.d[i].ProcessTitle+'</option>';}
$('#listAlternatives').html(options);$('#lblAltGroup').text(altTask.attr('altGrp'));$('#dlgChooseAlternative').dialog('open');}
function onAlternativeChosen(){var newItem=altTask.clone();altTask.addClass('removedTask');altTask.attr('isremoved','True');$('.removalReason',altTask).text('Alternative task selected.');newItem.removeClass('removedTask');newItem.removeAttr('isremoved');newItem.css('textDecoration','');$('.taskIdentifiers',newItem).remove();newItem.attr('isconc',altTask.attr('isconc'));newItem.attr('isiter',altTask.attr('isconc'));newItem.removeAttr('taskid');newItem.attr('iterguid',altTask.attr('taskid'));newItem.attr('altGrp',altTask.attr('altGrp'));if($('b a',newItem).length>0)
$('b a',newItem).text($('#listAlternatives :selected').text());else
$('b',newItem).text($('#listAlternatives :selected').text());newItem.attr('procid',$('#listAlternatives').val());newItem.insertAfter(altTask);newItem.hover(function(){$(".editTaskButtons span",this).fadeIn('fast')},function(){$(".editTaskButtons span",this).fadeOut('fast')});updateStepNumbers();$(this).dialog("close");}
function onSave()
{var tasks=[];var i=0;var childTasks=$("#tasks ol li");for(i=0;i<childTasks.length;i++)
{var chTask=getTask(childTasks.eq(i));tasks[tasks.length]=chTask;}
var dParams={taskId:taskId,tasks:tasks};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dParams),url:_reposRoot+'/ProcessDefinition.asmx/SaveTasks',success:function(msg){finished(msg);}});isDirty=false;}
function finished(msg)
{if(msg.d==true)
{window.location.href=_reposRoot+'/'+pPostTitle+'/Task/'+taskId;}}
function getTask(ele)
{var name;if($('b a',ele).length>0)
name=$('b a',ele).text();else
name=$('b',ele).text();var newStep={name:name,taskId:ele.attr('taskid'),processId:ele.attr('procid'),isConcurrent:ele.attr('isconc')=='True',isRemoved:(ele.attr('isremoved')=='True'),basedOnTaskId:ele.attr('iterguid'),altGroup:ele.attr('altGrp'),notes:$("div i",ele).html(),removalReason:(ele.attr('isremoved')=='True')?$('.removalReason',ele).text():""};return newStep;}