var XWiki=(function defineUserPicker(e){var b=e.widgets;if(!b||!b.SuggestPicker){var c=arguments[1]||0;if(c>5){console.error("Failed to define the UserPicker module: required dependency SuggestPicker is missing.")}else{setTimeout(defineUserPicker.bind(window,e,c+1),0)}return e}var a=Class.create(b.SuggestPicker,{matchesSelectedValue:function(g,f){return e.Model.resolve(g,e.EntityType.DOCUMENT).name==f.id},getDefaultSuggestion:function(g){var f=e.Model.resolve(g,e.EntityType.DOCUMENT);return{id:f.name,value:g,info:f.name,icon:"$xwiki.getSkinFile('icons/xwiki/noavatar.png')"}},addItem:function($super,f){this.input.hasClassName("multipleSelection")||this.list.update("");$super(f)},displayItem:function(f){var g=this.suggest.createItemDisplay(f,{});g.down(".user-name").insert(this.createDeleteTool());return new Element("li").insert(g).insert(this.createItemInput(f))}});b.UserPicker=Class.create(b.Suggest,{initialize:function($super,f,g){$super(f,Object.extend({varname:"input",enableHideButton:false,timeout:30000},g||{}));var h=f;if(f.hasClassName("withScope")&&!f.hasClassName("global")){this._sourceURL=g.script;this._createScope();h=f.up()}this._selectionManager=this._createSelectionManager({listInsertionElement:h,listInsertionPosition:"before",acceptFreeText:true});this.multipleSelection=f.hasClassName("multipleSelection");if(f.id!=""){b.UserPicker.instances[f.id]=this}},createItemDisplay:function(k,j){var f=new Element("div",{"class":"user"});var g=new Element("div",{"class":"user-avatar-wrapper"});g.insert(new Element("img",{src:k.icon,alt:k.info,"class":"icon"}));f.insert(g);var i=j.highlight?this.emphasizeMatches(this.sInput,k.info):k.info;f.insert(new Element("div",{"class":"user-name"}).update(i));var h=j.highlight?this.emphasizeMatches(this.sInput,k.id):k.id;f.insert(new Element("div",{"class":"user-alias"}).update(h));return f},clear:function(){this.fld.clear();this._selectionManager.clearAcceptedList()},_createSelectionManager:function(f){return new a(this.fld,this,f)},_createScope:function(){this._scope=new Element("input",{type:"image","class":"scope",alt:"$services.localization.render('core.widgets.userPicker.scopeHint')",title:"$services.localization.render('core.widgets.userPicker.scopeHint')"});var f=new Element("span").insert(this._scope);this.fld.insert({before:f});f.insert(this.fld);this._scope.observe("click",this._toggleScope.bindAsEventListener(this));this._toggleScope()},_toggleScope:function(f){f&&f.stop();if(this._scope.value=="local"){this._scope.value="global";this._scope.src="$xwiki.getSkinFile('icons/silk/world.png')"}else{this._scope.value="local";this._scope.src="$xwiki.getSkinFile('icons/silk/world_delete.png')"}this.sources[0].script=this._sourceURL+"wiki="+this._scope.value+"&"},detach:function($super){this._selectionManager&&this._selectionManager.detach();this._scope&&this._scope.stopObserving("click").up().insert({before:this.fld}).remove();$super()}});b.UserPicker.instances={};var d=function(f){var h={users:{script:e.currentDocument.getURL("get","xpage=uorgsuggest&uorg=user&"),noresults:"$services.localization.render('core.widgets.userPicker.noResults')"},groups:{script:e.currentDocument.getURL("get","xpage=uorgsuggest&uorg=group&"),noresults:"$services.localization.render('core.widgets.groupPicker.noResults')"}};var g=(f&&f.memo.elements)||[$("body")];Object.keys(h).each(function(i){g.each(function(j){j.select("input.suggest"+i.capitalize()).each(function(k){if(!k.hasClassName("initialized")){var l=Object.clone(h[i]);if(k.hasClassName("global")){l.script=l.script+"wiki=global&"}new b.UserPicker(k,l);k.addClassName("initialized")}})})});return true};(e.domIsLoaded&&d())||document.observe("xwiki:dom:loaded",d);document.observe("xwiki:dom:updated",d);return e})(XWiki||{});