!function(a,b){"use strict";function c(a,c){var d=this;c=b.extend({chooseText:ccmi18n.chooseUser,loadingText:ccmi18n.loadingText,inputName:"uID",uID:0},c),d.$element=a,d.options=c,d._chooseTemplate=_.template(d.chooseTemplate,{options:d.options}),d._loadingTemplate=_.template(d.loadingTemplate),d._userLoadedTemplate=_.template(d.userLoadedTemplate),d.$element.append(d._chooseTemplate),d.$element.on("click","a[data-user-selector-link=choose]",function(a){a.preventDefault(),b.fn.dialog.open({title:ccmi18n.chooseUser,href:CCM_DISPATCHER_FILENAME+"/ccm/system/dialogs/user/search",width:"90%",modal:!0,height:"70%",onOpen:function(){ConcreteEvent.unsubscribe("UserSearchDialogSelectUser.core"),ConcreteEvent.subscribe("UserSearchDialogSelectUser.core",function(a,b){d.loadUser(b.uID)})}})}),d.options.uID&&d.loadUser(d.options.uID),ConcreteEvent.unsubscribe("UserSearchDialogAfterSelectUser.core"),ConcreteEvent.subscribe("UserSearchDialogAfterSelectUser.core",function(a){jQuery.fn.dialog.closeTop()})}c.prototype={chooseTemplate:'<div class="ccm-item-selector"><input type="hidden" name="<%=options.inputName%>" value="0" /><a href="#" data-user-selector-link="choose"><%=options.chooseText%></a></div>',loadingTemplate:'<div class="ccm-item-selector"><div class="ccm-item-selector-choose"><input type="hidden" name="<%=options.inputName%>" value="<%=uID%>"><i class="fa fa-spin fa-spinner"></i> <%=options.loadingText%></div></div>',userLoadedTemplate:'<div class="ccm-item-selector"><div class="ccm-item-selector-item-selected"><input type="hidden" name="<%=inputName%>" value="<%=user.uID%>" /><div class="ccm-item-selector-item-selected-thumbnail"><%=user.avatar%></div><a data-user-selector-action="clear" href="#" class="ccm-item-selector-clear"><i class="fa fa-close"></i></a><div class="ccm-item-selector-item-selected-title"><%=user.displayName%></div></div></div>',loadUser:function(a){var c=this;c.$element.html(c._loadingTemplate({options:c.options,uID:a})),b.ajax({type:"post",dataType:"json",url:CCM_DISPATCHER_FILENAME+"/ccm/system/user/get_json",data:{uID:a},error:function(a){ConcreteAlert.dialog(ccmi18n.error,ConcreteAjaxRequest.errorResponseToString(a))},success:function(a){var b=a.users[0];c.$element.html(c._userLoadedTemplate({inputName:c.options.inputName,user:b})),c.$element.on("click","a[data-user-selector-action=clear]",function(a){a.preventDefault(),c.$element.html(c._chooseTemplate)})}})}},b.fn.concreteUserSelector=function(a){return b.each(b(this),function(d,e){new c(b(this),a)})},a.ConcreteUserSelector=c}(this,jQuery);