84 if(!Loader::includeModule(
'crm'))
87 \Bitrix\Main\UI\Extension::load(
'ui.fonts.opensans');
88 Asset::getInstance()->addCss(
'/bitrix/js/crm/css/crm.css');
89 Asset::getInstance()->addJs(
'/bitrix/js/crm/crm.js');
91 $html = self::getJsHandlerECrm();
93 if(!empty($listProperty)):
97 BX.FilterCrmEntitySelector.messages =
99 'contact':
'<?=GetMessageJS('FIP_CRM_FF_CONTACT
')?>',
100 'company':
'<?=GetMessageJS('FIP_CRM_FF_COMPANY
')?>',
101 'quote':
'<?=GetMessageJS('FIP_CRM_FF_QUOTE_MSGVER_1
')?>',
102 'lead':
'<?=GetMessageJS('FIP_CRM_FF_LEAD
')?>',
103 'deal':
'<?=GetMessageJS('FIP_CRM_FF_DEAL
')?>',
104 'selectButton':
'<?=GetMessageJS('CRM_ENTITY_SEL_BTN
')?>',
105 'noresult':
'<?=GetMessageJS('CRM_SEL_SEARCH_NO_RESULT
')?>',
106 'search':
'<?=GetMessageJS('CRM_ENTITY_SEL_SEARCH
')?>',
107 'last':
'<?=GetMessageJS('CRM_ENTITY_SEL_LAST
')?>'
110 $listAvailableEntity = array(
'DEAL',
'CONTACT',
'COMPANY',
'LEAD');
111 foreach($listProperty as $property)
113 $fieldId = $property[
'FIELD_ID'];
114 $entityTypeNames = array();
115 foreach($property[
'USER_TYPE_SETTINGS'] as $entityType => $useMarker)
117 if($useMarker ==
'Y' && in_array($entityType, $listAvailableEntity))
119 $entityTypeNames[] = $entityType;
122 $isMultiple = $property[
'MULTIPLE'] ==
'Y' ? true :
false;
125 BX.FilterHandlerECrm.create(
126 '<?=\CUtil::JSEscape($filterId.'_
'.$fieldId)?>',
128 fieldId:
'<?=\CUtil::JSEscape($fieldId)?>',
129 entityTypeNames: <?=Json::encode($entityTypeNames)?>,
130 isMultiple: <?=$isMultiple ?
'true' :
'false'?>,
131 title:
'<?=\CUtil::JSEscape($title)?>'
140 $html .= ob_get_contents();
147 protected static function renderByE($filterId, array $listProperty)
151 if(!empty($listProperty))
153 $html .= self::getJsHandlerE();
156 $filterOption =
new FilterOptions($filterId);
157 $filterData = $filterOption->getFilter();
158 foreach($listProperty as $property)
160 $currentElements = array();
161 if(!empty($filterData[$property[
'FIELD_ID']]))
166 $convertValue = $APPLICATION->ConvertCharset(
167 $filterData[$property[
'FIELD_ID']],
'UTF-8', LANG_CHARSET);
168 $currentValues = Json::decode($convertValue);
172 return $e->getMessage();
174 if(is_array($currentValues))
176 foreach($currentValues as $value)
178 $currentElements[] = current($value);
183 $currentElements[] = $currentValues;
187 $APPLICATION->includeComponent(
'bitrix:iblock.element.selector',
'',
189 'SELECTOR_ID' => $filterId.
'_'.$property[
'FIELD_ID'],
190 'SEARCH_INPUT_ID' => $filterId.
'_'.$property[
'FIELD_ID'],
191 'IBLOCK_ID' => $property[
'LINK_IBLOCK_ID'],
193 'PANEL_SELECTED_VALUES' =>
'N',
194 'CURRENT_ELEMENTS_ID' => $currentElements
196 null, array(
'HIDE_ICONS' =>
'Y')
201 BX.FilterHandlerE.create(
202 '<?=\CUtil::JSEscape($filterId.'_
'.$property['FIELD_ID
'])?>',
204 fieldId:
'<?=\CUtil::JSEscape($property['FIELD_ID
'])?>',
205 controlId:
'<?=\CUtil::JSEscape($filterId.'_
'.$property['FIELD_ID
'])?>',
212 $html .= ob_get_contents();
270 if(typeof(
BX.FilterHandlerECrm) ===
'undefined')
272 BX.FilterHandlerECrm =
function()
277 this._control =
null;
278 this._entitySelector =
null;
281 BX.FilterHandlerECrm.prototype =
283 initialize:
function(id, settings)
286 this._settings = settings ? settings : {};
287 this._fieldId = this.getSetting(
'fieldId',
'');
289 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityFocus',
290 BX.delegate(
this.onCustomEntitySelectorOpen,
this));
291 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityBlur',
292 BX.delegate(
this.onCustomEntitySelectorClose,
this));
298 getSetting:
function (name, defaultval)
300 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
302 getSearchInput:
function()
304 return this._control ? this._control.getLabelNode() :
null;
306 onCustomEntitySelectorOpen:
function(control)
308 if(control.getId() !== this._fieldId)
310 this._control =
null;
315 this._control = control;
316 this.closeSiblings();
320 onCustomEntitySelectorClose:
function(control)
322 if(this._fieldId === control.getId())
324 this._control =
null;
328 onSelect:
function(sender, data)
330 if(!this._control || this._control.getId() !== this._fieldId)
337 for(var typeName in data)
339 if(!data.hasOwnProperty(typeName))
344 var infos = data[typeName];
345 for(var i = 0, l = infos.length; i < l; i++)
348 labels.push(info[
'title']);
349 if(typeof(values[typeName]) ===
'undefined')
351 values[typeName] = [];
354 values[typeName].push(info[
'entityId']);
357 this._control.setData(labels.join(
', '), JSON.stringify(values));
361 if(!this._entitySelector)
363 this._entitySelector =
BX.FilterCrmEntitySelector.create(
366 control: this._control,
367 entityTypeNames: this.getSetting(
'entityTypeNames', []),
368 isMultiple: this.getSetting(
'isMultiple',
false),
369 anchor: this.getSearchInput(),
370 title: this.getSetting(
'title',
'')
374 BX.addCustomEvent(this._entitySelector,
'BX.FilterCrmEntitySelector:select',
375 BX.delegate(
this.onSelect,
this));
378 this._entitySelector.open();
381 if(this._entitySelector.getPopup())
383 this._control.setPopupContainer(this._entitySelector.getPopup()[
'contentContainer']);
389 if(this._entitySelector)
391 this._entitySelector.close();
394 this._control.setPopupContainer(
null);
398 closeSiblings:
function()
400 var siblings =
BX.FilterCrmEntitySelector.items;
401 for(var k in siblings)
403 if(siblings.hasOwnProperty(k) && siblings[k] !==
this)
411 BX.FilterHandlerECrm.items = {};
412 BX.FilterHandlerECrm.create =
function(id, settings)
414 var
self =
new BX.FilterHandlerECrm(
id, settings);
415 self.initialize(
id, settings);
416 BX.FilterHandlerECrm.items[
self.getId()] =
self;
421 if(typeof(
BX.FilterCrmEntitySelector) ===
'undefined')
423 BX.FilterCrmEntitySelector =
function()
427 this._entityTypeNames = [];
428 this._isMultiple =
false;
429 this._entityInfos =
null;
430 this._entitySelectHandler =
BX.delegate(this.onEntitySelect,
this);
432 BX.FilterCrmEntitySelector.prototype =
434 initialize:
function(id, settings)
437 this._settings = settings ? settings : {};
438 this._entityTypeNames = this.getSetting(
'entityTypeNames', []);
439 this._isMultiple = this.getSetting(
'isMultiple',
false);
440 this._entityInfos = [];
441 this._control = this.getSetting(
'control',
null)
447 getSetting:
function (name, defaultval)
449 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
451 getMessage:
function(name)
453 var msg =
BX.FilterCrmEntitySelector.messages;
454 return msg.hasOwnProperty(name) ? msg[name] : name;
458 return typeof(obCrm[this._id]) !==
'undefined' ? obCrm[this._id].popup :
null;
462 return ((obCrm[this._id].popup instanceof
BX.PopupWindow) && obCrm[this._id].popup.isShown());
464 getSearchInput:
function()
466 return this._control ? this._control.getLabelNode() :
null;
470 if(typeof(obCrm[this._id]) ===
'undefined')
472 var entityTypes = [];
473 for(var i = 0, l = this._entityTypeNames.length; i < l; i++)
475 entityTypes.push(this._entityTypeNames[i].toLowerCase());
478 obCrm[this._id] =
new CRM(
481 this.getSearchInput(),
488 'contact': this.getMessage(
'contact'),
489 'company': this.getMessage(
'company'),
490 'quote': this.getMessage(
'quote'),
491 'lead': this.getMessage(
'lead'),
492 'deal': this.getMessage(
'deal'),
493 'ok': this.getMessage(
'selectButton'),
494 'cancel':
BX.message(
'JS_CORE_WINDOW_CANCEL'),
495 'close':
BX.message(
'JS_CORE_WINDOW_CLOSE'),
496 'wait':
BX.message(
'JS_CORE_LOADING'),
497 'noresult': this.getMessage(
'noresult'),
498 'search' : this.getMessage(
'search'),
499 'last' : this.getMessage(
'last')
503 obCrm[this._id].Init();
504 obCrm[this._id].AddOnSaveListener(this._entitySelectHandler);
507 if(!((obCrm[this._id].popup instanceof
BX.PopupWindow) && obCrm[
this._id].popup.isShown()))
509 obCrm[this._id].Open(
511 closeIcon: { top:
'10px', right:
'15px' },
515 anchor: this.getSearchInput(),
516 titleBar: this.getSetting(
'title')
523 if(typeof(obCrm[this._id]) !==
'undefined')
525 obCrm[this._id].RemoveOnSaveListener(this._entitySelectHandler);
526 obCrm[this._id].Clear();
527 delete obCrm[this._id];
531 onEntitySelect:
function(settings)
536 for(var type in settings)
538 if(!settings.hasOwnProperty(type))
543 var entityInfos = settings[type];
544 if(!
BX.type.isPlainObject(entityInfos))
549 var typeName = type.toUpperCase();
550 for(var key in entityInfos)
552 if(!entityInfos.hasOwnProperty(key))
557 var entityInfo = entityInfos[key];
558 this._entityInfos.push(
560 'id': entityInfo[
'id'],
561 'type': entityInfo[
'type'],
562 'title': entityInfo[
'title'],
563 'desc': entityInfo[
'desc'],
564 'url': entityInfo[
'url'],
565 'image': entityInfo[
'image'],
566 'selected': entityInfo[
'selected']
570 var entityId =
BX.type.isNotEmptyString(entityInfo[
'id']) ?
571 parseInt(entityInfo[
'id']) : 0;
574 if(typeof(data[typeName]) ===
'undefined')
581 entityTypeName: typeName,
583 title:
BX.type.isNotEmptyString(entityInfo[
'title']) ?
584 entityInfo[
'title'] : (
'[' + entityId +
']')
591 BX.onCustomEvent(
this,
'BX.FilterCrmEntitySelector:select', [
this, data]);
595 if(typeof(
BX.FilterCrmEntitySelector.messages) ===
'undefined')
597 BX.FilterCrmEntitySelector.messages = {};
600 BX.FilterCrmEntitySelector.items = {};
601 BX.FilterCrmEntitySelector.create =
function(id, settings)
603 var
self =
new BX.FilterCrmEntitySelector(
id, settings);
604 self.initialize(
id, settings);
605 BX.FilterCrmEntitySelector.items[
self.getId()] =
self;
612 $script = ob_get_contents();
624 if(typeof(
BX.FilterHandlerEmployee) ===
'undefined')
626 BX.FilterHandlerEmployee =
function() {
630 this._control =
null;
632 this._currentUser =
null;
633 this._controlId =
null;
634 this._controlObj =
null;
635 this._controlContainer =
null;
636 this._serviceContainer =
null;
639 this._isDialogDisplayed =
false;
642 this._inputKeyPressHandler =
BX.delegate(this.onInputKeyPress,
this);
644 BX.FilterHandlerEmployee.prototype =
646 initialize:
function(id, settings)
649 this._settings = settings ? settings : {};
650 this._fieldId = this.getSetting(
'fieldId',
'');
651 this._controlId = this.getSetting(
'controlId',
'');
652 this._controlContainer =
BX(this._controlId +
'_selector_content');
654 this._serviceContainer = this.getSetting(
'serviceContainer',
null);
655 if(!
BX.type.isDomNode(
this._serviceContainer))
657 this._serviceContainer = document.body;
660 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityFocus',
661 BX.delegate(
this.onCustomEntitySelectorOpen,
this));
662 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityBlur',
663 BX.delegate(
this.onCustomEntitySelectorClose,
this));
669 getSetting:
function (name, defaultval)
671 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
673 getSearchInput:
function()
675 return this._control ? this._control.getLabelNode() :
null;
679 return this._isDialogDisplayed;
683 if(this._controlObj ===
null)
685 var objName =
'O_' + this._controlId;
688 throw 'BX.FilterHandlerEmployee: Could not find '+ objName +
' user selector.';
690 this._controlObj = window[objName];
693 var searchInput = this.getSearchInput();
694 if(this._controlObj.searchInput)
696 BX.unbind(this._controlObj.searchInput,
'keyup',
697 BX.proxy(
this._controlObj.search,
this._controlObj));
699 this._controlObj.searchInput = searchInput;
700 BX.bind(this._controlObj.searchInput,
'keyup',
701 BX.proxy(
this._controlObj.search,
this._controlObj));
702 this._controlObj.onSelect =
BX.delegate(this.onSelect,
this);
703 BX.bind(searchInput,
'keyup', this._inputKeyPressHandler);
705 if(this._currentUser)
707 this._controlObj.setSelected([ this._currentUser ]);
711 var selected = this._controlObj.getSelected();
714 for(var key in selected)
716 if(selected.hasOwnProperty(key))
718 this._controlObj.unselect(key);
724 if(this._dialog ===
null)
726 this._controlContainer.style.display =
'';
727 this._dialog =
new BX.PopupWindow(
729 this.getSearchInput(),
736 zIndex: this._zIndex,
737 bindOptions: { forceBindPosition:
true },
738 content : this._controlContainer,
741 onPopupShow:
BX.delegate(this.onDialogShow,
this),
742 onPopupClose:
BX.delegate(this.onDialogClose,
this),
743 onPopupDestroy:
BX.delegate(this.onDialogDestroy,
this)
750 this._controlObj._onFocus();
753 this._control.setPopupContainer(this._controlContainer);
758 var searchInput = this.getSearchInput();
761 BX.bind(searchInput,
'keyup', this._inputKeyPressHandler);
766 this._dialog.close();
771 this._control.setPopupContainer(
null);
774 onCustomEntitySelectorOpen:
function(control)
776 if(control.getId() !== this._fieldId)
778 this._control =
null;
783 this._control = control;
784 var currentValues = this._control.getCurrentValues();
785 this._currentUser = {
'id':currentValues.value,
'name':currentValues.label};
789 onCustomEntitySelectorClose:
function(control)
791 if(control.getId() !== this._fieldId)
797 onDialogShow:
function()
799 this._isDialogDisplayed =
true;
801 onDialogClose:
function()
803 this._isDialogDisplayed =
false;
804 this._controlContainer.parentNode.removeChild(this._controlContainer);
805 this._serviceContainer.appendChild(this._controlContainer);
806 this._controlContainer.style.display =
'none';
807 this._dialog.destroy();
809 onDialogDestroy:
function()
813 onInputKeyPress:
function(e)
815 if(!this._dialog || !this._isDialogDisplayed)
822 this._controlObj.search();
825 onSelect:
function(user)
827 this._currentUser = user;
830 var node = this._control.getLabelNode();
832 this._control.setData(user[
'name'], user[
'id']);
837 BX.FilterHandlerEmployee.closeAll =
function()
839 for(var k in this.items)
841 if(this.items.hasOwnProperty(k))
843 this.items[k].close();
847 BX.FilterHandlerEmployee.items = {};
848 BX.FilterHandlerEmployee.create =
function(id, settings)
850 var
self =
new BX.FilterHandlerEmployee(
id, settings);
851 self.initialize(
id, settings);
852 BX.FilterHandlerEmployee.items[
self.getId()] =
self;
859 $script = ob_get_contents();
871 if(typeof(
BX.FilterHandlerE) ===
'undefined')
873 BX.FilterHandlerE =
function() {
877 this._control =
null;
879 this._currentElements = [];
880 this._controlId =
null;
881 this._controlObj =
null;
882 this._controlContainer =
null;
883 this._serviceContainer =
null;
886 this._isDialogDisplayed =
false;
889 this._inputKeyPressHandler =
BX.proxy(this.onInputKeyPress,
this);
891 BX.FilterHandlerE.prototype =
893 initialize:
function(id, settings)
896 this._settings = settings ? settings : {};
897 this._fieldId = this.getSetting(
'fieldId',
'');
898 this._controlId = this.getSetting(
'controlId',
'');
899 this._multiple = this.getSetting(
'multiple',
'Y') ===
'Y';
900 this._controlContainer =
BX(this._controlId);
902 this._serviceContainer = this.getSetting(
'serviceContainer',
null);
903 if(!
BX.type.isDomNode(
this._serviceContainer))
905 this._serviceContainer = document.body;
908 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityFocus',
909 BX.proxy(
this.onCustomEntitySelectorOpen,
this));
910 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityBlur',
911 BX.proxy(
this.onCustomEntitySelectorClose,
this));
917 getSetting:
function (name, defaultval)
919 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
921 getSearchInput:
function()
923 return this._control ? this._control.getLabelNode() :
null;
927 return this._isDialogDisplayed;
931 if(this._controlObj ===
null)
933 var objName =
BX.Iblock[this._controlId];
936 throw 'BX.FilterHandlerE: Could not find '+ objName +
' element selector.';
938 this._controlObj = objName;
941 this._multiple = this._controlObj.multiple;
942 var searchInput = this.getSearchInput();
943 if(this._controlObj.searchInput)
945 BX.unbind(this._controlObj.searchInput,
'keyup',
946 BX.proxy(
this._controlObj.search,
this._controlObj));
948 this._controlObj.searchInput = searchInput;
949 BX.bind(this._controlObj.searchInput,
'keyup',
950 BX.proxy(
this._controlObj.search,
this._controlObj));
951 this._controlObj.onSelect =
BX.proxy(this.onSelect,
this);
952 BX.bind(searchInput,
'keyup', this._inputKeyPressHandler);
955 this._controlObj.onUnSelect =
BX.proxy(this.onSelect,
this);
958 if(this._currentElements)
960 this._controlObj.setSelected(this._currentElements);
964 var selected = this._controlObj.getSelected();
967 for(var key in selected)
969 if(selected.hasOwnProperty(key))
971 this._controlObj.unselect(key);
977 if(this._dialog ===
null)
979 this._controlContainer.style.display =
'';
980 this._dialog =
new BX.PopupWindow(
982 this.getSearchInput(),
989 zIndex: this._zIndex,
990 bindOptions: { forceBindPosition:
true },
991 content : this._controlContainer,
994 onPopupShow:
BX.delegate(this.onDialogShow,
this),
995 onPopupClose:
BX.delegate(this.onDialogClose,
this),
996 onPopupDestroy:
BX.delegate(this.onDialogDestroy,
this)
1002 this._dialog.show();
1003 this._controlObj._onFocus();
1006 this._control.setPopupContainer(this._controlContainer);
1011 var searchInput = this.getSearchInput();
1014 BX.bind(searchInput,
'keyup', this._inputKeyPressHandler);
1019 this._dialog.close();
1024 this._control.setPopupContainer(
null);
1027 onCustomEntitySelectorOpen:
function(control)
1029 if(control.getId() !== this._fieldId)
1031 this._control =
null;
1036 this._control = control;
1037 var currentValues = this._control.getCurrentValues();
1038 if(!!currentValues.value)
1040 this._currentElements = [];
1043 var values = JSON.parse(currentValues.value);
1044 for(var k in values)
1046 this._currentElements.push(
1047 {
"id": values[k][0],
"name": values[k][1]});
1052 this._currentElements.push(
1053 {
"id": currentValues.value,
"name": currentValues.label});
1059 onCustomEntitySelectorClose:
function(control)
1061 if (control.getId() !== this._fieldId)
1066 var currentValues = control.getCurrentValues();
1067 if (!currentValues.value && control.getLabelNode())
1069 var value = control.getLabelNode().value;
1070 if (parseInt(value))
1072 control.getLabelNode().value =
"";
1073 control.setData(value, value);
1079 onDialogShow:
function()
1081 this._isDialogDisplayed =
true;
1083 onDialogClose:
function()
1085 this._isDialogDisplayed =
false;
1086 this._controlContainer.parentNode.removeChild(this._controlContainer);
1087 this._serviceContainer.appendChild(this._controlContainer);
1088 this._controlContainer.style.display =
'none';
1089 this._dialog.destroy();
1091 onDialogDestroy:
function()
1093 this._dialog =
null;
1095 onInputKeyPress:
function()
1097 if(!this._dialog || !this._isDialogDisplayed)
1101 if(this._controlObj)
1103 this._controlObj.search();
1106 onSelect:
function(element)
1108 if(!this._control || this._control.getId() !== this._fieldId)
1112 var node = this._control.getLabelNode();
1117 this._currentElements = element;
1120 for(var k in this._currentElements)
1122 if(!this._currentElements.hasOwnProperty(k) || !this._currentElements[k])
1126 labels.push(this._currentElements[k].name);
1127 if(typeof(values[this._currentElements[k].
id]) ===
'undefined')
1129 values[this._currentElements[k].id] = [];
1131 values[this._currentElements[k].id].push(this._currentElements[k].
id);
1132 values[this._currentElements[k].id].push(this._currentElements[k].name);
1134 if (labels.join(
', '))
1136 this._control.setData(labels.join(
', '), JSON.stringify(values));
1140 this._control.removeSquares();
1145 this._currentElements.push(element);
1146 this._control.setData(element.name, element.id);
1151 BX.FilterHandlerE.closeAll =
function()
1153 for(var k in this.items)
1155 if(this.items.hasOwnProperty(k))
1157 this.items[k].close();
1161 BX.FilterHandlerE.items = {};
1162 BX.FilterHandlerE.create =
function(id, settings)
1164 var
self =
new BX.FilterHandlerE(
id, settings);
1165 self.initialize(
id, settings);
1166 BX.FilterHandlerE.items[
self.getId()] =
self;
1173 $script = ob_get_contents();
1178 protected static function addFilterByE($property, $controlSettings, &$filter, &$filtered)
1182 $filterOption = new \Bitrix\Main\UI\Filter\Options($controlSettings[
"FILTER_ID"]);
1183 $filterData = $filterOption->getFilter();
1184 if(!empty($filterData[$controlSettings[
'VALUE']]))
1185 $currentValue = $filterData[$controlSettings[
'VALUE']];
1187 if(!empty($currentValue))
1192 global $APPLICATION;
1193 $currentValue = $APPLICATION->ConvertCharset($currentValue,
'UTF-8', LANG_CHARSET);
1194 $currentValues = Json::decode($currentValue);
1195 if(is_array($currentValues))
1197 foreach($currentValues as $value)
1199 $values[] = current($value);
1204 $values[] = $currentValues;
1208 $filter[$controlSettings[
'VALUE']] = array();
1209 foreach($values as $value)
1211 $filter[$controlSettings[
'VALUE']][] = intval($value);