if(atlassian===undefined){var atlassian={}}if(atlassian.jira===undefined){atlassian.jira={}}if(atlassian.jira.share===undefined){atlassian.jira.share={}}if(atlassian.jira.share.i18n===undefined){atlassian.jira.share.i18n={}}atlassian.jira.share.toggleElements=function(A,C){var B=document.getElementById(C);var D=document.getElementById(A);if(B&&D){B.style.display="none";D.style.display=""}};atlassian.jira.share.i18n.getMessage=function(A){if(this[A]){return this[A]}return"unknown"};atlassian.jira.share.i18n._formatMessage=function(F,A,E){var D,C;for(var B=0;B<E.length;B++){C=String(E[B]);if(A){C=A(C)}D=new RegExp("\\{"+B+"\\}","g");while(F.search(D)>=0){F=F.replace(D,C)}}return F};atlassian.jira.share.i18n.formatMessage=function(B){var A=Array.prototype.slice.call(arguments,1);return atlassian.jira.share.i18n._formatMessage(B,htmlEscape,A)};atlassian.jira.share.i18n.formatMessageUnescaped=function(B){var A=Array.prototype.slice.call(arguments,1);return atlassian.jira.share.i18n._formatMessage(B,null,A)};atlassian.jira.share.EditSharesController=function(A){this.shares=new Array();this.displayDiv=document.getElementById("share_display_div");this.emptyDiv=document.getElementById("empty_share");this.shareDiv=document.getElementById("share_div");this.submitButtonId=A;this.shareTypes={};this.counter=0;this.singleton=false;this.dirty=false};atlassian.jira.share.EditSharesController.prototype={registerShareType:function(A){if(!A||!A.type){return }this.shareTypes[String(A.type)]=A},initialise:function(){var C,I,M,F;for(I in this.shareTypes){M=this.shareTypes[I];YAHOO.util.Event.addListener("share_add_"+M.type,"click",this.addShareCallback,M,this);if(M.initialise){M.initialise(this.setDescription)}}var J=document.getElementById("shares_data"),E;try{E=JSON.parse(J.firstChild.nodeValue);if(!(E instanceof Array)){E=[]}}catch(B){E=[]}for(C=0;C<E.length;C++){if(E[C].type!==undefined){M=this.shareTypes[E[C].type];if(M){var H=M.getDisplayFromPermission(E[C]);if(H){this.addDisplay(H)}}}}if(this.shares.length==0){var A=this.emptyDiv.cloneNode(true);A.removeAttribute("id");A.style.display="";this.displayDiv.appendChild(A)}this.recalculateHiddenValue();F=document.getElementById("share_busy");if(F){F.style.display="none";if(F.parentNode){F.parentNode.removeChild(F)}}this.shareDiv.style.display="";YAHOO.util.Event.addListener("share_type_selector","change",this.selectShareTypeCallback,this,true);var G=document.getElementById("share_type_selector"),L=G.options;var K=L[G.selectedIndex].value;document.getElementById("share_"+K).style.display="";var D=this.shareTypes[K];this.setDescription(D.getDisplayDescriptionFromUI());if(this.submitButtonId){YAHOO.util.Event.addListener(this.submitButtonId,"click",this.saveCallback,this,true)}},addDisplay:function(I){if(!I){return }var F=this.findShare(I.permission);if(F>=0){this.animateShare(F);return }var G=this.counter++,B=null;if(I.singleton){if(this.shares.length!=0){var E=confirm(atlassian.jira.share.i18n.getMessage("common.sharing.remove.shares"));if(!E){return }}B=this.clearDiv()}else{if(this.singleton){B=this.clearDiv()}else{if(this.shares.length==0){B=this.clearDiv()}}}if(!B){B=document.createElement("DIV")}else{while(B.firstChild){B.removeChild(B.firstChild)}}B.className="shareItem";B.id="share_div_"+G;var D=document.createElement("DIV");D.id="share_div_"+G+"_inner";D.title=I.description;var C=this.cloneImage("share_icon");if(C){D.appendChild(C)}var H=document.createElement("SPAN");H.innerHTML=I.display;D.appendChild(H);var A=this.cloneImage("share_trash");if(A){YAHOO.util.Event.addListener(A,"click",this.removeCallback,G,this);D.appendChild(A)}B.appendChild(D);this.singleton=I.singleton;this.displayDiv.appendChild(B);this.shares.push({id:G,permission:I.permission});this.recalculateHiddenValue()},cloneImage:function(B){var A=document.getElementById(B);if(A){A=A.cloneNode(true);A.removeAttribute("id");A.style.display=""}return A},findShare:function(A){for(var B=0;B<this.shares.length;B++){if(A.equals(this.shares[B].permission)){return this.shares[B].id}}return -1},selectShareTypeCallback:function(){var E=document.getElementById("share_type_selector"),B=E.options,G;for(var D=0;D<B.length;D++){var C=document.getElementById("share_"+B[D].value);if(C){if(D==E.selectedIndex){G=C}else{C.style.display="none"}}}G.style.display="";var F=B[E.selectedIndex].value;var A=this.shareTypes[F];this.setDescription(A.getDisplayDescriptionFromUI());this.dirty=true},saveCallback:function(B){if(this.dirty){var A=this.getCurrentShareType();if(A){var C=A.getDisplayFromUI();if(C&&C.permission&&this.findShare(C.permission)<0){if(!confirm(atlassian.jira.share.i18n.getMessage("common.sharing.dirty.warning"))){YAHOO.util.Event.preventDefault(B)}}}}},addShareCallback:function(A,B){this.addDisplay(B.getDisplayFromUI())},removeCallback:function(A,B){this.remove(B)},remove:function(C){for(var A=0;A<this.shares.length;A++){if(this.shares[A].id==C){this.shares.splice(A,1);break}}var B=document.getElementById("share_div_"+C);if(this.shares.length>=1){this.displayDiv.removeChild(B)}else{B.innerHTML=this.emptyDiv.innerHTML;B.className=this.emptyDiv.className;B.removeAttribute("id")}this.recalculateHiddenValue()},clearDiv:function(){this.shares=new Array();var A=null;while(!A&&this.displayDiv.firstChild){if(this.displayDiv.firstChild.nodeName.toLowerCase()=="div"){A=this.displayDiv.firstChild}else{this.displayDiv.removeChild(this.displayDiv.firstChild)}}if(A){while(A.nextSibling){this.displayDiv.removeChild(A.nextSibling)}}return A},setDescription:function(B){var A=document.getElementById("share_type_description");if(A){A.innerHTML=B}},recalculateHiddenValue:function(){var C=document.getElementById("share_type_hidden");if(C){var B=new Array();for(var A=0;A<this.shares.length;A++){B.push(this.shares[A].permission)}C.value=JSON.stringify(B)}},animateShare:function(B){var E=document.getElementById("share_div_"+B+"_inner");if(E){var A=E.parentNode;var D=null;while(!D&&A&&A!=document.body.parentNode){if(A.style){D=A.style.backgroundColor}if(!D&&A.bgColor){D=A.bgColor}A=A.parentNode}if(!D){D="#FFF"}var C=new YAHOO.util.ColorAnim(E,{backgroundColor:{from:"#FFCCCC",to:D}},1);C.animate()}},getCurrentShareType:function(){var A=document.getElementById("share_type_selector");if(A){return this.shareTypes[A.options[A.selectedIndex].value]}else{return null}}};atlassian.jira.share.SelectSingleShareTypeController=function(){this.shares=new Array();this.shareTypes={};this.singleton=false};atlassian.jira.share.SelectSingleShareTypeController.prototype={registerShareType:function(A){if(!A||!A.type){return }this.shareTypes[String(A.type)]=A},initialise:function(){var G,J;for(G in this.shareTypes){J=this.shareTypes[G];if(J.initialise){J.initialise(this.setDescription)}}var I=document.getElementById("shares_data"),D;try{var B=I.firstChild.nodeValue;D=JSON.parse(B);if(!(D instanceof Array)){D=[]}}catch(F){D=[]}var H=null;var C=null;if(D.length==0){H="any";J=this.shareTypes[H];C=null}else{H=D[0].type;J=this.shareTypes[H];C=D[0]}if(J.updateSelectionFromPermission){J.updateSelectionFromPermission(C)}var E=document.getElementById("share_type_selector");if(E){this.updateShareTypeSelectorList(E,H);this.setDescription(J.getDisplayDescriptionFromUI());YAHOO.util.Event.addListener(E,"change",this.selectShareTypeCallback,this,true)}var A=document.getElementById("share_busy");if(A){A.style.display="none";if(A.parentNode){A.parentNode.removeChild(A)}}A=document.getElementById("share_div");if(A){A.style.display=""}},updateShareTypeSelectorList:function(F,G){var C=F.options;var B=0;for(var D=0;D<C.length;D++){var A=C[D].value;if(A==G){B=D}document.getElementById("share_"+A).style.display="none"}C[B].selected=true;var E=document.getElementById("share_"+C[B].value);if(E){E.style.display=""}},selectShareTypeCallback:function(){var E=document.getElementById("share_type_selector"),A=E.options,G;for(var D=0;D<A.length;D++){var C=document.getElementById("share_"+A[D].value);if(C){if(D==E.selectedIndex){G=C}else{C.style.display="none"}}}G.style.display="";var F=A[E.selectedIndex].value;var B=this.shareTypes[F];this.setDescription(B.getDisplayDescriptionFromUI())},setDescription:function(B){var A=document.getElementById("share_type_description");if(A){A.innerHTML=B}}};atlassian.jira.share.GlobalShare=function(){this.type="global";this.singleton=true};atlassian.jira.share.GlobalShare.prototype={getDisplayFromUI:function(){var B=new atlassian.jira.share.SharePermission(this.type,null,null);var A=atlassian.jira.share.i18n.getMessage("share_global_display");return new atlassian.jira.share.Display(A,this.getDisplayDescriptionFromUI(),this.singleton,B)},getDisplayDescriptionFromUI:function(){return atlassian.jira.share.i18n.getMessage("share_global_description")},getDisplayFromPermission:function(A){if(!A||A.type!=this.type){return null}var C=new atlassian.jira.share.SharePermission(this.type,null,null);var B=atlassian.jira.share.i18n.getMessage("share_global_display");return new atlassian.jira.share.Display(B,this.getDisplayDescriptionFromUI(),this.singleton,C)}};atlassian.jira.share.GroupShare=function(){this.type="group";this.singleton=false};atlassian.jira.share.GroupShare.prototype={initialise:function(A){this.setDescription=A;this.groupSelect=document.getElementById("groupShare");if(this.groupSelect){YAHOO.util.Event.addListener(this.groupSelect,"change",this.groupChangeCallback,this,true)}},getDisplayFromUI:function(){if(!this.groupSelect){return }var A=this.groupSelect.options[this.groupSelect.selectedIndex].value;var B=new atlassian.jira.share.SharePermission(this.type,A,null);return new atlassian.jira.share.Display(this.getDisplayString(A),this.getDescriptionString(A,true),this.singleton,B)},getDisplayDescriptionFromUI:function(){if(!this.groupSelect){return }var A=this.groupSelect.options[this.groupSelect.selectedIndex].value;return this.getDescriptionString(A,false)},getDisplayFromPermission:function(A){if(!A||A.type!=this.type||!A.param1){return null}var B=new atlassian.jira.share.SharePermission(this.type,A.param1,null);return new atlassian.jira.share.Display(this.getDisplayString(B.param1),this.getDescriptionString(A.param1,true),this.singleton,B)},getDisplayString:function(B){var A=atlassian.jira.share.i18n.getMessage("share_group_display");return atlassian.jira.share.i18n.formatMessage(A,B)},getDescriptionString:function(C,B){var A=atlassian.jira.share.i18n.getMessage("share_group_description");if(B){return atlassian.jira.share.i18n.formatMessageUnescaped(A,C)}else{return atlassian.jira.share.i18n.formatMessage(A,C)}},updateSelectionFromPermission:function(B){if(!this.groupSelect){return }var D=B.param1;var A=this.groupSelect.options;for(var C=0;C<A.length;C++){if(A[C].value==D){A[C].selected=true}}},groupChangeCallback:function(){if(this.setDescription){this.setDescription(this.getDisplayDescriptionFromUI())}}};atlassian.jira.share.ProjectShare=function(){this.roleMap={};this.projectMap={};this.type="project";this.singleton=false};atlassian.jira.share.ProjectShare.prototype={initialise:function(A){this.setDescription=A;this.projectSelect=document.getElementById("projectShare-project");this.roleSelect=document.getElementById("projectShare-role");this.roleSelectGroup=document.getElementById("projectShare-role-group");if(!this.roleSelect||!this.projectSelect||!this.roleSelectGroup){return }var C,B;for(B=1;B<this.roleSelect.options.length;B++){C=this.roleSelect.options[B];this.roleMap[C.value]=C.text}for(B=0;B<this.projectSelect.options.length;B++){C=this.projectSelect.options[B];this.projectMap[C.value]=C.text}this.setRoles();YAHOO.util.Event.addListener(this.projectSelect,"change",this.changeCallbackForProject,this,true);YAHOO.util.Event.addListener(this.roleSelect,"change",this.updateDescription,this,true)},getDisplayFromUI:function(){if(!this.projectSelect||!this.roleSelect){return }var H=this.projectSelect.options[this.projectSelect.selectedIndex];var G=H.value;var E=H.text;var D=this.roleSelect.options[this.roleSelect.selectedIndex];var A=D.value;var C=D.text;var B;if(A==""){B=atlassian.jira.share.i18n.getMessage("share_project_display_all");B=atlassian.jira.share.i18n.formatMessage(B,E)}else{B=atlassian.jira.share.i18n.getMessage("share_project_display");B=atlassian.jira.share.i18n.formatMessage(B,E,C)}var F=new atlassian.jira.share.SharePermission(this.type,G,A);return new atlassian.jira.share.Display(B,this.getDescriptionString(E,A,C,true),this.singleton,F)},getDisplayDescriptionFromUI:function(){if(!this.projectSelect||!this.roleSelect){return }var E=this.projectSelect.options[this.projectSelect.selectedIndex];var D=E.text;var C=this.roleSelect.options[this.roleSelect.selectedIndex];var A=C.value;var B=C.text;return this.getDescriptionString(D,A,B,false)},getDescriptionString:function(E,A,C,D){var B;if(!A||A==""){A=null;B=atlassian.jira.share.i18n.getMessage("share_project_description");if(D){B=atlassian.jira.share.i18n.formatMessageUnescaped(B,E)}else{B=atlassian.jira.share.i18n.formatMessage(B,E)}}else{B=atlassian.jira.share.i18n.getMessage("share_role_description");if(D){B=atlassian.jira.share.i18n.formatMessageUnescaped(B,C,E)}else{B=atlassian.jira.share.i18n.formatMessage(B,C,E)}}return B},getDisplayFromPermission:function(B){var D,F,E,C,A;if(!B||B.type!=this.type||!B.param1){return null}if(B.param2){C=this.getProject(B.param1);A=this.getRole(B.param2);D=atlassian.jira.share.i18n.getMessage("share_project_display");D=atlassian.jira.share.i18n.formatMessage(D,C,A);F=new atlassian.jira.share.SharePermission(this.type,B.param1,B.param2);E=this.getDescriptionString(C,B.param2,A,true)}else{C=this.getProject(B.param1);D=atlassian.jira.share.i18n.getMessage("share_project_display_all");D=atlassian.jira.share.i18n.formatMessage(D,C);F=new atlassian.jira.share.SharePermission(this.type,B.param1,null);E=this.getDescriptionString(C,null,null,true)}return new atlassian.jira.share.Display(D,E,this.singleton,F)},changeCallbackForProject:function(){this.setRoles();this.updateDescription()},updateDescription:function(){if(this.setDescription){this.setDescription(this.getDisplayDescriptionFromUI())}},setProject:function(C){if(!this.projectSelect){return }var A=this.projectSelect.options;for(var B=0;B<A.length;B++){if(A[B].value==C){A[B].selected=true}}},setRoles:function(B){if(!this.projectSelect||!this.roleSelect||!this.roleSelectGroup){return }var E=this.projectSelect.options[this.projectSelect.selectedIndex];var F=E.getAttribute("roles");var A;if(F){try{A=JSON.parse(F);if(!A){A=[]}}catch(I){A=[]}}else{A=[]}if(this.roleSelectGroup.parentNode){this.roleSelect.removeChild(this.roleSelectGroup);this.roleSelectGroup=this.roleSelectGroup.cloneNode(false)}var G=null;if(A.length>0){for(var D=0;D<A.length;D++){var H=document.createElement("OPTION");H.appendChild(document.createTextNode(this.roleMap[A[D]]));var C=A[D];H.value=C;if(C==B){G=H}this.roleSelectGroup.appendChild(H)}this.roleSelect.appendChild(this.roleSelectGroup)}if(G){G.selected=true}},getProject:function(B){var A=this.projectMap[B];if(!A){A=atlassian.jira.share.i18n.getMessage("share_invalid_project");if(!A){A="[Invalid Project]"}}return A},getRole:function(B){var A=this.roleMap[B];if(!A){A=atlassian.jira.share.i18n.getMessage("share_invalid_role");if(!A){A="[Invalid Role]"}}return A},updateSelectionFromPermission:function(A){this.setProject(A.param1);this.setRoles(A.param2)}};atlassian.jira.share.AnyShare=function(){this.type="any";this.singleton=true};atlassian.jira.share.AnyShare.prototype={getDisplayDescriptionFromUI:function(){return atlassian.jira.share.i18n.getMessage("share_any_description")}};atlassian.jira.share.Display=function(D,B,C,A){this.display=D;this.singleton=C;this.permission=A;this.description=B};atlassian.jira.share.SharePermission=function(A,C,B){this.type=A;if(C){this.param1=C}if(B){this.param2=B}};atlassian.jira.share.SharePermission.prototype.equals=function(A){return this.type===A.type&&this.param1===A.param1&&this.param2===A.param2};atlassian.jira.share.registerEditShareTypes=function(B){var A=new atlassian.jira.share.EditSharesController(B);A.registerShareType(new atlassian.jira.share.GlobalShare());A.registerShareType(new atlassian.jira.share.GroupShare());A.registerShareType(new atlassian.jira.share.ProjectShare());YAHOO.util.Event.onDOMReady(A.initialise,A,true)};atlassian.jira.share.registerSelectShareTypes=function(){var A=new atlassian.jira.share.SelectSingleShareTypeController();A.registerShareType(new atlassian.jira.share.AnyShare());A.registerShareType(new atlassian.jira.share.GroupShare());A.registerShareType(new atlassian.jira.share.ProjectShare());YAHOO.util.Event.onDOMReady(A.initialise,A,true)};
