Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
property.php
1<?php
3
5use Bitrix\Main\Page\Asset;
9use Bitrix\Main\UI\Filter\Options as FilterOptions;
10
11Loc::loadMessages(__FILE__);
12
21{
30 public static function render($filterId, $propertyType, array $listProperty)
31 {
32 $result = '';
38 if(method_exists(__CLASS__, 'renderBy'.$propertyType))
39 {
40 $renderMethod = 'renderBy'.$propertyType;
41 $result = self::$renderMethod($filterId, $listProperty);
42 }
43
44 return $result;
45 }
46
56 public static function addFilter($property, $controlSettings, &$filter, &$filtered)
57 {
58 if(isset($property['PROPERTY_USER_TYPE']['USER_TYPE'])
59 && method_exists(__CLASS__, 'addFilterBy'.$property['PROPERTY_USER_TYPE']['USER_TYPE']))
60 {
61 $renderMethod = 'addFilterBy'.$property['PROPERTY_USER_TYPE']['USER_TYPE'];
62 self::$renderMethod($property, $controlSettings, $filter, $filtered);
63 }
64 elseif($property['PROPERTY_TYPE'] != '')
65 {
66 $renderMethod = 'addFilterBy'.$property['PROPERTY_TYPE'];
67 if(method_exists(__CLASS__, $renderMethod))
68 {
69 self::$renderMethod($property, $controlSettings, $filter, $filtered);
70 }
71 }
72 elseif($property['TYPE'] != '')
73 {
74 $renderMethod = 'addFilterBy'.str_replace('_', '', $property['TYPE']);
75 if(method_exists(__CLASS__, $renderMethod))
76 {
77 self::$renderMethod($property, $controlSettings, $filter, $filtered);
78 }
79 }
80 }
81
82 protected static function renderByECrm($filterId, $listProperty)
83 {
84 if(!Loader::includeModule('crm'))
85 return '';
86
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');
90
91 $html = self::getJsHandlerECrm();
92
93 if(!empty($listProperty)):
94 ob_start(); ?>
95 <script>
96 BX.ready(function() {
97 BX.FilterCrmEntitySelector.messages =
98 {
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')?>'
108 };
109 <?
110 $listAvailableEntity = array('DEAL', 'CONTACT', 'COMPANY', 'LEAD');
111 foreach($listProperty as $property)
112 {
113 $fieldId = $property['FIELD_ID'];
114 $entityTypeNames = array();
115 foreach($property['USER_TYPE_SETTINGS'] as $entityType => $useMarker)
116 {
117 if($useMarker == 'Y' && in_array($entityType, $listAvailableEntity))
118 {
119 $entityTypeNames[] = $entityType;
120 }
121 }
122 $isMultiple = $property['MULTIPLE'] == 'Y' ? true : false;
123 $title = '';
124 ?>
125 BX.FilterHandlerECrm.create(
126 '<?=\CUtil::JSEscape($filterId.'_'.$fieldId)?>',
127 {
128 fieldId: '<?=\CUtil::JSEscape($fieldId)?>',
129 entityTypeNames: <?=Json::encode($entityTypeNames)?>,
130 isMultiple: <?=$isMultiple ? 'true' : 'false'?>,
131 title: '<?=\CUtil::JSEscape($title)?>'
132 }
133 );
134 <?
135 }
136 ?>
137 });
138 </script>
139 <?
140 $html .= ob_get_contents();
141 ob_end_clean();
142 endif;
143
144 return $html;
145 }
146
147 protected static function renderByE($filterId, array $listProperty)
148 {
149 $html = '';
150
151 if(!empty($listProperty))
152 {
153 $html .= self::getJsHandlerE();
154 global $APPLICATION;
155
156 $filterOption = new FilterOptions($filterId);
157 $filterData = $filterOption->getFilter();
158 foreach($listProperty as $property)
159 {
160 $currentElements = array();
161 if(!empty($filterData[$property['FIELD_ID']]))
162 {
163 try
164 {
165 global $APPLICATION;
166 $convertValue = $APPLICATION->ConvertCharset(
167 $filterData[$property['FIELD_ID']], 'UTF-8', LANG_CHARSET);
168 $currentValues = Json::decode($convertValue);
169 }
170 catch(SystemException $e)
171 {
172 return $e->getMessage();
173 }
174 if(is_array($currentValues))
175 {
176 foreach($currentValues as $value)
177 {
178 $currentElements[] = current($value);
179 }
180 }
181 else
182 {
183 $currentElements[] = $currentValues;
184 }
185 }
186 ob_start();
187 $APPLICATION->includeComponent('bitrix:iblock.element.selector', '',
188 array(
189 'SELECTOR_ID' => $filterId.'_'.$property['FIELD_ID'],
190 'SEARCH_INPUT_ID' => $filterId.'_'.$property['FIELD_ID'],
191 'IBLOCK_ID' => $property['LINK_IBLOCK_ID'],
192 'MULTIPLE' => 'Y',
193 'PANEL_SELECTED_VALUES' => 'N',
194 'CURRENT_ELEMENTS_ID' => $currentElements
195 ),
196 null, array('HIDE_ICONS' => 'Y')
197 );
198 ?>
199 <script>
200 BX.ready(function(){
201 BX.FilterHandlerE.create(
202 '<?=\CUtil::JSEscape($filterId.'_'.$property['FIELD_ID'])?>',
203 {
204 fieldId: '<?=\CUtil::JSEscape($property['FIELD_ID'])?>',
205 controlId: '<?=\CUtil::JSEscape($filterId.'_'.$property['FIELD_ID'])?>',
206 multiple: 'Y'
207 }
208 );
209 });
210 </script>
211 <?
212 $html .= ob_get_contents();
213 ob_end_clean();
214 }
215 }
216
217 return $html;
218 }
219
220 protected static function renderByEmployee($filterId, array $listProperty)
221 {
222 if(!Loader::includeModule('intranet'))
223 return '';
224
225 $html = '';
226 if(!empty($listProperty))
227 {
228 $html .= self::getJsHandlerEmployee();
229 global $APPLICATION;
230 ob_start();
231 foreach($listProperty as $property):
232 $APPLICATION->includeComponent('bitrix:intranet.user.selector.new', '',
233 array(
234 'MULTIPLE' => 'N',
235 'NAME' => $filterId.'_'.$property['FIELD_ID'],
236 'INPUT_NAME' => mb_strtolower($filterId.'_'.$property['FIELD_ID']),
237 'POPUP' => 'Y',
238 'SITE_ID' => SITE_ID,
239 'SHOW_EXTRANET_USERS' => 'NONE',
240 ),
241 null, array('HIDE_ICONS' => 'Y')
242 );
243 ?>
244 <script>
245 BX.ready(function(){
246 BX.FilterHandlerEmployee.create(
247 '<?=\CUtil::JSEscape($filterId.'_'.$property['FIELD_ID'])?>',
248 {
249 fieldId: '<?=\CUtil::JSEscape($property['FIELD_ID'])?>',
250 controlId: '<?=\CUtil::JSEscape($filterId.'_'.$property['FIELD_ID'])?>'
251 }
252 );
253 });
254 </script>
255 <? endforeach;
256 $html .= ob_get_contents();
257 ob_end_clean();
258 }
259
260 return $html;
261 }
262
263 protected static function getJsHandlerECrm()
264 {
265 ob_start();
266 ?>
267 <script>
268 (function () {
269 'use strict';
270 if(typeof(BX.FilterHandlerECrm) === 'undefined')
271 {
272 BX.FilterHandlerECrm = function()
273 {
274 this._id = '';
275 this._settings = {};
276 this._fieldId = '';
277 this._control = null;
278 this._entitySelector = null;
279 };
280
281 BX.FilterHandlerECrm.prototype =
282 {
283 initialize: function(id, settings)
284 {
285 this._id = id;
286 this._settings = settings ? settings : {};
287 this._fieldId = this.getSetting('fieldId', '');
288
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));
293 },
294 getId: function()
295 {
296 return this._id;
297 },
298 getSetting: function (name, defaultval)
299 {
300 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
301 },
302 getSearchInput: function()
303 {
304 return this._control ? this._control.getLabelNode() : null;
305 },
306 onCustomEntitySelectorOpen: function(control)
307 {
308 if(control.getId() !== this._fieldId)
309 {
310 this._control = null;
311 this.close();
312 }
313 else
314 {
315 this._control = control;
316 this.closeSiblings();
317 this.open();
318 }
319 },
320 onCustomEntitySelectorClose: function(control)
321 {
322 if(this._fieldId === control.getId())
323 {
324 this._control = null;
325 this.close();
326 }
327 },
328 onSelect: function(sender, data)
329 {
330 if(!this._control || this._control.getId() !== this._fieldId)
331 {
332 return;
333 }
334
335 var labels = [];
336 var values = {};
337 for(var typeName in data)
338 {
339 if(!data.hasOwnProperty(typeName))
340 {
341 continue;
342 }
343
344 var infos = data[typeName];
345 for(var i = 0, l = infos.length; i < l; i++)
346 {
347 var info = infos[i];
348 labels.push(info['title']);
349 if(typeof(values[typeName]) === 'undefined')
350 {
351 values[typeName] = [];
352 }
353
354 values[typeName].push(info['entityId']);
355 }
356 }
357 this._control.setData(labels.join(', '), JSON.stringify(values));
358 },
359 open: function()
360 {
361 if(!this._entitySelector)
362 {
363 this._entitySelector = BX.FilterCrmEntitySelector.create(
364 this._id,
365 {
366 control: this._control,
367 entityTypeNames: this.getSetting('entityTypeNames', []),
368 isMultiple: this.getSetting('isMultiple', false),
369 anchor: this.getSearchInput(),
370 title: this.getSetting('title', '')
371 }
372 );
373
374 BX.addCustomEvent(this._entitySelector, 'BX.FilterCrmEntitySelector:select',
375 BX.delegate(this.onSelect, this));
376 }
377
378 this._entitySelector.open();
379 if(this._control)
380 {
381 if(this._entitySelector.getPopup())
382 {
383 this._control.setPopupContainer(this._entitySelector.getPopup()['contentContainer']);
384 }
385 }
386 },
387 close: function()
388 {
389 if(this._entitySelector)
390 {
391 this._entitySelector.close();
392 if(this._control)
393 {
394 this._control.setPopupContainer(null);
395 }
396 }
397 },
398 closeSiblings: function()
399 {
400 var siblings = BX.FilterCrmEntitySelector.items;
401 for(var k in siblings)
402 {
403 if(siblings.hasOwnProperty(k) && siblings[k] !== this)
404 {
405 siblings[k].close();
406 }
407 }
408 }
409 };
410
411 BX.FilterHandlerECrm.items = {};
412 BX.FilterHandlerECrm.create = function(id, settings)
413 {
414 var self = new BX.FilterHandlerECrm(id, settings);
415 self.initialize(id, settings);
416 BX.FilterHandlerECrm.items[self.getId()] = self;
417 return self;
418 }
419 }
420
421 if(typeof(BX.FilterCrmEntitySelector) === 'undefined')
422 {
423 BX.FilterCrmEntitySelector = function()
424 {
425 this._id = '';
426 this._settings = {};
427 this._entityTypeNames = [];
428 this._isMultiple = false;
429 this._entityInfos = null;
430 this._entitySelectHandler = BX.delegate(this.onEntitySelect, this);
431 };
432 BX.FilterCrmEntitySelector.prototype =
433 {
434 initialize: function(id, settings)
435 {
436 this._id = id;
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)
442 },
443 getId: function()
444 {
445 return this._id;
446 },
447 getSetting: function (name, defaultval)
448 {
449 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
450 },
451 getMessage: function(name)
452 {
453 var msg = BX.FilterCrmEntitySelector.messages;
454 return msg.hasOwnProperty(name) ? msg[name] : name;
455 },
456 getPopup: function()
457 {
458 return typeof(obCrm[this._id]) !== 'undefined' ? obCrm[this._id].popup : null;
459 },
460 isOpened: function()
461 {
462 return ((obCrm[this._id].popup instanceof BX.PopupWindow) && obCrm[this._id].popup.isShown());
463 },
464 getSearchInput: function()
465 {
466 return this._control ? this._control.getLabelNode() : null;
467 },
468 open: function()
469 {
470 if(typeof(obCrm[this._id]) === 'undefined')
471 {
472 var entityTypes = [];
473 for(var i = 0, l = this._entityTypeNames.length; i < l; i++)
474 {
475 entityTypes.push(this._entityTypeNames[i].toLowerCase());
476 }
477
478 obCrm[this._id] = new CRM(
479 this._id,
480 null,
481 this.getSearchInput(),
482 this._id,
483 this._entityInfos,
484 false,
485 this._isMultiple,
486 entityTypes,
487 {
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')
500 },
501 true
502 );
503 obCrm[this._id].Init();
504 obCrm[this._id].AddOnSaveListener(this._entitySelectHandler);
505 }
506
507 if(!((obCrm[this._id].popup instanceof BX.PopupWindow) && obCrm[this._id].popup.isShown()))
508 {
509 obCrm[this._id].Open(
510 {
511 closeIcon: { top: '10px', right: '15px' },
512 closeByEsc: true,
513 autoHide: false,
514 gainFocus: false,
515 anchor: this.getSearchInput(),
516 titleBar: this.getSetting('title')
517 }
518 );
519 }
520 },
521 close: function()
522 {
523 if(typeof(obCrm[this._id]) !== 'undefined')
524 {
525 obCrm[this._id].RemoveOnSaveListener(this._entitySelectHandler);
526 obCrm[this._id].Clear();
527 delete obCrm[this._id];
528 }
529
530 },
531 onEntitySelect: function(settings)
532 {
533 this.close();
534
535 var data = {};
536 for(var type in settings)
537 {
538 if(!settings.hasOwnProperty(type))
539 {
540 continue;
541 }
542
543 var entityInfos = settings[type];
544 if(!BX.type.isPlainObject(entityInfos))
545 {
546 continue;
547 }
548
549 var typeName = type.toUpperCase();
550 for(var key in entityInfos)
551 {
552 if(!entityInfos.hasOwnProperty(key))
553 {
554 continue;
555 }
556
557 var entityInfo = entityInfos[key];
558 this._entityInfos.push(
559 {
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']
567 }
568 );
569
570 var entityId = BX.type.isNotEmptyString(entityInfo['id']) ?
571 parseInt(entityInfo['id']) : 0;
572 if(entityId > 0)
573 {
574 if(typeof(data[typeName]) === 'undefined')
575 {
576 data[typeName] = [];
577 }
578
579 data[typeName].push(
580 {
581 entityTypeName: typeName,
582 entityId: entityId,
583 title: BX.type.isNotEmptyString(entityInfo['title']) ?
584 entityInfo['title'] : ('[' + entityId + ']')
585 }
586 );
587 }
588 }
589 }
590
591 BX.onCustomEvent(this, 'BX.FilterCrmEntitySelector:select', [this, data]);
592 }
593 };
594
595 if(typeof(BX.FilterCrmEntitySelector.messages) === 'undefined')
596 {
597 BX.FilterCrmEntitySelector.messages = {};
598 }
599
600 BX.FilterCrmEntitySelector.items = {};
601 BX.FilterCrmEntitySelector.create = function(id, settings)
602 {
603 var self = new BX.FilterCrmEntitySelector(id, settings);
604 self.initialize(id, settings);
605 BX.FilterCrmEntitySelector.items[self.getId()] = self;
606 return self;
607 }
608 }
609 })();
610 </script>
611 <?
612 $script = ob_get_contents();
613 ob_end_clean();
614 return $script;
615 }
616
617 protected static function getJsHandlerEmployee()
618 {
619 ob_start();
620 ?>
621 <script>
622 (function () {
623 'use strict';
624 if(typeof(BX.FilterHandlerEmployee) === 'undefined')
625 {
626 BX.FilterHandlerEmployee = function() {
627 this._id = '';
628 this._settings = {};
629 this._fieldId = '';
630 this._control = null;
631
632 this._currentUser = null;
633 this._controlId = null;
634 this._controlObj = null;
635 this._controlContainer = null;
636 this._serviceContainer = null;
637
638 this._zIndex = 1100;
639 this._isDialogDisplayed = false;
640 this._dialog = null;
641
642 this._inputKeyPressHandler = BX.delegate(this.onInputKeyPress, this);
643 };
644 BX.FilterHandlerEmployee.prototype =
645 {
646 initialize: function(id, settings)
647 {
648 this._id = id;
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');
653
654 this._serviceContainer = this.getSetting('serviceContainer', null);
655 if(!BX.type.isDomNode(this._serviceContainer))
656 {
657 this._serviceContainer = document.body;
658 }
659
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));
664 },
665 getId: function()
666 {
667 return this._id;
668 },
669 getSetting: function (name, defaultval)
670 {
671 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
672 },
673 getSearchInput: function()
674 {
675 return this._control ? this._control.getLabelNode() : null;
676 },
677 isOpened: function()
678 {
679 return this._isDialogDisplayed;
680 },
681 open: function()
682 {
683 if(this._controlObj === null)
684 {
685 var objName = 'O_' + this._controlId;
686 if(!window[objName])
687 {
688 throw 'BX.FilterHandlerEmployee: Could not find '+ objName +' user selector.';
689 }
690 this._controlObj = window[objName];
691 }
692
693 var searchInput = this.getSearchInput();
694 if(this._controlObj.searchInput)
695 {
696 BX.unbind(this._controlObj.searchInput, 'keyup',
697 BX.proxy(this._controlObj.search, this._controlObj));
698 }
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);
704
705 if(this._currentUser)
706 {
707 this._controlObj.setSelected([ this._currentUser ]);
708 }
709 else
710 {
711 var selected = this._controlObj.getSelected();
712 if(selected)
713 {
714 for(var key in selected)
715 {
716 if(selected.hasOwnProperty(key))
717 {
718 this._controlObj.unselect(key);
719 }
720 }
721 }
722 }
723
724 if(this._dialog === null)
725 {
726 this._controlContainer.style.display = '';
727 this._dialog = new BX.PopupWindow(
728 this._id,
729 this.getSearchInput(),
730 {
731 autoHide: false,
732 draggable: false,
733 closeByEsc: true,
734 offsetLeft: 0,
735 offsetTop: 0,
736 zIndex: this._zIndex,
737 bindOptions: { forceBindPosition: true },
738 content : this._controlContainer,
739 events:
740 {
741 onPopupShow: BX.delegate(this.onDialogShow, this),
742 onPopupClose: BX.delegate(this.onDialogClose, this),
743 onPopupDestroy: BX.delegate(this.onDialogDestroy, this)
744 }
745 }
746 );
747 }
748
749 this._dialog.show();
750 this._controlObj._onFocus();
751 if(this._control)
752 {
753 this._control.setPopupContainer(this._controlContainer);
754 }
755 },
756 close: function()
757 {
758 var searchInput = this.getSearchInput();
759 if(searchInput)
760 {
761 BX.bind(searchInput, 'keyup', this._inputKeyPressHandler);
762 }
763
764 if(this._dialog)
765 {
766 this._dialog.close();
767 }
768
769 if(this._control)
770 {
771 this._control.setPopupContainer(null);
772 }
773 },
774 onCustomEntitySelectorOpen: function(control)
775 {
776 if(control.getId() !== this._fieldId)
777 {
778 this._control = null;
779 this.close();
780 }
781 else
782 {
783 this._control = control;
784 var currentValues = this._control.getCurrentValues();
785 this._currentUser = {'id':currentValues.value,'name':currentValues.label};
786 this.open();
787 }
788 },
789 onCustomEntitySelectorClose: function(control)
790 {
791 if(control.getId() !== this._fieldId)
792 {
793 return;
794 }
795 this.close();
796 },
797 onDialogShow: function()
798 {
799 this._isDialogDisplayed = true;
800 },
801 onDialogClose: function()
802 {
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();
808 },
809 onDialogDestroy: function()
810 {
811 this._dialog = null;
812 },
813 onInputKeyPress: function(e)
814 {
815 if(!this._dialog || !this._isDialogDisplayed)
816 {
817 this.open();
818 }
819
820 if(this._controlObj)
821 {
822 this._controlObj.search();
823 }
824 },
825 onSelect: function(user)
826 {
827 this._currentUser = user;
828 if(this._control)
829 {
830 var node = this._control.getLabelNode();
831 node.value = '';
832 this._control.setData(user['name'], user['id']);
833 }
834 this.close();
835 }
836 };
837 BX.FilterHandlerEmployee.closeAll = function()
838 {
839 for(var k in this.items)
840 {
841 if(this.items.hasOwnProperty(k))
842 {
843 this.items[k].close();
844 }
845 }
846 };
847 BX.FilterHandlerEmployee.items = {};
848 BX.FilterHandlerEmployee.create = function(id, settings)
849 {
850 var self = new BX.FilterHandlerEmployee(id, settings);
851 self.initialize(id, settings);
852 BX.FilterHandlerEmployee.items[self.getId()] = self;
853 return self;
854 }
855 }
856 })();
857 </script>
858 <?
859 $script = ob_get_contents();
860 ob_end_clean();
861 return $script;
862 }
863
864 protected static function getJsHandlerE()
865 {
866 ob_start();
867 ?>
868 <script>
869 (function () {
870 'use strict';
871 if(typeof(BX.FilterHandlerE) === 'undefined')
872 {
873 BX.FilterHandlerE = function() {
874 this._id = '';
875 this._settings = {};
876 this._fieldId = '';
877 this._control = null;
878
879 this._currentElements = [];
880 this._controlId = null;
881 this._controlObj = null;
882 this._controlContainer = null;
883 this._serviceContainer = null;
884
885 this._zIndex = 1100;
886 this._isDialogDisplayed = false;
887 this._dialog = null;
888
889 this._inputKeyPressHandler = BX.proxy(this.onInputKeyPress, this);
890 };
891 BX.FilterHandlerE.prototype =
892 {
893 initialize: function(id, settings)
894 {
895 this._id = id;
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);
901
902 this._serviceContainer = this.getSetting('serviceContainer', null);
903 if(!BX.type.isDomNode(this._serviceContainer))
904 {
905 this._serviceContainer = document.body;
906 }
907
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));
912 },
913 getId: function()
914 {
915 return this._id;
916 },
917 getSetting: function (name, defaultval)
918 {
919 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
920 },
921 getSearchInput: function()
922 {
923 return this._control ? this._control.getLabelNode() : null;
924 },
925 isOpened: function()
926 {
927 return this._isDialogDisplayed;
928 },
929 open: function()
930 {
931 if(this._controlObj === null)
932 {
933 var objName = BX.Iblock[this._controlId];
934 if(!objName)
935 {
936 throw 'BX.FilterHandlerE: Could not find '+ objName +' element selector.';
937 }
938 this._controlObj = objName;
939 }
940
941 this._multiple = this._controlObj.multiple;
942 var searchInput = this.getSearchInput();
943 if(this._controlObj.searchInput)
944 {
945 BX.unbind(this._controlObj.searchInput, 'keyup',
946 BX.proxy(this._controlObj.search, this._controlObj));
947 }
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);
953 if(this._multiple)
954 {
955 this._controlObj.onUnSelect = BX.proxy(this.onSelect, this);
956 }
957
958 if(this._currentElements)
959 {
960 this._controlObj.setSelected(this._currentElements);
961 }
962 else
963 {
964 var selected = this._controlObj.getSelected();
965 if(selected)
966 {
967 for(var key in selected)
968 {
969 if(selected.hasOwnProperty(key))
970 {
971 this._controlObj.unselect(key);
972 }
973 }
974 }
975 }
976
977 if(this._dialog === null)
978 {
979 this._controlContainer.style.display = '';
980 this._dialog = new BX.PopupWindow(
981 this._id,
982 this.getSearchInput(),
983 {
984 autoHide: false,
985 draggable: false,
986 closeByEsc: true,
987 offsetLeft: 0,
988 offsetTop: 0,
989 zIndex: this._zIndex,
990 bindOptions: { forceBindPosition: true },
991 content : this._controlContainer,
992 events:
993 {
994 onPopupShow: BX.delegate(this.onDialogShow, this),
995 onPopupClose: BX.delegate(this.onDialogClose, this),
996 onPopupDestroy: BX.delegate(this.onDialogDestroy, this)
997 }
998 }
999 );
1000 }
1001
1002 this._dialog.show();
1003 this._controlObj._onFocus();
1004 if(this._control)
1005 {
1006 this._control.setPopupContainer(this._controlContainer);
1007 }
1008 },
1009 close: function()
1010 {
1011 var searchInput = this.getSearchInput();
1012 if(searchInput)
1013 {
1014 BX.bind(searchInput, 'keyup', this._inputKeyPressHandler);
1015 }
1016
1017 if(this._dialog)
1018 {
1019 this._dialog.close();
1020 }
1021
1022 if(this._control)
1023 {
1024 this._control.setPopupContainer(null);
1025 }
1026 },
1027 onCustomEntitySelectorOpen: function(control)
1028 {
1029 if(control.getId() !== this._fieldId)
1030 {
1031 this._control = null;
1032 this.close();
1033 }
1034 else
1035 {
1036 this._control = control;
1037 var currentValues = this._control.getCurrentValues();
1038 if(!!currentValues.value)
1039 {
1040 this._currentElements = [];
1041 if(this._multiple)
1042 {
1043 var values = JSON.parse(currentValues.value);
1044 for(var k in values)
1045 {
1046 this._currentElements.push(
1047 {"id": values[k][0], "name": values[k][1]});
1048 }
1049 }
1050 else
1051 {
1052 this._currentElements.push(
1053 {"id": currentValues.value, "name": currentValues.label});
1054 }
1055 }
1056 this.open();
1057 }
1058 },
1059 onCustomEntitySelectorClose: function(control)
1060 {
1061 if (control.getId() !== this._fieldId)
1062 {
1063 return;
1064 }
1065
1066 var currentValues = control.getCurrentValues();
1067 if (!currentValues.value && control.getLabelNode())
1068 {
1069 var value = control.getLabelNode().value;
1070 if (parseInt(value))
1071 {
1072 control.getLabelNode().value = "";
1073 control.setData(value, value);
1074 }
1075 }
1076
1077 this.close();
1078 },
1079 onDialogShow: function()
1080 {
1081 this._isDialogDisplayed = true;
1082 },
1083 onDialogClose: function()
1084 {
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();
1090 },
1091 onDialogDestroy: function()
1092 {
1093 this._dialog = null;
1094 },
1095 onInputKeyPress: function()
1096 {
1097 if(!this._dialog || !this._isDialogDisplayed)
1098 {
1099 this.open();
1100 }
1101 if(this._controlObj)
1102 {
1103 this._controlObj.search();
1104 }
1105 },
1106 onSelect: function(element)
1107 {
1108 if(!this._control || this._control.getId() !== this._fieldId)
1109 {
1110 return;
1111 }
1112 var node = this._control.getLabelNode();
1113 node.value = '';
1114
1115 if(this._multiple)
1116 {
1117 this._currentElements = element;
1118 var labels = [];
1119 var values = {};
1120 for(var k in this._currentElements)
1121 {
1122 if(!this._currentElements.hasOwnProperty(k) || !this._currentElements[k])
1123 {
1124 continue;
1125 }
1126 labels.push(this._currentElements[k].name);
1127 if(typeof(values[this._currentElements[k].id]) === 'undefined')
1128 {
1129 values[this._currentElements[k].id] = [];
1130 }
1131 values[this._currentElements[k].id].push(this._currentElements[k].id);
1132 values[this._currentElements[k].id].push(this._currentElements[k].name);
1133 }
1134 if (labels.join(', '))
1135 {
1136 this._control.setData(labels.join(', '), JSON.stringify(values));
1137 }
1138 else
1139 {
1140 this._control.removeSquares();
1141 }
1142 }
1143 else
1144 {
1145 this._currentElements.push(element);
1146 this._control.setData(element.name, element.id);
1147 this.close();
1148 }
1149 }
1150 };
1151 BX.FilterHandlerE.closeAll = function()
1152 {
1153 for(var k in this.items)
1154 {
1155 if(this.items.hasOwnProperty(k))
1156 {
1157 this.items[k].close();
1158 }
1159 }
1160 };
1161 BX.FilterHandlerE.items = {};
1162 BX.FilterHandlerE.create = function(id, settings)
1163 {
1164 var self = new BX.FilterHandlerE(id, settings);
1165 self.initialize(id, settings);
1166 BX.FilterHandlerE.items[self.getId()] = self;
1167 return self;
1168 }
1169 }
1170 })();
1171 </script>
1172 <?
1173 $script = ob_get_contents();
1174 ob_end_clean();
1175 return $script;
1176 }
1177
1178 protected static function addFilterByE($property, $controlSettings, &$filter, &$filtered)
1179 {
1180 $filtered = false;
1181
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']];
1186
1187 if(!empty($currentValue))
1188 {
1189 try
1190 {
1191 $values = array();
1192 global $APPLICATION;
1193 $currentValue = $APPLICATION->ConvertCharset($currentValue, 'UTF-8', LANG_CHARSET);
1194 $currentValues = Json::decode($currentValue);
1195 if(is_array($currentValues))
1196 {
1197 foreach($currentValues as $value)
1198 {
1199 $values[] = current($value);
1200 }
1201 }
1202 else
1203 {
1204 $values[] = $currentValues;
1205 }
1206 if(!empty($values))
1207 {
1208 $filter[$controlSettings['VALUE']] = array();
1209 foreach($values as $value)
1210 {
1211 $filter[$controlSettings['VALUE']][] = intval($value);
1212 }
1213 $filtered = true;
1214 }
1215 }
1216 catch(SystemException $e)
1217 {
1218 return;
1219 }
1220 }
1221 }
1222}
static renderByE($filterId, array $listProperty)
Definition property.php:147
static render($filterId, $propertyType, array $listProperty)
Definition property.php:30
static addFilterByE($property, $controlSettings, &$filter, &$filtered)
static renderByEmployee($filterId, array $listProperty)
Definition property.php:220
static renderByECrm($filterId, $listProperty)
Definition property.php:82
static addFilter($property, $controlSettings, &$filter, &$filtered)
Definition property.php:56
static loadMessages($file)
Definition loc.php:64