268 if(typeof(BX.FilterHandlerECrm) ===
'undefined')
270 BX.FilterHandlerECrm =
function()
275 this._control =
null;
276 this._entitySelector =
null;
279 BX.FilterHandlerECrm.prototype =
281 initialize:
function(id, settings)
284 this._settings = settings ? settings : {};
285 this._fieldId = this.getSetting(
'fieldId',
'');
287 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityFocus',
288 BX.delegate(
this.onCustomEntitySelectorOpen,
this));
289 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityBlur',
290 BX.delegate(
this.onCustomEntitySelectorClose,
this));
296 getSetting:
function (name, defaultval)
298 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
300 getSearchInput:
function()
302 return this._control ? this._control.getLabelNode() :
null;
304 onCustomEntitySelectorOpen:
function(control)
306 if(control.getId() !==
this._fieldId)
308 this._control =
null;
313 this._control = control;
314 this.closeSiblings();
318 onCustomEntitySelectorClose:
function(control)
320 if(this._fieldId === control.getId())
322 this._control =
null;
326 onSelect:
function(sender, data)
328 if(!this._control || this._control.getId() !==
this._fieldId)
335 for(var typeName in data)
337 if(!data.hasOwnProperty(typeName))
342 var infos = data[typeName];
343 for(var i = 0, l = infos.length; i < l; i++)
346 labels.push(info[
'title']);
347 if(typeof(values[typeName]) ===
'undefined')
349 values[typeName] = [];
352 values[typeName].push(info[
'entityId']);
355 this._control.setData(labels.join(
', '), JSON.stringify(values));
359 if(!this._entitySelector)
361 this._entitySelector = BX.FilterCrmEntitySelector.create(
364 control: this._control,
365 entityTypeNames: this.getSetting(
'entityTypeNames', []),
366 isMultiple: this.getSetting(
'isMultiple',
false),
367 anchor: this.getSearchInput(),
368 title: this.getSetting(
'title',
'')
372 BX.addCustomEvent(this._entitySelector,
'BX.FilterCrmEntitySelector:select',
373 BX.delegate(
this.onSelect,
this));
376 this._entitySelector.open();
379 if(this._entitySelector.getPopup())
381 this._control.setPopupContainer(this._entitySelector.getPopup()[
'contentContainer']);
387 if(this._entitySelector)
389 this._entitySelector.close();
392 this._control.setPopupContainer(
null);
396 closeSiblings:
function()
398 var siblings = BX.FilterCrmEntitySelector.items;
399 for(var k in siblings)
401 if(siblings.hasOwnProperty(k) && siblings[k] !==
this)
409 BX.FilterHandlerECrm.items = {};
410 BX.FilterHandlerECrm.create =
function(id, settings)
412 var
self =
new BX.FilterHandlerECrm(
id, settings);
413 self.initialize(
id, settings);
414 BX.FilterHandlerECrm.items[
self.getId()] =
self;
419 if(typeof(BX.FilterCrmEntitySelector) ===
'undefined')
421 BX.FilterCrmEntitySelector =
function()
425 this._entityTypeNames = [];
426 this._isMultiple =
false;
427 this._entityInfos =
null;
428 this._entitySelectHandler = BX.delegate(this.onEntitySelect,
this);
430 BX.FilterCrmEntitySelector.prototype =
432 initialize:
function(id, settings)
435 this._settings = settings ? settings : {};
436 this._entityTypeNames = this.getSetting(
'entityTypeNames', []);
437 this._isMultiple = this.getSetting(
'isMultiple',
false);
438 this._entityInfos = [];
439 this._control = this.getSetting(
'control',
null)
445 getSetting:
function (name, defaultval)
447 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
449 getMessage:
function(name)
451 var msg = BX.FilterCrmEntitySelector.messages;
452 return msg.hasOwnProperty(name) ? msg[name] : name;
456 return typeof(obCrm[this._id]) !==
'undefined' ? obCrm[this._id].popup :
null;
460 return ((obCrm[this._id].popup instanceof BX.PopupWindow) && obCrm[
this._id].popup.isShown());
462 getSearchInput:
function()
464 return this._control ? this._control.getLabelNode() :
null;
468 if(typeof(obCrm[this._id]) ===
'undefined')
470 var entityTypes = [];
471 for(var i = 0, l = this._entityTypeNames.length; i < l; i++)
473 entityTypes.push(this._entityTypeNames[i].toLowerCase());
476 obCrm[this._id] =
new CRM(
479 this.getSearchInput(),
486 'contact': this.getMessage(
'contact'),
487 'company': this.getMessage(
'company'),
488 'quote': this.getMessage(
'quote'),
489 'lead': this.getMessage(
'lead'),
490 'deal': this.getMessage(
'deal'),
491 'ok': this.getMessage(
'selectButton'),
492 'cancel': BX.message(
'JS_CORE_WINDOW_CANCEL'),
493 'close': BX.message(
'JS_CORE_WINDOW_CLOSE'),
494 'wait': BX.message(
'JS_CORE_LOADING'),
495 'noresult': this.getMessage(
'noresult'),
496 'search' : this.getMessage(
'search'),
497 'last' : this.getMessage(
'last')
501 obCrm[this._id].Init();
502 obCrm[this._id].AddOnSaveListener(this._entitySelectHandler);
505 if(!((obCrm[this._id].popup instanceof BX.PopupWindow) && obCrm[
this._id].popup.isShown()))
507 obCrm[this._id].Open(
509 closeIcon: {
top:
'10px',
right:
'15px' },
513 anchor: this.getSearchInput(),
514 titleBar: this.getSetting(
'title')
521 if(typeof(obCrm[this._id]) !==
'undefined')
523 obCrm[this._id].RemoveOnSaveListener(this._entitySelectHandler);
524 obCrm[this._id].Clear();
525 delete obCrm[this._id];
529 onEntitySelect:
function(settings)
534 for(var type in settings)
536 if(!settings.hasOwnProperty(type))
541 var entityInfos = settings[type];
542 if(!BX.type.isPlainObject(entityInfos))
547 var typeName = type.toUpperCase();
548 for(var key in entityInfos)
550 if(!entityInfos.hasOwnProperty(key))
555 var entityInfo = entityInfos[key];
556 this._entityInfos.push(
558 'id': entityInfo[
'id'],
559 'type': entityInfo[
'type'],
560 'title': entityInfo[
'title'],
561 'desc': entityInfo[
'desc'],
562 'url': entityInfo[
'url'],
563 'image': entityInfo[
'image'],
564 'selected': entityInfo[
'selected']
568 var entityId = BX.type.isNotEmptyString(entityInfo[
'id']) ?
569 parseInt(entityInfo[
'id']) : 0;
572 if(typeof(data[typeName]) ===
'undefined')
579 entityTypeName: typeName,
581 title: BX.type.isNotEmptyString(entityInfo[
'title']) ?
582 entityInfo[
'title'] : (
'[' + entityId +
']')
589 BX.onCustomEvent(
this,
'BX.FilterCrmEntitySelector:select', [
this, data]);
593 if(typeof(BX.FilterCrmEntitySelector.messages) ===
'undefined')
595 BX.FilterCrmEntitySelector.messages = {};
598 BX.FilterCrmEntitySelector.items = {};
599 BX.FilterCrmEntitySelector.create =
function(id, settings)
601 var
self =
new BX.FilterCrmEntitySelector(
id, settings);
602 self.initialize(
id, settings);
603 BX.FilterCrmEntitySelector.items[
self.getId()] =
self;
610 $script = ob_get_contents();
622 if(typeof(BX.FilterHandlerEmployee) ===
'undefined')
624 BX.FilterHandlerEmployee =
function() {
628 this._control =
null;
630 this._currentUser =
null;
631 this._controlId =
null;
632 this._controlObj =
null;
633 this._controlContainer =
null;
634 this._serviceContainer =
null;
637 this._isDialogDisplayed =
false;
640 this._inputKeyPressHandler = BX.delegate(this.onInputKeyPress,
this);
642 BX.FilterHandlerEmployee.prototype =
644 initialize:
function(id, settings)
647 this._settings = settings ? settings : {};
648 this._fieldId = this.getSetting(
'fieldId',
'');
649 this._controlId = this.getSetting(
'controlId',
'');
650 this._controlContainer = BX(this._controlId +
'_selector_content');
652 this._serviceContainer = this.getSetting(
'serviceContainer',
null);
653 if(!BX.type.isDomNode(
this._serviceContainer))
655 this._serviceContainer = document.body;
658 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityFocus',
659 BX.delegate(
this.onCustomEntitySelectorOpen,
this));
660 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityBlur',
661 BX.delegate(
this.onCustomEntitySelectorClose,
this));
667 getSetting:
function (name, defaultval)
669 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
671 getSearchInput:
function()
673 return this._control ? this._control.getLabelNode() :
null;
677 return this._isDialogDisplayed;
681 if(this._controlObj ===
null)
683 var objName =
'O_' + this._controlId;
686 throw 'BX.FilterHandlerEmployee: Could not find '+ objName +
' user selector.';
688 this._controlObj = window[objName];
691 var searchInput = this.getSearchInput();
692 if(this._controlObj.searchInput)
694 BX.unbind(this._controlObj.searchInput,
'keyup',
695 BX.proxy(
this._controlObj.search,
this._controlObj));
697 this._controlObj.searchInput = searchInput;
698 BX.bind(this._controlObj.searchInput,
'keyup',
699 BX.proxy(
this._controlObj.search,
this._controlObj));
700 this._controlObj.onSelect = BX.delegate(this.onSelect,
this);
701 BX.bind(searchInput,
'keyup', this._inputKeyPressHandler);
703 if(this._currentUser)
705 this._controlObj.setSelected([ this._currentUser ]);
709 var
selected = this._controlObj.getSelected();
716 this._controlObj.unselect(key);
722 if(this._dialog ===
null)
724 this._controlContainer.style.display =
'';
725 this._dialog =
new BX.PopupWindow(
727 this.getSearchInput(),
734 zIndex: this._zIndex,
735 bindOptions: { forceBindPosition:
true },
736 content : this._controlContainer,
739 onPopupShow: BX.delegate(this.onDialogShow,
this),
740 onPopupClose: BX.delegate(this.onDialogClose,
this),
741 onPopupDestroy: BX.delegate(this.onDialogDestroy,
this)
748 this._controlObj._onFocus();
751 this._control.setPopupContainer(this._controlContainer);
756 var searchInput = this.getSearchInput();
759 BX.bind(searchInput,
'keyup', this._inputKeyPressHandler);
764 this._dialog.close();
769 this._control.setPopupContainer(
null);
772 onCustomEntitySelectorOpen:
function(control)
774 if(control.getId() !==
this._fieldId)
776 this._control =
null;
781 this._control = control;
782 var currentValues = this._control.getCurrentValues();
783 this._currentUser = {
'id':currentValues.value,
'name':currentValues.label};
787 onCustomEntitySelectorClose:
function(control)
789 if(control.getId() !==
this._fieldId)
795 onDialogShow:
function()
797 this._isDialogDisplayed =
true;
799 onDialogClose:
function()
801 this._isDialogDisplayed =
false;
802 this._controlContainer.parentNode.removeChild(this._controlContainer);
803 this._serviceContainer.appendChild(this._controlContainer);
804 this._controlContainer.style.display =
'none';
805 this._dialog.destroy();
807 onDialogDestroy:
function()
811 onInputKeyPress:
function(e)
813 if(!this._dialog || !this._isDialogDisplayed)
820 this._controlObj.search();
823 onSelect:
function(user)
825 this._currentUser = user;
828 var node = this._control.getLabelNode();
830 this._control.setData(user[
'name'], user[
'id']);
835 BX.FilterHandlerEmployee.closeAll =
function()
837 for(var k in this.items)
839 if(this.items.hasOwnProperty(k))
841 this.items[k].close();
845 BX.FilterHandlerEmployee.items = {};
846 BX.FilterHandlerEmployee.create =
function(id, settings)
848 var
self =
new BX.FilterHandlerEmployee(
id, settings);
849 self.initialize(
id, settings);
850 BX.FilterHandlerEmployee.items[
self.getId()] =
self;
857 $script = ob_get_contents();
869 if(typeof(BX.FilterHandlerE) ===
'undefined')
871 BX.FilterHandlerE =
function() {
875 this._control =
null;
877 this._currentElements = [];
878 this._controlId =
null;
879 this._controlObj =
null;
880 this._controlContainer =
null;
881 this._serviceContainer =
null;
884 this._isDialogDisplayed =
false;
887 this._inputKeyPressHandler = BX.proxy(this.onInputKeyPress,
this);
889 BX.FilterHandlerE.prototype =
891 initialize:
function(id, settings)
894 this._settings = settings ? settings : {};
895 this._fieldId = this.getSetting(
'fieldId',
'');
896 this._controlId = this.getSetting(
'controlId',
'');
897 this._multiple = this.getSetting(
'multiple',
'Y') ===
'Y';
898 this._controlContainer = BX(this._controlId);
900 this._serviceContainer = this.getSetting(
'serviceContainer',
null);
901 if(!BX.type.isDomNode(
this._serviceContainer))
903 this._serviceContainer = document.body;
906 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityFocus',
907 BX.proxy(
this.onCustomEntitySelectorOpen,
this));
908 BX.addCustomEvent(window,
'BX.Main.Filter:customEntityBlur',
909 BX.proxy(
this.onCustomEntitySelectorClose,
this));
915 getSetting:
function (name, defaultval)
917 return this._settings.hasOwnProperty(name) ? this._settings[name] : defaultval;
919 getSearchInput:
function()
921 return this._control ? this._control.getLabelNode() :
null;
925 return this._isDialogDisplayed;
929 if(this._controlObj ===
null)
931 var objName = BX.Iblock[this._controlId];
934 throw 'BX.FilterHandlerE: Could not find '+ objName +
' element selector.';
936 this._controlObj = objName;
939 this._multiple = this._controlObj.multiple;
940 var searchInput = this.getSearchInput();
941 if(this._controlObj.searchInput)
943 BX.unbind(this._controlObj.searchInput,
'keyup',
944 BX.proxy(
this._controlObj.search,
this._controlObj));
946 this._controlObj.searchInput = searchInput;
947 BX.bind(this._controlObj.searchInput,
'keyup',
948 BX.proxy(
this._controlObj.search,
this._controlObj));
949 this._controlObj.onSelect = BX.proxy(this.onSelect,
this);
950 BX.bind(searchInput,
'keyup', this._inputKeyPressHandler);
953 this._controlObj.onUnSelect = BX.proxy(this.onSelect,
this);
956 if(this._currentElements)
958 this._controlObj.setSelected(this._currentElements);
962 var
selected = this._controlObj.getSelected();
969 this._controlObj.unselect(key);
975 if(this._dialog ===
null)
977 this._controlContainer.style.display =
'';
978 this._dialog =
new BX.PopupWindow(
980 this.getSearchInput(),
987 zIndex: this._zIndex,
988 bindOptions: { forceBindPosition:
true },
989 content : this._controlContainer,
992 onPopupShow: BX.delegate(this.onDialogShow,
this),
993 onPopupClose: BX.delegate(this.onDialogClose,
this),
994 onPopupDestroy: BX.delegate(this.onDialogDestroy,
this)
1000 this._dialog.show();
1001 this._controlObj._onFocus();
1004 this._control.setPopupContainer(this._controlContainer);
1009 var searchInput = this.getSearchInput();
1012 BX.bind(searchInput,
'keyup', this._inputKeyPressHandler);
1017 this._dialog.close();
1022 this._control.setPopupContainer(
null);
1025 onCustomEntitySelectorOpen:
function(control)
1027 if(control.getId() !==
this._fieldId)
1029 this._control =
null;
1034 this._control = control;
1035 var currentValues = this._control.getCurrentValues();
1036 if(!!currentValues.value)
1038 this._currentElements = [];
1041 var values = JSON.parse(currentValues.value);
1042 for(var k in values)
1044 this._currentElements.push(
1045 {
"id": values[k][0],
"name": values[k][1]});
1050 this._currentElements.push(
1051 {
"id": currentValues.value,
"name": currentValues.label});
1057 onCustomEntitySelectorClose:
function(control)
1059 if (control.getId() !==
this._fieldId)
1064 var currentValues = control.getCurrentValues();
1065 if (!currentValues.value && control.getLabelNode())
1067 var value = control.getLabelNode().value;
1068 if (parseInt(value))
1070 control.getLabelNode().value =
"";
1071 control.setData(value, value);
1077 onDialogShow:
function()
1079 this._isDialogDisplayed =
true;
1081 onDialogClose:
function()
1083 this._isDialogDisplayed =
false;
1084 this._controlContainer.parentNode.removeChild(this._controlContainer);
1085 this._serviceContainer.appendChild(this._controlContainer);
1086 this._controlContainer.style.display =
'none';
1087 this._dialog.destroy();
1089 onDialogDestroy:
function()
1091 this._dialog =
null;
1093 onInputKeyPress:
function()
1095 if(!this._dialog || !this._isDialogDisplayed)
1099 if(this._controlObj)
1101 this._controlObj.search();
1104 onSelect:
function(element)
1106 if(!this._control || this._control.getId() !==
this._fieldId)
1110 var node = this._control.getLabelNode();
1115 this._currentElements = element;
1118 for(var k in this._currentElements)
1120 if(!this._currentElements.hasOwnProperty(k) || !
this._currentElements[k])
1124 labels.push(this._currentElements[k].name);
1125 if(typeof(values[this._currentElements[k].
id]) ===
'undefined')
1127 values[this._currentElements[k].id] = [];
1129 values[this._currentElements[k].id].push(this._currentElements[k].
id);
1130 values[this._currentElements[k].id].push(this._currentElements[k].name);
1132 if (labels.join(
', '))
1134 this._control.setData(labels.join(
', '), JSON.stringify(values));
1138 this._control.removeSquares();
1143 this._currentElements.push(element);
1144 this._control.setData(element.name, element.id);
1149 BX.FilterHandlerE.closeAll =
function()
1151 for(var k in this.items)
1153 if(this.items.hasOwnProperty(k))
1155 this.items[k].close();
1159 BX.FilterHandlerE.items = {};
1160 BX.FilterHandlerE.create =
function(id, settings)
1162 var
self =
new BX.FilterHandlerE(
id, settings);
1163 self.initialize(
id, settings);
1164 BX.FilterHandlerE.items[
self.getId()] =
self;
1171 $script = ob_get_contents();