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')"}},acceptSuggestion:function(f){if(!this.list.down('input[value="'+f.value+'"]')){this.addItem(f)}this.input.value=""},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))},createItemInput:function(f){return new Element("input",{type:"hidden",name:this.inputName,value:f.value})}});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(j,f){var h=new Element("div",{"class":"user"});var m=new Element("div",{"class":"user-avatar-wrapper"});m.insert(new Element("img",{src:j.icon,alt:j.info,"class":"icon"}));h.insert(m);var l=f.highlight?this.emphasizeMatches(this.sInput.escapeHTML(),j.info.escapeHTML()):j.info.escapeHTML();h.insert(new Element("div",{"class":"user-name"}).update(l));var i=new Element("div");var g=f.highlight?this.emphasizeMatches(this.sInput.escapeHTML(),j.id.escapeHTML()):j.id.escapeHTML();i.insert(new Element("span",{"class":"user-alias"}).update(g));var k=e.Model.resolve(j.value,e.EntityType.DOCUMENT);var n=k.extractReferenceValue(e.EntityType.WIKI)||e.currentWiki;if(n!=="$xcontext.mainWikiName"){i.insert(new Element("span",{"class":"user-wiki"}).update(n.escapeHTML()))}h.insert(i);return h},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||{});