
$("document").ready(function(){$("#txtNewUsers").keypress(function(e){txtNewUsers_KeyPress(e);});$("#btnAddUsers").click(function(){btnAddUsers_Click();});$(".memberEdit").live("click",function(e){editMember(e);});$(".memberDelete").live("click",function(e){confirmDeleteMember(e);});$(".reposAccessOk").live("click",function(e){reposAccessOk_Click(e);});$(".reposAccessCancel").live("click",function(e){reposAccessCancel_Click(e);});setupEventHandlers();$("#dialog").dialog({autoOpen:false,bgiframe:true,resizable:false,height:140,modal:true,overlay:{backgroundColor:'#000',opacity:0.5},buttons:{Cancel:function(){$(this).dialog('close');},'Ok':function(){$(this).dialog('close');deleteMember();}}});});function setupEventHandlers(){$(".memberDetailContainer").hover(function(){$(".memberDetailIcons",$(this)).fadeTo("fast",1);},function(){$(".memberDetailIcons",$(this)).fadeTo("fast",.3);});}
var txtNewUsersExpanded=false;function txtNewUsers_KeyPress(e){if((e.which==59)||(e.which==32)||(e.which==44)){if(!txtNewUsersExpanded){$("#txtNewUsers").animate({rows:"10"},"normal","linear",null);txtNewUsersExpanded=true;}}}
var memberAccess;function btnAddUsers_Click(){newUserAccessString=$("input:radio:checked",".newUsersAccessOptions").val();memberAccess=newUserAccessString.substring(newUserAccessString.indexOf('_')+1);$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{'emailString':'"+$("#txtNewUsers").val()+"', 'access':"+memberAccess+"}",url:_reposRoot+'/ProcessDefinition.asmx/AddUsers',success:function(data){usersAdded(data);}});}
function usersAdded(data){var newMembers="";for(var member in data.d.Users){$("div.memberDetailContainer[u='"+data.d.Users[member].UserId+"']").slideUp("slow",function(){$(this).remove();});var newMember="<div class='memberDetailContainer' u='"+data.d.Users[member].UserId+"'><div class='memberDetail memberDetailImage avatar'>"
newMember+="<img src='"+data.d.Users[member].GravatarUrl+"' width='40px' height='40px' />";newMember+="</div>";newMember+="<div class='memberDetail memberDetailDetails'>";newMember+="<p> <strong>"+data.d.Users[member].Name+"</strong></p>";newMember+="<p> "+data.d.Users[member].Email+"</p>";newMember+="</div>";newMember+="<div class='memberDetail memberDetailIcons'>";newMember+="<span class='memberEdit ui-icon ui-icon-pencil'></span><span class='memberDelete ui-icon ui-icon-trash'>";newMember+="</span>";newMember+="</div>";newMember+="<br class='clear' />";newMember+="<div class='memberDetailAccessOptions'>";newMember+="<div class='reposAccessOptions'>";newMember+="<p class='reposAccessOption'>Access Level:</p>";var uid=data.d.Users[member].UserId;newMember+="<span class='reposAccessOption adminAccess'><input id='ctl00_ContentBody_rmlAdmins_lvMembers_ctrl0_admin_4_"+uid+"' type='radio' name='ctl00$ContentBody$rmlAdmins$lvMembers$ctrl0$accessOptions_1_"+uid+"' value='admin_4' checked='checked' /><label for='ctl00_ContentBody_rmlAdmins_lvMembers_ctrl0_admin_4_"+uid+"'>Admin</label></span>";newMember+="<span class='reposAccessOption authorAccess'><input id='ctl00_ContentBody_rmlAdmins_lvMembers_ctrl0_author_3_"+uid+"' type='radio' name='ctl00$ContentBody$rmlAdmins$lvMembers$ctrl0$accessOptions_1_"+uid+"' value='author_3' /><label for='ctl00_ContentBody_rmlAdmins_lvMembers_ctrl0_author_3_"+uid+"'>Author</label></span>";newMember+="<span class='reposAccessOption commentAccess'><input id='ctl00_ContentBody_rmlAdmins_lvMembers_ctrl0_comment_2_"+uid+"' type='radio' name='ctl00$ContentBody$rmlAdmins$lvMembers$ctrl0$accessOptions_1_"+uid+"' value='comment_2' /><label for='ctl00_ContentBody_rmlAdmins_lvMembers_ctrl0_comment_2_"+uid+"'>Comment</label></span>";newMember+="<p class='reposAccessOption reposAccessOk'><span class='ui-icon ui-icon-circle-check' title='Ok'></span></p>";newMember+="<p class='reposAccessOption reposAccessCancel'><span class='ui-icon ui-icon-circle-close' title='Cancel'></span></p>";newMember+="<br class='clear' />";newMember+="</div>";newMember+="</div></div>";newMembers+=newMember;}
var newMembersObject=$(newMembers);var containerClassName="";switch(memberAccess)
{case"2":containerClassName="Readers";break;case"3":containerClassName="Authors";break;case"4":containerClassName="Admins";break;}
newMembersObject.hide();$(".newMembers",$("."+containerClassName)).append(newMembersObject);newMembersObject.slideDown("slow");$("#txtNewUsers").val("");setupEventHandlers();}
function editMember(e){var container=$($(e.target)[0].parentNode.parentNode);var containerT=$($(e.target)[0].parentNode.parentNode.parentNode);if(containerT.hasClass("newMembers"))
containerT=containerT.parent();if(containerT.hasClass("Readers")){$(".memberDetailAccessOptions input[value='comment_2']",container).attr('checked','checked');}
else if(containerT.hasClass("Authors")){$(".memberDetailAccessOptions input[value='author_3']",container).attr('checked','checked');}
else if(containerT.hasClass("Admins")){$(".memberDetailAccessOptions input[value='admin_4']",container).attr('checked','checked');}
$(".memberDetailAccessOptions",container).slideToggle("fast");}
var movedMember;var movedTo;function reposAccessOk_Click(e)
{var okSpan;if(e.target.nodeName=='SPAN')
okSpan=$(e.target)[0].parentNode;else
okSpan=$(e.target)[0];var userId=$(okSpan.parentNode.parentNode.parentNode).attr("u");var memberAccess=$("input:radio:checked",$(okSpan.parentNode)).val();memberAccess=memberAccess.substring(memberAccess.indexOf('_')+1);movedTo=memberAccess;movedMember=$(okSpan.parentNode.parentNode.parentNode);$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{'userId':"+userId+", 'memberRole':"+memberAccess+"}",url:_reposRoot+'/ProcessDefinition.asmx/ChangeUserRepositoryAccess',success:function(){memberAccessChanged();}});}
function reposAccessCancel_Click(e)
{var okSpan;if(e.target.nodeName=='SPAN')
okSpan=$(e.target)[0].parentNode;else
okSpan=$(e.target)[0];$(okSpan.parentNode.parentNode).slideUp("fast");}
function memberAccessChanged()
{$(".memberDetailAccessOptions",$(movedMember)).slideUp("fast");$(movedMember).slideUp("normal",function()
{if(movedTo!="0")
{var containerClassName="";switch(movedTo)
{case"2":containerClassName="Readers";break;case"3":containerClassName="Authors";break;case"4":containerClassName="Admins";break;}
$(".newMembers",$("."+containerClassName)).append($(movedMember));$(movedMember).slideDown("normal");}});}
var userIdToRemove="";var containerToRemove;function confirmDeleteMember(e){containerToRemove=$($(e.target)[0].parentNode.parentNode);userIdToRemove=containerToRemove.attr("u");$("#dialog").dialog("open");}
function deleteMember(){$.ajax({type:'POST',contentType:"application/json; charset=utf-8",dataType:"json",data:"{'userId':"+userIdToRemove+", 'memberRole':0}",url:_reposRoot+'/ProcessDefinition.asmx/ChangeUserRepositoryAccess',success:function(){containerToRemove.slideUp("normal");}});}