Your IP : 18.117.102.123
(function(){var e=window.BX;e.namespace("BX.Bizproc");if(e.Bizproc.Selector)return;e.Bizproc.Selector={delimiter:"=",listenKeyCode:187,currentData:{},inputElement:null,popup:null,selectedTab:null,activitiesItemsCache:null};e.Bizproc.Selector.initSelectors=function(t){if(!t)t=document;var s,i,r,a=t.querySelectorAll('[data-role="bp-selector-button"]');if(a){for(r=0;r<a.length;++r){i=JSON.parse(a[r].getAttribute("data-bp-selector-props"));if(typeof i!=="object")continue;s=document.getElementById(i.controlId);if(!s)continue;e.bind(s,"keydown",function(t){e.Bizproc.Selector.onSearch(this,t)});s.setAttribute("autocomplete","off")}}};e.Bizproc.Selector.getTabItems=function(e){var t;for(t=0;t<this.currentData.length;++t){if(this.currentData[t]["tabId"]===e)return this.currentData[t]["items"]}return[]};e.Bizproc.Selector.getActivitiesItems=function(){if(this.activitiesItemsCache===null){this.activitiesItemsCache=this.getTemplateActivitiesItems([rootActivity.Serialize()],arAllActivities)}return this.activitiesItemsCache};e.Bizproc.Selector.getTemplateActivitiesItems=function(e,t){var s=[],i,r,a,o,n;for(i=0,r=e.length;i<r;++i){a=e[i].Type.toLowerCase();if(t[a])o=t[a];if(o&&o["RETURN"]){for(n in o["RETURN"]){if(!o["RETURN"].hasOwnProperty(n))continue;s.push({text:o["RETURN"][n].NAME,description:e[i].Properties.Title||o.NAME,value:"{="+e[i].Name+":"+n+"}"})}}if(e[i].Children&&e[i].Children.length>0){var l=this.getTemplateActivitiesItems(e[i].Children,t);for(var c=0;c<l.length;++c){s.push(l[c])}}}return s};e.Bizproc.Selector.getTabsCounters=function(){var e,t={};for(e=0;e<this.currentData.length;++e){t[this.currentData[e]["tabId"]]=this.currentData[e]["items"].length}return t};e.Bizproc.Selector.getListElement=function(){return e.findChild(this.popup.contentContainer,{className:"bp-selector-list"},true)};e.Bizproc.Selector.getSelectedItem=function(){return e.findChild(this.popup.contentContainer,{className:"bp-selector-item-selected"},true)};e.Bizproc.Selector.getTabsElements=function(){return e.findChildren(this.popup.contentContainer,{className:"bp-selector-tab"},true)};e.Bizproc.Selector.closePopup=function(){if(this.popup)this.popup.close()};e.Bizproc.Selector.insertItemValue=function(e,t){var s=this.inputElement.value.substr(0,this.inputElement.selectionEnd),i=this.inputElement.value.substr(0,s.lastIndexOf(this.delimiter)),r=e.getAttribute("data-value")+(t?this.delimiter:""),a=this.inputElement.value.substr(this.inputElement.selectionEnd),o=parseInt(e.getAttribute("data-cursor-position"));if(isNaN(o))o=r.length;if(i.substr(-1)==="{")i=i.substr(0,i.length-1);this.inputElement.value=i+r+a;this.inputElement.selectionEnd=i.length+o};e.Bizproc.Selector.onSearch=function(t,s){var i=this,r=true;if(t.mentionListen){if(s.keyCode==27){t.mentionListen=false;this.closePopup();return e.PreventDefault(s)}else if(s.keyCode==13&&this.popup){var a=this.getSelectedItem();if(a){this.insertItemValue(a,s.shiftKey===true);if(s.shiftKey!==true)this.closePopup()}return e.PreventDefault(s)}else if((s.keyCode==37||s.keyCode==39||s.keyCode==9)&&this.popup){this.SelectNextTab(s.keyCode==37?-1:1);return e.PreventDefault(s)}else if((s.keyCode==38||s.keyCode==40)&&this.popup){this.SelectNextItem(s.keyCode==38?-1:1);return e.PreventDefault(s)}else if(s.altKey===true||s.ctrlKey===true||s.shiftKey===true&&s.keyCode==16){}else{setTimeout(e.delegate(function(){var e=this.value.substr(0,this.selectionEnd);if(e.lastIndexOf(i.delimiter)<0){i.closePopup();return false}e=e.substr(e.lastIndexOf(i.delimiter),this.selectionEnd-e.lastIndexOf(i.delimiter));if(e.length<=0){i.closePopup();return false}e=e.substr(1);if(e.substr(0,1)==" "){i.closePopup();return false}if(i.popup)i.updatePopupContent(e)},t),10)}}else if(s.shiftKey===false&&s.keyCode==i.listenKeyCode){if(!t.mentionListen){setTimeout(e.delegate(function(){var t=this.value.substr(this.selectionEnd-1,1);if(t!=i.delimiter)return false;this.mentionListen=true;i.closePopup();i.popup=new e.PopupWindow("bx-bizproc-selector",this,{lightShadow:true,offsetTop:0,closeIcon:true,offsetLeft:0,autoHide:true,bindOptions:{position:"bottom"},closeByEsc:true,zIndex:200,events:{onPopupShow:function(){e.WindowManager.currently_loaded=this;this.CloseDialog=this.Close=function(){e.WindowManager.currently_loaded=null;if(i.popup!==null){var t=e.WindowManager.Get();if(t&&!t.unclosable)t.Close()}}},onPopupClose:function(){this.destroy();setTimeout(function(){e.WindowManager.currently_loaded=null},50)},onPopupDestroy:e.delegate(function(){i.popup=null;i.activitiesItemsCache=null;this.mentionListen=false},this)},content:e.create("DIV",{children:[i.generatePopupContent()]})});i.popup.show();i.inputElement=this},t),100)}}if(!r)return e.PreventDefault(s)};e.Bizproc.Selector.extractMenuItem=function(e,t,s){var i=[];var r;for(r in t){if(!t.hasOwnProperty(r))continue;i.push({text:t[r].Name,value:"{="+s+":"+r+"}"})}return this.filterItems(i,e)};e.Bizproc.Selector.filterItems=function(t,s){var i=[],r;s=s?s.toLowerCase():"";var a=s&&e.correctText?e.correctText(s,{replace_way:"AUTO",mixed:true}).toLowerCase():"";for(r=0;r<t.length;++r){if(!s||t[r].text.toLowerCase().indexOf(s)>=0||t[r].value.toLowerCase().indexOf(s)>=0||t[r].text.toLowerCase().indexOf(a)>=0||t[r].value.toLowerCase().indexOf(a)>=0){i.push(t[r])}}return i};e.Bizproc.Selector.updateCurrentData=function(t){var s=[];if(e.util.object_keys(arWorkflowParameters).length>0)s.push({tabName:e.message("BIZPROC_JS_BP_SELECTOR_PARAMETERS"),tabId:"parameters",items:this.extractMenuItem(t,arWorkflowParameters,"Template")});if(e.util.object_keys(arWorkflowVariables).length>0)s.push({tabName:e.message("BIZPROC_JS_BP_SELECTOR_VARIABLES"),tabId:"variables",items:this.extractMenuItem(t,arWorkflowVariables,"Variable")});if(e.util.object_keys(arWorkflowConstants).length>0)s.push({tabName:e.message("BIZPROC_JS_BP_SELECTOR_CONSTANTS"),tabId:"constants",items:this.extractMenuItem(t,arWorkflowConstants,"Constant")});if(typeof arDocumentFields!=="undefined"){s.push({tabName:e.message("BIZPROC_JS_BP_SELECTOR_DOCUMENT"),tabId:"document",items:this.extractMenuItem(t,arDocumentFields,"Document")})}var i=this.getActivitiesItems();if(i.length>0)s.push({tabName:e.message("BIZPROC_JS_BP_SELECTOR_ACTIVITIES"),tabId:"activities",items:this.filterItems(i,t)});s.push({tabName:e.message("BIZPROC_JS_BP_SELECTOR_SYSTEM"),tabId:"system",items:this.filterItems([{text:e.message("BIZPROC_JS_BP_SELECTOR_WORKFLOW_ID"),value:"{=Workflow:ID}"},{text:e.message("BIZPROC_JS_BP_SELECTOR_TARGET_USER"),value:"{=Template:TargetUser}"},{text:e.message("BIZPROC_JS_BP_SELECTOR_USER_ID"),value:"{=User:ID}"},{text:e.message("BIZPROC_JS_BP_SELECTOR_NOW"),value:"{=System:Now}"},{text:e.message("BIZPROC_JS_BP_SELECTOR_NOW_LOCAL"),value:"{=System:NowLocal}"},{text:e.message("BIZPROC_JS_BP_SELECTOR_DATE"),value:"{=System:Date}"}],t)});s.push({tabName:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTIONS"),tabId:"functions",items:this.filterItems([{text:"abs",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_ABS_DESCRIPTION"),value:"{{=abs()}}",cursorPosition:7},{text:"dateadd",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_DATEADD_DESCRIPTION"),value:"{{=dateadd(,)}}",cursorPosition:11},{text:"datediff",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_DATEDIFF_DESCRIPTION"),value:"{{=datediff(,,)}}",cursorPosition:12},{text:"if",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_IF_DESCRIPTION"),value:"{{=if(,,)}}",cursorPosition:6},{text:"intval",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_INTVAL_DESCRIPTION"),value:"{{=intval()}}",cursorPosition:10},{text:"floatval",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_FLOATVAL_DESCRIPTION"),value:"{{=floatval()}}",cursorPosition:12},{text:"min",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_MIN_DESCRIPTION"),value:"{{=min(,)}}",cursorPosition:7},{text:"max",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_MAX_DESCRIPTION"),value:"{{=max(,)}}",cursorPosition:7},{text:"rand",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_RAND_DESCRIPTION"),value:"{{=rand(,)}}",cursorPosition:8},{text:"round",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_ROUND_DESCRIPTION"),value:"{{=round(,)}}",cursorPosition:9},{text:"ceil",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_CEIL_DESCRIPTION"),value:"{{=ceil()}}",cursorPosition:8},{text:"floor",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_FLOOR_DESCRIPTION"),value:"{{=floor()}}",cursorPosition:9},{text:"substr",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_SUBSTR_DESCRIPTION"),value:"{{=substr(,,)}}",cursorPosition:10},{text:"strpos",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_STRPOS_DESCRIPTION"),value:"{{=strpos(,)}}",cursorPosition:10},{text:"merge",description:e.message("BIZPROC_JS_BP_SELECTOR_FUNCTION_MERGE_DESCRIPTION"),value:"{{=merge(,)}}",cursorPosition:9}],t)});this.currentData=s;return s};e.Bizproc.Selector.generatePopupContent=function(t){var s=e.create("DIV",{attrs:{className:"bp-selector-popup"}});var i=e.create("UL",{attrs:{className:"bp-selector-tabs"}});var r=e.create("UL",{attrs:{className:"bp-selector-list"}});s.appendChild(i);s.appendChild(r);var a=this.updateCurrentData(t);var o,n,l=this;for(o=0;o<a.length;++o){n=e.create("LI",{attrs:{className:"bp-selector-tab"},html:a[o].tabName+' (<span class="counter-value">'+a[o].items.length+"</span>)"});n.setAttribute("data-tab-id",a[o].tabId);n.setAttribute("hidefocus","true");if(!this.selectedTab&&o===0||this.selectedTab==a[o].tabId){e.addClass(n,"selected");this.updateList(r,a[o].items)}e.bind(n,"click",function(t){l.selectTab(this);e.focus(l.inputElement);return e.PreventDefault(t)});i.appendChild(n)}return s};e.Bizproc.Selector.updatePopupContent=function(t){var s=this.getListElement();var i,r,a,o=this.updateCurrentData(t);var n=this.getTabsCounters();var l=this.getTabsElements();for(i=0;i<l.length;++i){r=l[i].getAttribute("data-tab-id");a=e.findChild(l[i],{className:"counter-value"});a.innerHTML=n[r]||0;if(e.hasClass(l[i],"selected")){this.updateList(s,this.getTabItems(r))}}};e.Bizproc.Selector.SelectNextTab=function(t){var s,i,r,a,o,n=this.getTabsElements();for(r=0,a=n.length;r<a;++r){s=e.hasClass(n[r],"selected");if(s&&t<0){o=r-1>=0?r-1:a-1;e.removeClass(n[r],"selected");e.addClass(n[o],"selected");i=n[o].getAttribute("data-tab-id");break}if(s&&t>0){o=r+1<=a-1?r+1:0;e.removeClass(n[r],"selected");e.addClass(n[o],"selected");i=n[o].getAttribute("data-tab-id");break}}var l=this.getListElement();this.updateList(l,this.getTabItems(i));this.selectedTab=i};e.Bizproc.Selector.selectTab=function(t){var s=this.getListElement();var i=this.getTabsElements();for(var r=0;r<i.length;++r){if(i[r]==t){e.addClass(t,"selected");this.updateList(s,this.getTabItems(t.getAttribute("data-tab-id")))}else{e.removeClass(i[r],"selected")}}this.selectedTab=t.getAttribute("data-tab-id")};e.Bizproc.Selector.SelectNextItem=function(t){var s=this.getListElement();var i,r,a,o=0,n=e.findChildren(s,{className:"bp-selector-item"},true);for(r=0,a=n.length;r<a;++r){i=e.hasClass(n[r],"bp-selector-item-selected");if(i&&t<0){o=r-1>=0?r-1:a-1;e.removeClass(n[r],"bp-selector-item-selected");e.addClass(n[o],"bp-selector-item-selected");break}if(i&&t>0){o=r+1<=a-1?r+1:0;e.removeClass(n[r],"bp-selector-item-selected");e.addClass(n[o],"bp-selector-item-selected");break}}this.fixListScroll(s,n[o])};e.Bizproc.Selector.updateList=function(t,s){e.cleanNode(t);var i,r,a,o=this;if(s.length===0){a=e.create("LI",{html:e.message("BIZPROC_JS_BP_SELECTOR_EMPTY_LIST")});e.addClass(a,"bp-selector-item-empty");t.appendChild(a)}for(i=0;i<s.length;++i){r=s[i];a=e.create("LI",{html:e.util.htmlspecialchars(r.text)+(r.description?'<span class="bp-selector-item-description"> '+e.util.htmlspecialchars(r.description)+"</span>":"")});a.setAttribute("data-value",r.value);a.setAttribute("data-cursor-position",r.cursorPosition||"");a.setAttribute("hidefocus","true");e.addClass(a,"bp-selector-item");if(i===0)e.addClass(a,"bp-selector-item-selected");e.bind(a,"click",function(t){o.insertItemValue(this,t.shiftKey===true);if(t.shiftKey!==true)o.closePopup();e.focus(o.inputElement);return e.PreventDefault(t)});t.appendChild(a)}t.scrollTop=0};e.Bizproc.Selector.fixListScroll=function(t,s){var i=e.pos(t);var r=e.pos(s);if(r.bottom>i.bottom||r.top<i.top){t.scrollTop+=r.bottom>i.bottom?r.bottom-i.bottom:r.top-i.top}}})();