
$(document).ready(function(){$('#taskProgress').click(showTaskProgress);$('#btnUpdateStartVals').click(updateStartVals);$('#btnStartProgress').click(startTaskProgress);$('#btnCancelProgress').click(cancelTaskProgress);$('#btnUpdateStartedVals').click(updateStartedVals);$('#btnFinishProgress').click(finishTaskProgress);$('#btnRollback1').click(function(){rollbackStatus(1);});$('#btnCancelStartedProgress').click(cancelTaskProgress);$('#btnSaveFinished').click(saveFinishedTaskProgress);$('#btnRollback2').click(function(){rollbackStatus(2);});$('#btnCancelFinished').click(cancelTaskProgress);$('#chSuccess').click(changeSuccessCheck);$('#btnCancelFinishedStatus').click(cancelTaskProgress);$('.tProgress').click(function(){showTaskItemProgress($(this));});$('.tProgress').hover(function(){$(this).addClass('hovering');},function(){$(this).removeClass('hovering');});$('#progressSlider').slider({range:'min',value:0,min:0,max:100,slide:function(event,ui){$('#progressAmount').text(ui.value);if(ui.value==100)
{$('#btnFinishProgress').effect('pulsate',{times:1},500);}}});});var curTaskId=null;var selTaskProgress=null;function showTaskProgress()
{curTaskId=thisTaskId;selTaskProgress=null;$('#sendProcesDlg').slideUp('fast');$('#taskProgressDlg').insertAfter('#upgradeProcessDlg');$('#taskProgressDlg').css({'top':$(this).position().top,'right':$(window).width()-($(this).parent().position().left+($(this).parent().outerWidth()))}).slideDown('fast',function(){});loadTaskInfo();}
function showTaskItemProgress(t)
{curTaskId=t.parent().attr('tid');selTaskProgress=t;$('#taskProgressDlg').insertAfter(t);$('#taskProgressDlg').css({'top':'','right':''}).slideDown('fast',function(){});$('#taskProgressDlg').slideDown('fast',function(){});loadTaskInfo();}
function hideProgressPanels()
{$('#progressLoading').css('display','none');$('#progressNotStarted').css('display','none');$('#progressStarted').css('display','none');$('#progressFinished').css('display','none');$('#progressFinishedStatus').css('display','none');$('#progressSaving').css('display','none');}
function loadTaskInfo()
{hideProgressPanels();$('#progressLoading').css('display','');$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{taskId:"+curTaskId+"}",url:_reposRoot+'/ProcessDefinition.asmx/GetTaskProgress',success:function(data){onLoadedTaskInfo(data);},error:function(XMLHttpRequest,textStatus,errorThrown){loadInfoError(XMLHttpRequest,textStatus,errorThrown)}});}
function loadInfoError(XMLHttpRequest,textStatus,errorThrown){$('#taskProgressDlg').slideUp('fast');}
function onLoadedTaskInfo(data)
{$('#progressLoading').css('display','none');if(data.d.CurrentStatus==1)
{$('#progressNotStarted').css('display','');if(data.d.EstimatedStartDate!=null)
{$('#dtEstimatedStart_txt').val(data.d.EstimatedStartDateText);}
else
{$('#dtEstimatedStart_txt').val('');}
if(data.d.EstimatedEndDate!=null)
{$('#dtEstimatedFinish_txt').val(data.d.EstimatedEndDateText);}
else
{$('#dtEstimatedFinish_txt').val('');}}
else if(data.d.CurrentStatus==2)
{$('#progressStarted').css('display','');$('#tActualStart').text(data.d.ActualStartDateText);if(data.d.EstimatedEndDate!=null)
{$('#dtStartedEstimatedFinish_txt').val(data.d.EstimatedEndDateText);}
else
{$('#dtStartedEstimatedFinish_txt').val('');}
$('#chSuccess').attr("checked","true");$('#exceptionReason').css('display','none');$('#txtException').val('');$('#progressSlider').slider('option','value',data.d.TaskProgressPc);$('#progressAmount').text(data.d.TaskProgressPc);}
else if((data.d.CurrentStatus==3)||(data.d.CurrentStatus==4))
{$('#progressFinishedStatus').css('display','');$('#tActualStartFinished').text(data.d.ActualStartDateText);$('#tActualEndFinished').text(data.d.ActualEndDateText);if(data.d.CurrentStatus==3)
{$('#tFinishStatus').text("Successfully");$('#failedReason').css('display','none');}
else
{$('#tFinishStatus').text("Unsuccessfully");$('#failedReason').css('display','');$('#failedReason').text(data.d.StatusNotes);}}}
function onSavedProgress(data)
{$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{taskId:"+curTaskId+"}",url:_reposRoot+'/ProcessDefinition.asmx/GetTaskProgress',success:function(data){onUpdateProgressText(data);}});}
function updateStartVals()
{hideProgressPanels();$('#progressSaving').css('display','');var dSend={taskId:curTaskId,estimatedStartDate:$('#dtEstimatedStart_txt').val(),estimatedEndDate:$('#dtEstimatedFinish_txt').val()};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/SetTaskProgressEstimates',success:function(data){onSavedProgress(data);}});return false;}
function cancelTaskProgress()
{$('#taskProgressDlg').slideUp('fast');return false;}
function startTaskProgress()
{hideProgressPanels();$('#progressSaving').css('display','');var dSend={taskId:curTaskId,estimatedStartDate:$('#dtEstimatedStart_txt').val(),estimatedEndDate:$('#dtEstimatedFinish_txt').val()};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/StartTaskProgress',success:function(data){onSavedProgress(data);}});return false;}
function updateStartedVals()
{hideProgressPanels();$('#progressSaving').css('display','');var dSend={taskId:curTaskId,estimatedEndDate:$('#dtStartedEstimatedFinish_txt').val(),progress:$('#progressSlider').slider('option','value')};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/SetTaskProgressFinishEstimates',success:function(data){onSavedProgress(data);}});return false;}
function finishTaskProgress()
{$('#progressStarted').slideUp('fast');$('#progressFinished').slideDown('fast');}
function onUpdateProgressText(data)
{if(selTaskProgress!=null)
{selTaskProgress.removeClass('tProgress1');selTaskProgress.removeClass('tProgress2');selTaskProgress.removeClass('tProgress3');selTaskProgress.removeClass('tProgress4');selTaskProgress.addClass('tProgress'+data.d.CurrentStatus);selTaskProgress.html(data.d.StatusText);$('#taskProgressDlg').slideUp('fast');}
else
{$('h1.processHead,#tabs').removeClass('taskStat1');$('h1.processHead,#tabs').removeClass('taskStat2');$('h1.processHead,#tabs').removeClass('taskStat3');$('h1.processHead,#tabs').removeClass('taskStat4');$('h1.processHead,#tabs').addClass('taskStat'+data.d.CurrentStatus);$('#taskProgressDlg').slideUp('fast');}}
function saveFinishedTaskProgress()
{hideProgressPanels();$('#progressSaving').css('display','');var finishStatus=3;var statusNotes='';if($('#chSuccess').is(':checked')==false)
{finishStatus=4;statusNotes=$('#txtException').val();}
var dSend={taskId:curTaskId,finishStatus:finishStatus,statusNotes:statusNotes};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/StopTaskProgress',success:function(data){onSavedProgress(data);}});return false;}
function changeSuccessCheck()
{if($('#chSuccess').is(':checked')==true)
{$('#exceptionReason').slideUp('fast');}
else
{$('#exceptionReason').slideDown('fast');}}
function rollbackStatus(toStat)
{hideProgressPanels();$('#progressSaving').css('display','');var dSend={taskId:curTaskId,currentStatus:toStat};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/SetTaskProgressStatus',success:function(data){onSavedProgress(data);}});return false;}