Your IP : 3.141.190.247
(function(){"use strict";BX.namespace("BX.Intranet");if(!!BX.Intranet.UserFieldEmployee){return}var e={};var t={};BX.Intranet.UserFieldEmployee=function(t,i){this.id=t;this.param=i;this.inited=false;this.callback={select:BX.delegate(this.callbackSelect,this),unSelect:BX.delegate(this.callbackUnSelect,this)};this.value=this.param.multiple?[]:null;e[t]=this;BX.ready(BX.defer(this.init,this))};BX.Intranet.UserFieldEmployee.instance=function(t){return e[t]};BX.Intranet.UserFieldEmployee.getInitEvent=function(e){return"BX.UFEMP:"+e+":init"};BX.Intranet.UserFieldEmployee.getOpenEvent=function(e){return"BX.UFEMP:"+e+":open"};BX.Intranet.UserFieldEmployee.prototype.init=function(){if(!!BX.Main.selectorManagerV2.controls[this.id]){var e=BX.UI.SelectorManager.instances[this.id];if(e){e.reinit()}}BX.onCustomEvent(window,BX.Intranet.UserFieldEmployee.getInitEvent(this.id),[{id:this.id,openDialogWhenInit:false}]);this.inited=true};BX.Intranet.UserFieldEmployee.prototype.open=function(e){BX.onCustomEvent(window,BX.Intranet.UserFieldEmployee.getOpenEvent(this.id),[{id:this.id}]);return false};BX.Intranet.UserFieldEmployee.prototype.close=function(){var e=BX.UI.SelectorManager.instances[this.id];if(!e){return}if(e.popups.main){e.popups.main.close()}if(e.popups.search){e.popups.main.search.close()}if(e.popups.container){e.popups.container.close()}};BX.Intranet.UserFieldEmployee.prototype.storeUser=function(e){e.name=BX.util.htmlspecialcharsback(e.name);t[e.entityId]=e};BX.Intranet.UserFieldEmployee.prototype.setValue=function(e){this.value=e;var t=BX.UI.SelectorManager.instances[this.id];if(t){t.itemsSelected={}}this.updateValue()};BX.Intranet.UserFieldEmployee.prototype.callbackSelect=function(e){var t=e.selectorId,i=e.item;if(!BX.type.isNotEmptyString(t)||t!=this.id||!BX.type.isNotEmptyObject(i)){return}var s=i.entityId;this.storeUser(i);if(this.param.multiple){this.value.push(s)}else{this.value=s;this.close()}this.updateValue()};BX.Intranet.UserFieldEmployee.prototype.callbackUnSelect=function(e){var t=e.selectorId,i=e.item;if(!BX.type.isNotEmptyString(t)||t!=this.id||!BX.type.isNotEmptyObject(i)){return}var s=i.entityId;this.storeUser(i);if(this.param.multiple){var n=BX.util.array_search(s,this.value);if(n>=0){this.value.splice(n,1)}}else if(this.value===s){this.value=null;this.close()}this.updateValue()};BX.Intranet.UserFieldEmployee.prototype.updateValue=function(){if(this.inited){var e=BX.UI.SelectorManager.instances[this.id];if(e){if(this.param.multiple){this.value=BX.util.array_unique(this.value);for(var i=0;i<this.value.length;i++){e.itemsSelected["U"+this.value[i]]="users"}}else{if(this.value!==null){e.itemsSelected["U"+this.value]="users"}}}}BX.onCustomEvent(this,"onUpdateValue",[this.value,t])};BX.Intranet.UserFieldEmployeeEntity=function(e){this.field=null;this.squareClass="main-ui-square";this.multiple=null;if(!!e){if(e.field){this.setField(e.field)}if(typeof e.multiple!=="undefined"){this.multiple=e.multiple}}};BX.Intranet.UserFieldEmployeeEntity.prototype={setField:function(e){if(this.field!==BX(e)){this.field=BX(e);this.reset();BX.bind(this.field,"click",BX.proxy(this._fieldClick,this))}},_fieldClick:function(e){e=e||window.event;if(BX.hasClass(e.target,"main-ui-square-delete")){this.remove(e.target.parentNode)}},remove:function(e){BX.remove(e);BX.onCustomEvent(this,"BX.Intranet.UserFieldEmployeeEntity:remove",[this.getCurrentValues()])},isMultiple:function(){return this.multiple},reset:function(){},getField:function(){return this.field},getSquares:function(){return i(this.getField(),this.squareClass,true)},removeSquares:function(){this.getSquares().forEach(BX.remove)},setSquare:function(e,t){var i=this.getField();var s={block:"main-ui-square",name:e,item:{_label:e,_value:t}};var n=BX.decl(s);var l=this.getSquares();if(!l.length){BX.prepend(n,i)}else{BX.insertAfter(n,l[l.length-1])}},getCurrentValues:function(){var e=this.getSquares();var t,i=[];try{for(var s=0;s<e.length;s++){t=JSON.parse(BX.data(e[s],"item"));i.push({label:t._label,value:t._value})}}catch(e){i=[{label:"",value:""}]}return i},setData:function(e,t){return this.isMultiple()?this.setMultipleData(e):this.setSingleData(e,t)},setSingleData:function(e,t){this.removeSquares();this.setSquare(e,t)},setMultipleData:function(e){var t=[];if(BX.type.isArray(e)){this.removeSquares();if(BX.type.isArray(e)){e.forEach(function(e){t.push(e.value);this.setSquare(e.label,e.value)},this)}}}};function i(e,t,i){var s=[];if(t){s=(e||document.body).getElementsByClassName(t);if(!i){s=s.length?s[0]:null}else{s=[].slice.call(s)}}return s}})();
//# sourceMappingURL=userfieldemployee.map.js