| Current Path : /var/www/amortar/data/www/a-mortar/bitrix/js/ui/selector/ |
| Current File : /var/www/amortar/data/www/a-mortar/bitrix/js/ui/selector/selector.min.js |
(function(){var t=window.BX;t.namespace("BX.UI");if(!!t.UI.Selector){return}t.UI.Selector=function(e){this.statuses={searchWaiterEnabled:false};this.manager=t.UI.SelectorManager;this.id=t.type.isNotEmptyString(e.id)?e.id:null;this.fieldName=t.type.isNotEmptyString(e.fieldName)?e.fieldName:null;this.tabs={list:{},selected:null};this.dialogGroups={};this.entities=t.type.isNotEmptyObject(e.entities)?e.entities:{};this.networkItems={};this.sortData={};this.itemsSelected=t.type.isNotEmptyObject(e.itemsSelected)?e.itemsSelected:{};this.itemsUndeletable=t.type.isNotEmptyObject(e.itemsUndeletable)?e.itemsUndeletable:[];this.options=t.type.isNotEmptyObject(e.options)?e.options:{};this.bindOptions=t.type.isNotEmptyObject(e.bindOptions)?e.bindOptions:{};this.bindOptions.forceBindPosition=true;this.popups={container:null,main:null,search:null,inviteEmailUser:null};this.nodes={input:t.type.isDomNode(e.input)?e.input:null,inputBox:t.type.isDomNode(e.inputBox)?e.inputBox:null,inputItemsContainer:t.type.isDomNode(e.inputItemsContainer)?e.inputItemsContainer:null,tag:t.type.isDomNode(e.tag)?e.tag:null,containerContentsContainer:null,searchContentsContainer:null,contentWaiter:null,searchWaiter:null};this.cursors={};this.result={search:[]};this.resultChanged={};this.tmpSearchResult={client:[],ajax:[]};this.callback=t.type.isNotEmptyObject(e.callback)?e.callback:{};this.searchXhr=null;this.searchRequestId=null;this.timeouts={search:null};this.dialogNodes={tabsContainer:null,contentsContainer:null};this.treeItemLoaded={};this.clientDBSearchResult={users:{}};this.ajaxSearchResult={users:{}};this.containerSearchResult={};this.searchInstance=null;this.navigationInstance=null;this.renderInstance=null;this.postponeSearch=false;var s=this.getOption("search");if(t.type.isNotEmptyString(s.useClientDatabase)&&s.useClientDatabase=="Y"){t.onCustomEvent("BX.UI.SelectorManager:initClientDatabase",[])}};t.UI.Selector.create=function(e){var s=new t.UI.Selector(e);t.UI.SelectorManager.instances[e.id]=s;return s};t.UI.Selector.prototype.getSearchInstance=function(){if(this.searchInstance===null){this.searchInstance=t.UI.Selector.Search.create({selectorInstance:this})}return this.searchInstance};t.UI.Selector.prototype.getNavigationInstance=function(){if(this.navigationInstance===null){this.navigationInstance=t.UI.Selector.Navigation.create({selectorInstance:this})}return this.navigationInstance};t.UI.Selector.prototype.getRenderInstance=function(){if(this.renderInstance===null){this.renderInstance=t.UI.Selector.Render.create({selectorInstance:this})}return this.renderInstance};t.UI.Selector.prototype.getPopupBind=function(){return t.type.isNotEmptyObject(this.bindOptions.position)?this.bindOptions.position:this.bindOptions.node};t.UI.Selector.prototype.openDialog=function(){if(this.getOption("useContainer")=="Y"){if(!this.openContainer()){return false}t.cleanNode(this.nodes.containerContentsContainer);this.nodes.containerContentsContainer.appendChild(this.getDialogContent());var e=null;for(var s in this.itemsSelected){if(this.itemsSelected.hasOwnProperty(s)){e=this.manager.convertEntityType(this.itemsSelected[s]);if(this.callback.select){this.callback.select({item:this.entities[e].items[s],entityType:e,selectorId:this.id,state:"init"})}}}this.popups.container.setAngle({});this.popups.container.setBindElement(this.getPopupBind());this.popups.container.show()}else{this.popups.main=new t.PopupWindow("bx-selector-dialog-"+this.id,this.getPopupBind(),{autoHide:true,zIndex:1200,className:this.getRenderInstance().class.popup,offsetLeft:this.bindOptions.offsetLeft,offsetTop:this.bindOptions.offsetTop,bindOptions:this.bindOptions,closeByEsc:true,closeIcon:this.getOption("showCloseIcon")=="Y"?{top:"12px",right:"15px"}:false,lightShadow:true,events:{onPopupShow:function(){if(this.manager.statuses.allowSendEvent&&this.callback.openDialog){this.callback.openDialog({selectorId:this.id})}if(this.popups.inviteEmailUser&&this.popups.inviteEmailUser.isShown()){this.popups.inviteEmailUser.close()}}.bind(this),onPopupClose:function(){if(this.popups.main){this.popups.main.destroy()}}.bind(this),onPopupDestroy:function(){this.popups.main=null;if(this.manager.statuses.allowSendEvent&&this.callback.closeDialog){this.callback.closeDialog({selectorId:this.id})}}.bind(this)},content:this.getDialogContent()});this.popups.main.setAngle({});this.popups.main.show()}if(this.getOption("enableLast")!="N"){this.tabs.selected="last"}if(this.getOption("enableLast")=="N"&&this.getOption("enableSonetgroups")!="Y"&&this.getOption("enableDepartments")=="Y"){this.switchTab({code:"departments"});if(this.getOption("useContainer")=="Y"){this.popups.container.adjustPosition()}else{this.popups.main.adjustPosition()}}this.getNavigationInstance().hoverFirstItem({tab:this.tabs.selected})};t.UI.Selector.prototype.openContainer=function(){this.popups.container=new t.PopupWindow("bx-selector-dialog-"+this.id+"-container",this.getPopupBind(),{autoHide:true,zIndex:1200,className:this.getRenderInstance().class.popup,offsetLeft:this.bindOptions.offsetLeft,offsetTop:this.bindOptions.offsetTop,bindOptions:this.bindOptions,closeByEsc:true,closeIcon:this.getOption("showCloseIcon")=="Y"?{top:0,right:0}:false,lightShadow:true,events:{onPopupShow:function(){if(this.manager.statuses.allowSendEvent&&this.callback.openDialog){this.callback.openDialog({selectorId:this.id})}if(this.popups.inviteEmailUser&&this.popups.inviteEmailUser.isShown()){this.popups.inviteEmailUser.close()}}.bind(this),onPopupClose:function(){if(this.popups.container){this.popups.container.destroy()}}.bind(this),onPopupDestroy:function(){this.popups.container=null;if(this.manager.statuses.allowSendEvent){if(this.callback.closeDialog){this.callback.closeDialog({selectorId:this.id})}if(this.callback.closeSearch){this.callback.closeSearch({selectorId:this.id})}}}.bind(this)},content:this.getContainerContent()});return true};t.UI.Selector.prototype.openSearch=function(e){if(this.popups.main!=null){this.popups.main.close()}if(this.popups.search!=null){this.popups.search.close();return false}if(this.getOption("useContainer")=="Y"){this.containerSearchResult=e.itemsList;if(this.nodes.searchContent){t.cleanNode(this.nodes.searchContent);var s=this.buildContentCollection({type:"search",items:e.itemsList});for(i=0;i<s.length;i++){this.nodes.searchContent.appendChild(s[i])}}else{t.cleanNode(this.nodes.searchContent);t(this.nodes.searchContent).appendChild(this.getSearchContent({itemsList:e.itemsList}))}this.switchTab({code:"search"});this.popups.container.setAngle({})}else{this.popups.search=new t.PopupWindow("bx-selector-dialog-"+this.id+"-search",this.getPopupBind(),{autoHide:true,zIndex:1200,className:this.getRenderInstance().class.popup,offsetLeft:this.bindOptions.offsetLeft,offsetTop:this.bindOptions.offsetTop,bindOptions:this.bindOptions,closeByEsc:true,closeIcon:false,lightShadow:true,events:{onPopupShow:function(){if(this.manager.statuses.allowSendEvent&&this.callback.openSearch){this.callback.openSearch({selectorId:this.id})}if(this.popups.inviteEmailUser&&this.popups.inviteEmailUser.isShown()){this.popups.inviteEmailUser.close()}}.bind(this),onPopupClose:function(){if(this.popups.search){this.popups.search.destroy()}}.bind(this),onPopupDestroy:function(){this.popups.search=null;this.getSearchInstance().abortSearchRequest();if(this.manager.statuses.allowSendEvent&&this.callback.closeSearch){this.callback.closeSearch({selectorId:this.id})}}.bind(this)},content:this.getSearchContent({itemsList:e.itemsList})});this.popups.search.setAngle({});this.popups.search.show()}this.getNavigationInstance().hoverFirstItem({tab:"search"})};t.UI.Selector.prototype.getDialogContent=function(){this.dialogNodes.tabsContainer=t.create("DIV",{props:{className:this.getRenderInstance().class.tabsContainer}});var e=null,s=0,i=[];for(var n in this.tabs.list){if(this.tabs.list.hasOwnProperty(n)){e=this.tabs.list[n];i.push({code:n,value:typeof e["sort"]!="undefined"&&parseInt(e["sort"])>0?parseInt(e["sort"]):100})}}if(this.getOption("useContainer")=="Y"&&!t.type.isNotEmptyObject(this.tabs.list["search"])){this.tabs.list["search"]={name:t.message("MAIN_UI_SELECTOR_SEARCH_TAB_TITLE")};i.push({code:"search",value:1e4})}i.sort(function(t,e){if(t.value<e.value){return-1}if(t.value>e.value){return 1}return 0});var a=[];var r=null;for(var o=0;o<i.length;o++){n=i[o].code;e=this.tabs.list[n];if(s===0){this.tabs.selected=n}r=t.create("A",{attrs:{hidefocus:"true","data-code":n},props:{className:this.getRenderInstance().class.tab+" "+this.getRenderInstance().class.tabLast+" "+(s==0?this.getRenderInstance().class.tabSelected:"")},events:{click:function(t){this.switchTab({code:t.target.getAttribute("data-code")});t.stopPropagation();return t.preventDefault()}.bind(this)},html:e.name});this.dialogNodes.tabsContainer.appendChild(r);a.push(this.buildContentNode({type:n}));s++}this.dialogNodes.contentsContainer=t.create("DIV",{props:{className:this.getRenderInstance().class.tabsContentContainer+" "+this.getRenderInstance().class.tabsContentContainerWindow},children:[t.create("TABLE",{props:{className:this.getRenderInstance().class.tabsContentContainerTable},children:[t.create("TR",{children:[t.create("TD",{props:{className:this.getRenderInstance().class.tabsContentContainerCell},children:a})]})]})]});var p=this.getOption("windowClass");return t.create("DIV",{style:{minWidth:"650px",paddingBottom:"8px"},props:{className:this.getRenderInstance().class.boxCommon+" "+this.getRenderInstance().class.boxContainer+" "+this.getRenderInstance().class.boxContainerVertical+" "+(p?p:this.getRenderInstance().class.boxDefault)},children:[this.dialogNodes.tabsContainer,this.dialogNodes.contentsContainer]})};t.UI.Selector.prototype.getContainerContent=function(){var e=this.getOption("windowClass"),s=null;this.nodes.containerContentsContainer=t.create("div",{props:{className:this.getRenderInstance().class.containerContent}});this.nodes.inputItemsContainer=t.create("SPAN",{attrs:{id:"bx-dest-internal-item"}});var i=t.create("DIV",{children:[t.create("DIV",{props:{className:this.getRenderInstance().class.boxCommon+" "+this.getRenderInstance().class.boxContainer+" "+this.getRenderInstance().class.boxContainerVertical+" "+(e?e:this.getRenderInstance().class.boxDefault)},style:{minWidth:"650px",paddingBottom:"8px",overflow:"hidden"},children:[t.create("DIV",{props:{className:this.getRenderInstance().class.containerSearchBlock},children:[t.create("DIV",{props:{className:this.getRenderInstance().class.containerSearchBlockCell},children:[this.nodes.inputItemsContainer,t.create("SPAN",{attrs:{id:"bx-dest-internal-input-box"},style:{display:"inline-block"},props:{className:this.getRenderInstance().class.containerSearchBlockInputBox},children:[this.getSearchInput()]})],events:{click:function(e){t.focus(this.nodes.input);return e.preventDefault()}.bind(this)}})]}),this.nodes.containerContentsContainer]})]});t.bind(this.nodes.input,"keydown",function(t){this.getSearchInstance().beforeSearchHandler({event:t})}.bind(this));t.bind(this.nodes.input,"keyup",function(t){this.getSearchInstance().searchHandler({event:t})}.bind(this));t.bind(this.nodes.input,"paste",function(t){this.getSearchInstance().searchHandler({event:t})}.bind(this));t.defer(t.focus)(this.nodes.input);return i};t.UI.Selector.prototype.getSearchInput=function(){this.nodes.input=t.create("INPUT",{attrs:{type:"text"},props:{className:this.getRenderInstance().class.containerSearchBlockInput}});return this.nodes.input};t.UI.Selector.prototype.getSearchContent=function(e){this.nodes.searchContentsContainer=t.create("DIV",{attrs:{},props:{className:this.getRenderInstance().class.tabsContentContainer+" "+this.getRenderInstance().class.tabsContentContainerWindow},children:[t.create("TABLE",{props:{className:this.getRenderInstance().class.tabsContentContainerTable},children:[t.create("TR",{children:[t.create("TD",{props:{className:this.getRenderInstance().class.tabsContentContainerCell},children:[this.buildContentNode({type:"search",items:e.itemsList})]})]})]})]});var s=this.getOption("windowClass");return t.create("DIV",{style:{minWidth:"650px",paddingBottom:"8px"},props:{className:this.getRenderInstance().class.boxCommon+" "+this.getRenderInstance().class.boxContainer+" "+this.getRenderInstance().class.boxContainerVertical+" "+(s?s:this.getRenderInstance().class.boxDefault)},children:[this.nodes.searchContentsContainer,this.getOption("useContainer")=="Y"?null:this.getSearchInstance().buildSearchWaiter()]})};t.UI.Selector.prototype.switchTab=function(e){var s=t.type.isNotEmptyString(e.code)?e.code:null;if(!s){return}var i=null,n=null;this.tabs.selected=s;var a=t.findChildren(this.dialogNodes.tabsContainer,{className:this.getRenderInstance().class.tab},true);if(a){for(i=0;i<a.length;i++){if(a[i].getAttribute("data-code")==s){a[i].classList.add(this.getRenderInstance().class.tabSelected)}else{a[i].classList.remove(this.getRenderInstance().class.tabSelected)}}}a=t.findChildren(this.dialogNodes.contentsContainer,{className:this.getRenderInstance().class.tabContent},true);if(a){for(i=0;i<a.length;i++){if(a[i].getAttribute("data-code")==s){t.cleanNode(a[i]);var r=this.buildContentCollection({type:s,items:s=="search"?this.containerSearchResult:null});for(n=0;n<r.length;n++){a[i].appendChild(r[n])}a[i].classList.add(this.getRenderInstance().class.tabContentSelected)}else{a[i].classList.remove(this.getRenderInstance().class.tabContentSelected)}}}this.getNavigationInstance().hoverFirstItem({tab:s});if(this.getOption("focusInputOnSwitchTab")!="N"){t.focus(this.input)}if(this.getOption("useContainer")=="Y"){this.popups.container.adjustPosition()}else{this.popups.main.adjustPosition()}};t.UI.Selector.prototype.setOption=function(e,s,i){if(!t.type.isNotEmptyString(i)){this.options[e]=s}else{i=i.toUpperCase();if(t.type.isNotEmptyObject(this.entities[i])){if(!t.type.isNotEmptyObject(this.entities[i].options)){this.entities[i].options={}}this.entities[i].options[e]=s}}};t.UI.Selector.prototype.getOption=function(e,s){if(!t.type.isNotEmptyString(s)){return typeof this.options[e]!="undefined"?this.options[e]:null}else{s=s.toUpperCase();return t.type.isNotEmptyObject(this.entities[s])&&t.type.isNotEmptyObject(this.entities[s].options)&&t.type.isNotEmptyString(this.entities[s].options[e])?this.entities[s].options[e]:null}};t.UI.Selector.prototype.buildContentNode=function(e){var s=e.type;var i=[this.tabs.selected];if(this.getOption("useContainer")!="Y"){i.push("search")}var n=[];if(t.util.in_array(s,i)){n=this.buildContentCollection(e)}var a=t.create("DIV",{attrs:{"data-code":s},props:{className:this.getRenderInstance().class.tabContent+" "+this.getRenderInstance().class.tabContentPrefix+s+" "+(t.util.in_array(s,[this.tabs.selected,"search"])?this.getRenderInstance().class.tabContentSelected:"")},children:n});if(s=="search"){this.nodes.searchContent=a}return a};t.UI.Selector.prototype.getItemsCodeList=function(t){var e=t.type,s=null;if(e=="last"){s=this.getLastItems()}else if(e=="search"){s=t.items}else{s=this.getEntityItems(this.entities[e.toUpperCase()])}return s};t.UI.Selector.prototype.buildContentCollection=function(e){var s=e.type,i=[],n=null,a=null,r=null;var o=this.getItemsCodeList(e);var p=t.util.in_array(s,["last","search"]);if(p){var c=[];for(var l in this.dialogGroups){if(this.dialogGroups.hasOwnProperty(l)){n=this.dialogGroups[l];c.push({code:l,value:typeof n.SORT!="undefined"&&parseInt(n.SORT)>0?parseInt(n.SORT):100})}}c.sort(function(t,e){if(t.value<e.value){return-1}if(t.value>e.value){return 1}return 0});var h={tab:s,group:0};for(r=0;r<c.length;r++){l=c[r].code;a=this.drawItemsGroup({groupCode:l,itemsCodeList:o,descLessMode:t.type.isNotEmptyString(this.dialogGroups[l].DESC_LESS_MODE)&&this.dialogGroups[l].DESC_LESS_MODE=="Y",navData:h});if(a){i.push(a)}}}else if(t.type.isNotEmptyObject(this.entities[s.toUpperCase()])){var d={type:s,itemsCodeList:o,descLessMode:t.type.isNotEmptyObject(this.entities[s.toUpperCase()].additionalData)&&t.type.isNotEmptyString(this.entities[s.toUpperCase()].additionalData.DESC_LESS_MODE)&&this.entities[s.toUpperCase()].additionalData.DESC_LESS_MODE=="Y"};if(t.type.isNotEmptyObject(this.entities[s.toUpperCase()].additionalData)&&t.type.isNotEmptyString(this.entities[s.toUpperCase()].additionalData.TYPE)&&this.entities[s.toUpperCase()].additionalData.TYPE=="tree"){var u=this.drawItemsTreeTabNode(d);for(r=0;r<u.length;r++){i.push(u[r])}}else{var m=this.drawItemsTab(d);if(m){i.push(m)}}}var f=false;if(i.length<=0){if(s=="search"){f=true;this.nodes.contentWaiter=t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxContent},html:t.message("MAIN_UI_SELECTOR_STUB_PLEASE_WAIT")});var y=t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBox+" "+this.getRenderInstance().class.groupBoxSearch},children:[this.nodes.contentWaiter]});if(this.getOption("useContainer")=="Y"&&this.nodes.input&&!t.type.isNotEmptyString(this.nodes.input.value)){this.nodes.contentWaiter.style.display="none"}i.push(y)}else{i.push(t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBox+" "+this.getRenderInstance().class.groupBoxSearch},children:[t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxContent},html:t.message("MAIN_UI_SELECTOR_STUB_EMPTY_LIST")})]}))}}if(typeof this.result[s]!="undefined"){this.cursors[s]={firstItem:!f?this.result[s][0][0][0]:null,currentItem:!f?this.result[s][0][0][0]:null,position:{group:0,row:0,column:0}}}return i};t.UI.Selector.prototype.getLastItems=function(){var e={};for(var s in this.entities){if(this.entities.hasOwnProperty(s)&&t.type.isArray(this.entities[s].itemsLast)){if(typeof e[s]=="undefined"){e[s]=[]}for(var i=0;i<this.entities[s].itemsLast.length;i++){if(t.util.in_array(this.entities[s].itemsLast[i],e[s])){continue}e[s].push(this.entities[s].itemsLast[i])}}}return e};t.UI.Selector.prototype.getEntityItems=function(e){var s=[];if(!t.type.isNotEmptyObject(e)){return s}for(var i in e.items){if(e.items.hasOwnProperty(i)){if(t.util.in_array(i,s)||t.type.isNotEmptyString(e.items[i].selectable)&&e.items[i].selectable=="N"){continue}s.push(i)}}return s};t.UI.Selector.prototype.drawItemsGroup=function(e){var s=null;var i=e.groupCode;var n=e.itemsCodeList;if(!i||!t.type.isNotEmptyObject(this.dialogGroups[i])){return s}var a=[],r,o,p,c=null;if(t.type.isNotEmptyObject(this.dialogGroups[i].TYPE_LIST)){var l=[];for(r in this.dialogGroups[i].TYPE_LIST){if(this.dialogGroups[i].TYPE_LIST.hasOwnProperty(r)){p=this.dialogGroups[i].TYPE_LIST[r];if(t.type.isNotEmptyObject(n[p])){for(o in n[p]){if(n[p].hasOwnProperty(o)){c={entityType:p,itemCode:n[p][o]};if(t.type.isNotEmptyObject(this.sortData[c.itemCode])){c.sort=this.sortData[c.itemCode]}l.push(c)}}}}}l.sort(function(t,e){if(typeof t.sort=="undefined"&&typeof e.sort=="undefined"){return 0}else if(typeof t.sort!="undefined"&&typeof e.sort=="undefined"){return-1}else if(typeof t.sort=="undefined"&&typeof e.sort!="undefined"){return 1}else{if(typeof t.sort.Y!="undefined"&&typeof e.sort.Y=="undefined"){return-1}else if(typeof t.sort.Y=="undefined"&&typeof e.sort.Y!="undefined"){return 1}else if(typeof t.sort.Y!="undefined"&&typeof e.sort.Y!="undefined"){if(parseInt(t.sort.Y)>parseInt(e.sort.Y)){return-1}else if(parseInt(t.sort.Y)<parseInt(e.sort.Y)){return 1}else{return 0}}else{if(parseInt(t.sort.N)>parseInt(e.sort.N)){return-1}else if(parseInt(t.sort.N)<parseInt(e.sort.N)){return 1}else{return 0}}}});var h=null,d=false,u=0,m=0;for(var f=0;f<l.length;f++){if(f==0){if(typeof this.result[e.navData.tab]=="undefined"){this.result[e.navData.tab]=[]}this.result[e.navData.tab][e.navData.group]=[];d=true}if(m==2){m=0;u++}if(typeof this.result[e.navData.tab][e.navData.group][u]=="undefined"){this.result[e.navData.tab][e.navData.group][u]=[]}h=this.drawItem(l[f]);if(h){this.result[e.navData.tab][e.navData.group][u][m]={entityType:l[f].entityType,itemCode:l[f].itemCode};a.push(h);m++}}if(d){e.navData.group++}}if(a.length>0){s=t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBox+" "+this.getRenderInstance().class.groupBoxPrefix+i},children:[t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxName},html:this.dialogGroups[i].TITLE}),t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxContent},children:a})]})}return s};t.UI.Selector.prototype.drawItemsTab=function(e){var s=e.type;var i=e.itemsCodeList;var n=[],a=0,r=0,o=0,p=null;if(t.type.isNotEmptyObject(i)){for(var c in i){if(i.hasOwnProperty(c)){if(a==0){this.result[e.type]=[];this.result[e.type][0]=[]}if(o==2){o=0;r++}if(typeof this.result[e.type][0][r]=="undefined"){this.result[e.type][0][r]=[]}p={entityType:s.toUpperCase(),itemCode:i[c]};this.result[e.type][0][r][o]=p;n.push(this.drawItem(p));o++}a++}}return t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBox+" "+this.getRenderInstance().class.groupBoxPrefix+s},children:[t.create("SPAN",{props:{className:this.getRenderInstance().class.groupBoxContent},children:n})]})};t.UI.Selector.prototype.drawItemsTreeTabNode=function(e){var s=[];var i=t.type.isNotEmptyString(e.type)?e.type:false,n=e.relation!="undefined"?e.relation:false,a=e.categoryId!="undefined"?e.categoryId:false,r=e.categoryOpened,o=false,p=null,c=null,l=null;if(!n&&t.type.isNotEmptyObject(this.entities[i.toUpperCase()+"_RELATION"])&&t.type.isNotEmptyObject(this.entities[i.toUpperCase()+"_RELATION"].items)){n=this.entities[i.toUpperCase()+"_RELATION"].items;o=true}if(!n){return s}var h=t.type.isNotEmptyObject(this.entities[i.toUpperCase()].additionalData)&&t.type.isNotEmptyString(this.entities[i.toUpperCase()].additionalData.SELECT_TEXT)?this.entities[i.toUpperCase()].additionalData.SELECT_TEXT:t.message("MAIN_UI_SELECTOR_SELECT_TEXT");var d=t.type.isNotEmptyObject(this.entities[i.toUpperCase()].additionalData)&&t.type.isNotEmptyString(this.entities[i.toUpperCase()].additionalData.SELECT_FLAT_TEXT)?this.entities[i.toUpperCase()].additionalData.SELECT_FLAT_TEXT:t.message("MAIN_UI_SELECTOR_SELECT_FLAT_TEXT");var u=null,m=null,f=null,y=null;for(p in n){if(n.hasOwnProperty(p)&&n[p].type=="category"){c=this.entities[i.toUpperCase()].items[n[p].id];o=o&&c.id!="EX";u=t.create("DIV",{props:{className:this.getRenderInstance().class.treeBranch+" "+(o?this.getRenderInstance().class.treeBranchOpened:"")},children:[t.create("A",{attrs:{href:"#"+c.id,hidefocus:"true","data-entity-id":c.entityId},props:{className:this.getRenderInstance().class.treeBranchInner},events:{click:function(t){this.openTreeItem({treeItemNode:t.currentTarget.parentNode,entityType:i,categoryId:t.currentTarget.getAttribute("data-entity-id")});t.stopPropagation();return t.preventDefault()}.bind(this)},children:[t.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchArrow}}),t.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchText},html:c.name})]})]});s.push(u);f=t.type.isNotEmptyObject(this.entities[i.toUpperCase()].additionalData)&&t.type.isNotEmptyString(this.entities[i.toUpperCase()].additionalData.ALLOW_SELECT)&&this.entities[i.toUpperCase()].additionalData.ALLOW_SELECT=="Y"&&!o&&c.id!="EX"?t.create("A",{attrs:{hidefocus:"true",href:"#"+n[p].id,"data-item-id":n[p].id,"data-entity-type":i.toUpperCase()},props:{className:this.getRenderInstance().class.treeBranchCheckBox+" "+(typeof this.itemsSelected[n[p].id]!="undefined"?this.getRenderInstance().class.treeBranchCheckBoxSelected:"")+" "+this.getRenderInstance().class.itemElement},events:{click:function(t){this.selectItem({itemId:t.currentTarget.getAttribute("data-item-id"),entityType:t.currentTarget.getAttribute("data-entity-type"),itemNode:t.currentTarget,className:this.getRenderInstance().class.treeBranchCheckBoxSelected});t.stopPropagation();return t.preventDefault()}.bind(this)},children:[t.create("SPAN",{props:{className:this.getRenderInstance().class.treeBranchCheckBoxInner},children:[t.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchCheckBoxArrow}}),t.create("DIV",{attrs:{rel:c.name+": "+h},props:{className:this.getRenderInstance().class.treeBranchCheckBoxText},html:h})]})]}):null;y=[f];if(t.type.isNotEmptyObject(this.entities[i.toUpperCase()].additionalData)&&t.type.isNotEmptyString(this.entities[i.toUpperCase()].additionalData.ALLOW_FLAT)&&this.entities[i.toUpperCase()].additionalData.ALLOW_FLAT=="Y"&&c.id!="EX"&&t.type.isNotEmptyString(this.entities[i.toUpperCase()].items[n[p].id].idFlat)){f=t.create("A",{attrs:{hidefocus:"true",href:"#"+this.entities[i.toUpperCase()].items[n[p].id].idFlat,"data-item-id":this.entities[i.toUpperCase()].items[n[p].id].idFlat,"data-entity-type":i.toUpperCase()},props:{className:this.getRenderInstance().class.treeBranchCheckBox+" "+(typeof this.itemsSelected[n[p].id]!="undefined"?this.getRenderInstance().class.treeBranchCheckBoxSelected:"")+" "+this.getRenderInstance().class.itemElement},events:{click:function(t){this.selectItem({itemId:t.currentTarget.getAttribute("data-item-id"),entityType:t.currentTarget.getAttribute("data-entity-type"),itemNode:t.currentTarget,className:this.getRenderInstance().class.treeBranchCheckBoxSelected});t.stopPropagation();return t.preventDefault()}.bind(this)},children:[t.create("SPAN",{props:{className:this.getRenderInstance().class.treeBranchCheckBoxInner},children:[t.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchCheckBoxArrow}}),t.create("DIV",{attrs:{rel:c.name+": "+d},props:{className:this.getRenderInstance().class.treeBranchCheckBoxText},html:d})]})]});y.push(f)}var g=t.clone(e);g.relation=n[p].items;g.categoryId=c.entityId;g.categoryOpened=o;var I=this.drawItemsTreeTabNode(g);if(I.length>0){for(l=0;l<I.length;l++){y.push(I[l])}}m=t.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchLeavesContainer+" "+(o?this.getRenderInstance().class.treeBranchLeavesContainerOpened:"")},children:y});s.push(m)}}if(a){var S=[],C=null,b=0;for(l in n){if(n.hasOwnProperty(l)&&n[l].type==this.entities[i.toUpperCase()].additionalData.RELATION_ENTITY_TYPE){C=this.entities[n[l].type].items[n[l].id];if(!C){continue}S.push(this.drawTreeLeafItem({entityType:n[l].type,item:C}));b++}}if(b<=0){if(!t.type.isNotEmptyObject(this.treeItemLoaded[i])||!this.treeItemLoaded[i][a]){S.push(t.create("DIV",{props:{className:this.getRenderInstance().class.treeBranchLeavesWaiter},html:t.message("MAIN_UI_SELECTOR_PLEASE_WAIT")}))}if(r){this.getTreeItemRelation({entityType:i,categoryId:a})}}s.push(t.create("DIV",{attrs:{id:"bx-lm-category-relation-"+a},props:{className:this.getRenderInstance().class.treeLeavesList},children:S}))}return s};t.UI.Selector.prototype.drawTreeLeafItem=function(e){var s=e.entityType,i=e.item;var n=typeof this.itemsSelected[i.id]!="undefined"?this.getRenderInstance().class.treeLeafSelected:"";return t.create("A",{attrs:{href:"#"+i.id,rel:i.id,hidefocus:"true","data-item-id":i.id,"data-entity-type":s},props:{className:this.getRenderInstance().class.treeLeaf+" "+n+" "+this.getRenderInstance().class.itemElement},events:{click:function(t){this.selectItem({itemNode:t.currentTarget,itemId:t.currentTarget.getAttribute("data-item-id"),entityType:t.currentTarget.getAttribute("data-entity-type"),className:this.getRenderInstance().class.treeLeafSelected});t.stopPropagation();return t.preventDefault()}.bind(this)},children:[t.create("DIV",{props:{className:this.getRenderInstance().class.treeLeafInfo},children:[t.create("DIV",{props:{className:this.getRenderInstance().class.treeLeafName},html:i.name}),t.create("DIV",{props:{className:this.getRenderInstance().class.treeLeafDescription},html:i.desc})]}),t.create("DIV",{attrs:{style:i.avatar?"background:url('"+i.avatar+"') no-repeat center center; background-size: cover;":""},props:{className:this.getRenderInstance().class.treeLeafAvatar}})]})};t.UI.Selector.prototype.openTreeItem=function(e){var s=t.type.isDomNode(e.treeItemNode)?e.treeItemNode:null,i=e.categoryId,n=e.entityType;var a=!t.hasClass(s,this.getRenderInstance().class.treeBranchOpened);t.toggleClass(s,this.getRenderInstance().class.treeBranchOpened);var r=t.findNextSibling(s,{tagName:"div"});if(t.hasClass(r,this.getRenderInstance().class.treeBranchLeavesContainer)){t.toggleClass(r,this.getRenderInstance().class.treeBranchLeavesContainerOpened)}if(a){this.getTreeItemRelation({entityType:n,categoryId:i})}return false};t.UI.Selector.prototype.getTreeItemRelation=function(e){var s=e.categoryId;if(typeof this.treeItemLoaded[s]!="undefined"){return false}e.callback=this.getTreeItemRelationCallback.bind(this);e.entityType=e.entityType.toUpperCase();e.selectorId=this.id;t.onCustomEvent(this,"BX.UI.SelectorManager:getTreeItemRelation",[e])};t.UI.Selector.prototype.getTreeItemRelationCallback=function(e){if(typeof e.selectorInstanceId=="undefined"||this.id!=e.selectorInstanceId){return}var s=e.entityType,i=e.categoryId,n=e.data,a={},r=null;if(i!="EX"){i=parseInt(i)}if(typeof this.treeItemLoaded[s]=="undefined"){this.treeItemLoaded[s]={}}this.treeItemLoaded[s][i]=true;var o=t.util.object_search_key(i=="EX"?i:this.entities[s.toUpperCase()].additionalData.PREFIX+i,this.entities[s.toUpperCase()+"_RELATION"].items);if(t.type.isNotEmptyObject(this.entities[s.toUpperCase()])&&t.type.isNotEmptyObject(this.entities[s.toUpperCase()].additionalData)&&t.type.isNotEmptyString(this.entities[s.toUpperCase()].additionalData.RELATION_ENTITY_TYPE)){r=this.entities[s.toUpperCase()].additionalData.RELATION_ENTITY_TYPE;a=n[r]}var p=null;if(t.type.isNotEmptyObject(o.items)){for(p in o.items){if(!o.items.hasOwnProperty(p)){continue}if(o.items[p].type==r){delete o.items[p]}}}t.cleanNode(t("bx-lm-category-relation-"+i));for(p in a){if(a.hasOwnProperty(p)){if(!t.type.isNotEmptyObject(this.entities[r].items[p])){this.entities[r].items[p]=a[p]}if(t("bx-lm-category-relation-"+i)&&!o.items[p]){o.items[p]={id:p,type:r};t("bx-lm-category-relation-"+i).appendChild(this.drawTreeLeafItem({entityType:r,item:this.entities[r].items[p]}))}}}if(this.popups.container){this.popups.container.adjustPosition()}if(this.popups.main){this.popups.main.adjustPosition()}};t.UI.Selector.prototype.drawItem=function(e){var s=null;var i=t.type.isNotEmptyString(e.entityType)?e.entityType:null;var n=t.type.isNotEmptyString(e.itemCode)?e.itemCode:null;if(!i||!n){return s}var a=t.type.isNotEmptyObject(this.entities[i])&&t.type.isNotEmptyObject(this.entities[i].items)&&t.type.isNotEmptyObject(this.entities[i].items[n])?this.entities[i].items[n]:null;if(!a){return s}var r=a.name,o="";if(this.getOption("emailDescMode")!="Y"&&t.type.isNotEmptyString(a.showEmail)&&a.showEmail=="Y"&&t.type.isNotEmptyString(a.email)){r+=" ("+a.email+")"}var p=t.type.isNotEmptyString(a.desc);p=e.descLessMode&&e.descLessMode==true?false:p;p=p||a.showDesc;var c=typeof e.emailDescMode!="undefined"&&e.emailDescMode==true;if(c===true){p=true}var l=null;if(t.type.isNotEmptyString(a.avatar)){l=t.create("DIV",{props:{className:this.getRenderInstance().class.itemAvatar},children:[t.create("IMG",{attrs:{src:a.avatar,"bx-lm-item-id":a.id,"bx-lm-item-type":i.toLowerCase()},props:{className:this.getRenderInstance().class.itemAvatarImage},events:{error:function(){t.onCustomEvent("removeClientDbObject",[t.UI.SelectorManager,this.getAttribute("bx-lm-item-id"),this.getAttribute("bx-lm-item-type")]);t.cleanNode(this,true)}}}),t.create("SPAN",{props:{className:this.getRenderInstance().class.itemAvatarStatus}})]})}else{l=t.create("DIV",{props:{className:this.getRenderInstance().class.itemAvatar+" "+(a.iconCustom?this.getRenderInstance().class.itemAvatarCustom:"")},html:a.iconCustom?a.iconCustom:""})}return t.create("A",{attrs:{id:this.getItemNodeId({entityType:i,itemId:a.id}),hidefocus:"true",rel:a.id,"data-entity-type":i},props:{className:this.getRenderInstance().class.item+" "+this.getRenderInstance().class.itemElement+" "+(typeof this.itemsSelected[a.id]!="undefined"?this.getRenderInstance().class.itemSelected:"")+" "+(e.itemHover?this.getRenderInstance().class.itemHover:"")+" "+(p?this.getRenderInstance().class.itemShowDescriptionMode:"")+" "+(e.className?" "+e.className:"")+" "+this.getRenderInstance().class.itemElementTypePrefix+i.toLowerCase()+" "+(this.getOption("avatarLessMode")=="Y"?this.getRenderInstance().class.itemAvatarlessMode:"")+" "+(t.type.isNotEmptyString(a.isExtranet)&&a.isExtranet=="Y"||t.type.isNotEmptyString(a.isNetwork)&&a.isNetwork=="Y"?this.getRenderInstance().class.itemElementExtranet:"")+" "+(t.type.isNotEmptyString(a.isCrmEmail)&&a.isCrmEmail=="Y"?this.getRenderInstance().class.itemElementCrmEmail:"")+" "+(t.type.isNotEmptyString(a.isEmail)&&a.isEmail=="Y"?this.getRenderInstance().class.itemElementEmail:"")+" "+(this.getOption("showVacations")=="Y"&&t.type.isNotEmptyObject(this.entities[i].additionalData)&&t.type.isNotEmptyObject(this.entities[i].additionalData["USERS_VACATION"])&&t.type.isNotEmptyString(this.entities[i].additionalData["USERS_VACATION"][a.entityId])?this.getRenderInstance().class.itemElementVacation:"")},events:{click:function(t){this.selectItem({entityType:t.currentTarget.getAttribute("data-entity-type"),itemNode:t.currentTarget,itemId:a.id});t.stopPropagation();return t.preventDefault()}.bind(this)},children:[l,t.create("DIV",{props:{className:this.getRenderInstance().class.itemSpace}}),t.create("DIV",{props:{className:this.getRenderInstance().class.itemInfo},children:[t.create("DIV",{props:{className:this.getRenderInstance().class.itemName},html:r}),p?t.create("DIV",{props:{className:this.getRenderInstance().class.itemDescription},html:o}):null]})]})};t.UI.Selector.prototype.isDialogOpen=function(){return this.popups.main!=null||this.popups.container!=null};t.UI.Selector.prototype.isContainerOpen=function(){return this.popups.container!=null};t.UI.Selector.prototype.isSearchOpen=function(){return this.popups.popup!=null||this.popups.container!=null};t.UI.Selector.prototype.closeDialog=function(e){var s=t.type.isNotEmptyObject(e)&&!!e.silent;if(this.popups.main!=null){if(s){this.popups.main.destroy()}else{this.popups.main.close()}}else if(this.popups.container!=null){if(s){this.popups.container.destroy()}else{this.popups.container.close()}}t.onCustomEvent("BX.UI.SelectorManager:onDialogClose",[this]);return true};t.UI.Selector.prototype.closeSearch=function(){if(this.popups.search){this.popups.search.close()}else if(this.popups.container){this.popups.container.close()}return true};t.UI.Selector.prototype.closeAllPopups=function(){for(var t in this.popups){if(!this.popups.hasOwnProperty(t)){continue}if(this.popups[t]){this.popups[t].close()}}};t.UI.Selector.prototype.getItemNodeId=function(t){return(this.id+"_"+(this.tabs.selected?this.tabs.selected:"")+"_"+t.entityType+"_"+t.itemId).toLowerCase()};t.UI.Selector.prototype.getAdditionalEntitiesData=function(){var e={};for(var s in this.entities){if(!this.entities.hasOwnProperty(s)){continue}e[s]={};if(t.type.isNotEmptyObject(this.entities[s].additionalData)){e[s]=this.entities[s].additionalData}}return e};t.UI.Selector.prototype.setTagTitle=function(){if(t.type.isDomNode(this.nodes.tag)){if(Object.keys(this.itemsSelected).length<=0&&this.getOption("tagLink1")){this.nodes.tag.innerHTML=this.getOption("tagLink1")}else if(Object.keys(this.itemsSelected).length>0&&this.getOption("tagLink2")){this.nodes.tag.innerHTML=this.getOption("tagLink2")}}};t.UI.Selector.prototype.selectItem=function(e){var s=e.itemId,i=e.entityType,n=e.itemNode,a=t.type.isNotEmptyString(e.className)?e.className:this.getRenderInstance().class.itemSelected,r=t.type.isNotEmptyString(e.tab)?e.tab:"";if(!t.type.isNotEmptyString(s)){return false}if(this.getOption("focusInputOnSelectItem")!="N"){t.focus(this.input)}if(typeof this.itemsSelected[s]!="undefined"){return this.unselectItem({itemNode:n,itemId:s,entityType:i,className:a})}else{if(this.getOption("multiple")!="Y"){this.itemsSelected={}}this.itemsSelected[s]=i.toLowerCase()}if(!t.type.isArray(this.entities[i].itemsLast)){this.entities[i].itemsLast=[]}if(!t.util.in_array(s,this.entities[i].itemsLast)){this.entities[i].itemsLast.push(s)}t.addClass(n,a);t.onCustomEvent("BX.UI.Selector:onSelectItem",[{selectorId:this.id,itemId:e.itemId}]);if(this.callback.select){this.callback.select({item:this.entities[i].items[s],entityType:i,selectorId:this.id,state:"select",tab:r})}if(this.popups.search){this.popups.search.close()}if(this.getOption("multiple")!="Y"&&this.getOption("preventCloseAfterSelect")!="Y"){if(this.popups.container){this.popups.container.close()}if(this.popups.main){this.popups.main.close()}}this.getSearchInstance().abortSearchRequest();return false};t.UI.Selector.prototype.deleteSelectedItem=function(e){var s=e.itemId;if(!t.type.isNotEmptyString(s)){return false}if(this.popups.main){var i=t.findChildren(this.popups.main.popupContainer,{attrs:{rel:s}},true);if(i){for(var n=0;n<i.length;n++){t.removeClass(i[n],this.getRenderInstance().class.itemSelected);t.removeClass(i[n],this.getRenderInstance().class.treeLeafSelected)}}}delete this.itemsSelected[s]};t.UI.Selector.prototype.unselectItem=function(e){var s=e.itemId,i=e.entityType,n=e.itemNode,a=t.type.isNotEmptyString(e.className)?e.className:this.getRenderInstance().class.itemSelected;if(!t.type.isNotEmptyString(s)){return false}if((!t.type.isNotEmptyString(e.mode)||e.mode!="reinit")&&(typeof this.itemsSelected[s]=="undefined"||t.util.in_array(s,this.itemsUndeletable))){return false}else{delete this.itemsSelected[s]}t.removeClass(n,a);if(this.callback.unSelect){this.callback.unSelect({item:this.entities[i].items[s],entityType:i,selectorId:this.id})}if(this.getOption("multiple")!="Y"&&this.getOption("preventCloseAfterSelect")!="Y"){if(this.popups.container){this.popups.container.close()}if(this.popups.main){this.popups.main.close()}if(this.popups.search){this.popups.search.close()}}return false};t.UI.Selector.prototype.deleteLastItem=function(){var t=false;for(var e in this.itemsSelected){if(this.itemsSelected.hasOwnProperty(e)){t=e}}if(t){var s=this.itemsSelected[t];delete this.itemsSelected[t];if(this.callback.unSelect){this.callback.unSelect({item:this.entities[s.toUpperCase()].items[t],entityType:s.toUpperCase(),selectorId:this.id})}}};t.UI.Selector.prototype.reinit=function(){var e=null;if(this.callback.select){for(var s in this.itemsSelected){if(this.itemsSelected.hasOwnProperty(s)){e=this.itemsSelected[s];if(t.type.isNotEmptyObject(this.entities[e.toUpperCase()])&&t.type.isNotEmptyObject(this.entities[e.toUpperCase()].items)&&t.type.isNotEmptyObject(this.entities[e.toUpperCase()].items[s])){this.callback.select({item:this.entities[e.toUpperCase()].items[s],entityType:e,selectorId:this.id,state:"init"})}}}}};t.UI.Selector.prototype.getItemsSelectedSorted=function(){var e=[],s=null;for(var i in this.itemsSelected){if(this.itemsSelected.hasOwnProperty(i)){s=this.itemsSelected[i];e.push({itemId:i,entityType:s,sort:t.type.isNotEmptyObject(this.entities)&&t.type.isNotEmptyObject(this.entities[s.toUpperCase()])&&t.type.isNotEmptyObject(this.entities[s.toUpperCase()].additionalData)&&typeof this.entities[s.toUpperCase()].additionalData.SORT_SELECTED!="undefined"?parseInt(this.entities[s.toUpperCase()].additionalData.SORT_SELECTED):100})}}e.sort(function(t,e){if(t.sort<e.sort){return-1}if(t.sort>e.sort){return 1}return 0});return e}})();
//# sourceMappingURL=selector.map.js