
$(document).ready(function(){$("#txtSendTo").autocomplete(_reposRoot+"/ProcessDefinition.asmx/GetMembers",{parse:function(data){var parsed=[];for(var i=0;i<data.d.length;i++){parsed[parsed.length]={data:htmlEncode(data.d[i].DisplayName),value:data.d[i].UserId.toString(),result:data.d[i].DisplayName};}
return parsed;},selectFirst:true,dataType:"json",mustMatch:true,formatItem:function(data){return data;}});$('#txtSendTo').result(function(event,data,formatted){if(data){if($("#selSendTo li[uid='"+formatted+"']").length==0){$("<li uid='"+formatted+"'>").html(data+"<span class='del ui-icon-close'></span>").appendTo("#selSendTo");updateAssignButton();}
$('#txtSendTo').val('');}});$('#selSendTo li .del').live('click',function(){$(this).parent().fadeOut
('fast',function(){$(this).remove();updateAssignButton();});});$('.assignTaskButton').click(showAssignTask);$('#btnAssignTaskOk').click(assignTask);$('#btnAssignTaskCancel').click(cancelAssignTask);$('.projectRole').each(function(index){refreshAssignedUsers($(this).attr('roleId'))});$('ul.selAssignedTo li .del').live('click',function(){$(this).parent().fadeOut
('fast',function(){var thisTaskId=parseInt($(this).parents('.roleTask').attr('taskId'));var thisRoleId=parseInt($(this).parents('.projectRole').attr('roleId'));$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({removeUserId:$(this).attr("uid"),roleId:thisRoleId,taskId:thisTaskId}),url:_reposRoot+'/ProcessDefinition.asmx/RemoveUserRoleTaskAssignment'});if($('li',$(this).parents('ul.selAssignedTo')).length==1)
{$(this).parents('.roleTask').removeClass('taskAssigned');$(this).parents('.roleTask').addClass('taskNone');}
$(this).remove();});});});var _roleId;function showAssignTask(){_roleId=$(this).parents('.projectRole').attr('roleId');$('#taskProgressDlg').slideUp('fast');var leftPos=$(this).parent().position().left;$('#assignTaskDlg').css({'top':$(this).position().top,'left':$(this).parent().position().left}).slideDown('fast',function(){$('#txtSendTo').focus();});}
function assignTask(){var uArr=[];$('#selSendTo li').each(function(i){uArr[uArr.length]=parseInt($(this).attr('uid'));});var dSend={roleId:parseInt(_roleId),users:uArr,note:$('#txtComments').val()};$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(dSend),url:_reposRoot+'/ProcessDefinition.asmx/AssignToRole',success:function(data){onAssignedTask();}});}
function onAssignedTask(){$('#assignTaskDlg').slideUp('fast',function(){$('#assignTask').effect('pulsate',{times:2},500,function(){$('#assignTask a').text('Assign task');});});$('#selSendTo li').remove();$('#txtComments').val('');$('#txtSendTo').val('');updateAssignButton();refreshAssignedUsers(_roleId);}
function updateAssignButton(){if($("#selSendTo li").length==0){$('#btnAssignTaskOk').css('display','none');}
else{$('#btnAssignTaskOk').css('display','');}}
function refreshAssignedUsers(roleId){var assignedAreaId='div.projectRole[roleId='+roleId+'] .selAssignedTo';$(assignedAreaId).html('');var taskAreaId='div.projectRole[roleId='+roleId+'] span.roleTask';$(taskAreaId).removeClass('taskNone');$(taskAreaId).removeClass('taskAssigned');$(taskAreaId).addClass('taskLoading');$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({roleId:parseInt(roleId)}),url:_reposRoot+'/ProcessDefinition.asmx/GetRoleAssignments',success:function(data){onGotAssignedUsers(roleId,data);}});}
function onGotAssignedUsers(roleId,data){var taskAreaId='div.projectRole[roleId='+roleId+'] span.roleTask';$(taskAreaId).removeClass('taskLoading');$(taskAreaId).addClass('taskNone');for(var i=0;i<data.d.length;i++){var assignedTaskAreaId='div.projectRole[roleId='+roleId+'] span.roleTask[taskId='+data.d[i].TaskId+'] ul.selAssignedTo';$(assignedTaskAreaId).append("<li uid='"+data.d[i].AssignedToId+"'>"+data.d[i].DisplayName+"<span class='del ui-icon-close'></span></li>");var taskAreaId='div.projectRole[roleId='+roleId+'] span.roleTask[taskId='+data.d[i].TaskId+']';$(taskAreaId).removeClass('taskNone');$(taskAreaId).addClass('taskAssigned');}}
function cancelAssignTask(){$('#assignTaskDlg').slideUp('fast');return false;}