text: BX.namespace("BX.Crm.ClientPortrait");(function(t){"use strict";if(typeof t.Crm.ClientPortrait.Loadbar!=="undefined")return;var e="/bitrix/components/bitrix/crm.client.portrait/ajax.php?site_id="+t.message("SITE_ID")+"&sessid="+t.bitrix_sessid();var i=function(t,e){if(!(t instanceof Element))throw"Loadbar: barNode is incorrect!";this.entityContext=e;this.loadData={min:0,max:20,target:5,current:0,currentOriginal:0,manualTarget:false};this.nodes={};this.nodes.bar=t;this.nodes.level1=t.querySelector('[data-role="level-1"]');this.nodes.level2=t.querySelector('[data-role="level-2"]');this.nodes.level3=t.querySelector('[data-role="level-3"]');this.nodes.level4=t.querySelector('[data-role="level-4"]');this.nodes.level5=t.querySelector('[data-role="level-5"]');this.nodes.level6=t.querySelector('[data-role="level-6"]');this.nodes.level7=t.querySelector('[data-role="level-7"]');this.nodes.current=t.querySelector('[data-role="current"]');this.nodes.currentText=t.querySelector('[data-role="current-text"]');this.nodes.configBtn=t.querySelector('[data-role="config-btn"]')};i.messages={};i.prototype={setLoadData:function(e){if(!t.type.isPlainObject(this.loadData))throw"Loadbar: load data is incorrect!";var i=0,a=parseInt(e.max),s=parseInt(e.target),r=parseInt(e.current),o=r;if(isNaN(a))a=0;if(isNaN(s))s=0;if(isNaN(r))r=0;if(isNaN(o))o=0;if(a<8)a=8;if(s<i)s=i;if(s>a)s=a;if(r<i)r=i;else if(r>a)r=a;this.loadData={min:i,max:a,target:s,current:r,currentOriginal:o,manualTarget:e.manualTarget};return this},setLoadTarget:function(t){t=parseInt(t);if(isNaN(t))t=0;if(t<this.loadData.min)t=this.loadData.min;if(t>this.loadData.max)t=this.loadData.max;this.loadData.target=t;return this},init:function(){var e=this.nodes.bar.getAttribute("data-loaddata");if(e){var i=JSON.parse(e);if(t.type.isPlainObject(i))this.setLoadData(i)}if(!t.type.isPlainObject(this.entityContext)){var a=this.nodes.bar.getAttribute("data-context");if(a){this.entityContext=JSON.parse(a);if(!t.type.isPlainObject(this.entityContext))this.entityContext={}}}if(this.nodes.configBtn){t.bind(this.nodes.configBtn,"click",t.delegate(this.onConfigBtnClick,this))}return this},refreshView:function(t){if(t)this.setLoadData(t);this.renderLevels();this.renderCurrent();return this},renderLevels:function(){var t=this.loadData.max-this.loadData.min;var e=this.loadData.target/t*100;var i=1;if(e<50){if(e!==0)i=e/3.5;this.setLevelWidth(this.nodes.level1,i);this.setLevelWidth(this.nodes.level2,i);this.setLevelWidth(this.nodes.level3,i);this.setLevelWidth(this.nodes.level5);this.setLevelWidth(this.nodes.level6);this.setLevelWidth(this.nodes.level7)}else{if(e!==100)i=(100-e)/3.5;this.setLevelWidth(this.nodes.level1);this.setLevelWidth(this.nodes.level2);this.setLevelWidth(this.nodes.level3);this.setLevelWidth(this.nodes.level5,i);this.setLevelWidth(this.nodes.level6,i);this.setLevelWidth(this.nodes.level7,i)}this.setLevelWidth(this.nodes.level4,i)},setLevelWidth:function(e,i){e.style.maxWidth=i?i+"%":"none";e.style.minWidth=i?i+"%":"auto";t[i<10?"addClass":"removeClass"](e,"crm-portrait-load-hide")},renderCurrent:function(){var t=this.loadData.max-this.loadData.min;var e=this.loadData.current/t*100;this.nodes.current.style.left=e+"%";this.nodes.currentText.innerHTML=this.loadData.currentOriginal.toString()},onConfigBtnClick:function(){this.getConfigPopup().show()},getConfigPopup:function(){var a=this,s=false;if(!this.configPopup)this.configPopup=new t.PopupWindow("crm-client-portrait-loadbar"+Math.random(),null,{content:this.getConfigPopupHtml(),closeIcon:true,titleBar:t.util.htmlspecialchars(i.messages.CONFIG_TITLE),overlay:{backgroundColor:"black",opacity:"80"},buttons:[new t.PopupWindowButton({text:t.util.htmlspecialchars(i.messages.SAVE),className:"popup-window-button-accept",events:{click:function(){var i=this.popupWindow;var r=a.configPopup.contentContainer.querySelector('[data-role="is_manual"]').checked;var o=a.configPopup.contentContainer.querySelector('[data-role="load_target"]').value;a.loadData.manualTarget=r;s=true;t.ajax.post(e,{ajax_action:"SET_LOAD_TARGET",is_manual:r?"Y":"N",load_target:o,entity_context:a.entityContext},function(){s=false;a.setLoadTarget(o);a.refreshView();i.close()})}}}),new t.PopupWindowButton({text:t.util.htmlspecialchars(i.messages.CANCEL),className:"popup-window-button",events:{click:function(){this.popupWindow.close()}}})]});return this.configPopup},getConfigPopupHtml:function(){var e="crm-client-portrait-loadbar"+Math.random();var a=this.loadData.target.toString();return['<div class="crm-portriat-popup-text">',t.util.htmlspecialchars(i.messages.CONFIG_DESCRIPTION),"<br>","<br>",t.util.htmlspecialchars(i.messages.CONFIG_HELP),"</div>",'<div class="crm-portriat-popup-set">','<form action="">','<div class="crm-portriat-popup-set-item">','<input class="crm-portriat-popup-radio" type="radio" name="is_manual" value="N" id="',e,'-interval-1" ',this.loadData.manualTarget?"":"checked",">",'<label class="crm-portriat-popup-label" for="',e,'-interval-1">',t.util.htmlspecialchars(i.messages.CONFIG_AUTO),"</label>","</div>",'<div class="crm-portriat-popup-set-item">','<input class="crm-portriat-popup-radio" type="radio" name="is_manual" data-role="is_manual" value="Y" id="',e,'-interval-2" ',this.loadData.manualTarget?"checked":"",">",'<label class="crm-portriat-popup-label" for="',e,'-interval-2">',t.util.htmlspecialchars(i.messages.CONFIG_MANUAL),":",'<input class="crm-portriat-popup-input" type="text" name="load_manual" data-role="load_target" value="',a,'">',"</label>","</div>","</form>","</div>"].join("")}};var a=function(e,i,a){if(!(e instanceof Element))throw"LoadbarMenu: menuNode is incorrect!";if(!(i instanceof Element))throw"LoadbarMenu: containerNode is incorrect!";if(!t.type.isPlainObject(a))a={};this.entityContext=a;this.nodes={menu:e,container:i};this.loadbars=[]};a.prototype={init:function(){var e;t.bind(this.nodes.menu,"click",t.delegate(this.onMenuClick,this));var a=this.nodes.container.querySelectorAll('[data-role="loadbar"]');if(a){for(e=0;e<a.length;++e){this.loadbars.push(new i(a[e]).init())}}return this},onMenuClick:function(){var e=t.hasClass(this.nodes.container,"crm-portrait-item-show");t[e?"removeClass":"addClass"](this.nodes.menu,"crm-portrait-direction-show");t.toggleClass(this.nodes.container,"crm-portrait-item-show");if(!e)this.refreshView()},refreshView:function(){var t;for(t=0;t<this.loadbars.length;++t){this.loadbars[t].refreshView()}}};t.Crm.ClientPortrait.Loadbar=i;t.Crm.ClientPortrait.LoadbarMenu=a})(window.BX||window.top.BX);
  //# sourceMappingURL=script.map.js