14 return Loc::getMessage(
'BP_FIELDTYPE_MAIL_SENDER') ?: parent::getName();
19 $options = static::makeMailboxListSelectOptions(static::getMailboxList());
20 return static::normalizeOptions($options);
25 return static::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
30 return static::renderControl($fieldType, $field, $value, $allowSelection, $renderMode);
35 $providers = static::getMailboxList();
36 $fieldName = htmlspecialcharsbx(static::generateControlName($field));
41 if (is_array($typeValue))
43 $typeValue = (string)current($value);
46 $valueHtml = htmlspecialcharsbx((
string)$typeValue);
49 if ($allowSelection && $isPublicControl)
51 $nodeAttributes = sprintf(
52 'data-role="inline-selector-target" data-select-mode="replace" data-property="%s" ',
53 htmlspecialcharsbx(Main\Web\Json::encode($fieldType->
getProperty()))
57 if (!$isPublicControl)
59 $nodeAttributes .=
'style="opacity: 1" ';
62 $controlId = htmlspecialcharsbx(static::generateControlId($field));
63 $className = htmlspecialcharsbx(static::generateControlClassName($fieldType, $field));
64 $placeholder = htmlspecialcharsbx(
Loc::getMessage(
'BP_FIELDTYPE_MAIL_SENDER_AUTO'));
73 class=
"{$className} bizproc-type-control-select-wide"
74 placeholder=
"{$placeholder}"
79 if ($allowSelection && !$isPublicControl)
81 $node .= static::renderControlSelectorButton($controlId, $fieldType,
'replace');
84 return $node . static::getJs($providers, $controlId);
87 private static function getMailboxList()
89 $mailboxes = Main\Mail\Sender::prepareUserMailboxes();
94 private static function makeMailboxListSelectOptions(array $mailboxes)
97 foreach ($mailboxes as $mailbox)
100 $mailbox[
'name'] ?
'%s <%s>' :
'%s%s',
101 $mailbox[
'name'], $mailbox[
'email']
104 $options[$boxValue] = $boxValue;
110 private static function getJs(array $mailboxes,
string $controlId)
112 $mailboxesJs = Main\Web\Json::encode($mailboxes);
113 $controlIdJs = \CUtil::JSEscape($controlId);
115 $textAuto = \CUtil::JSEscape(
Loc::getMessage(
'BP_FIELDTYPE_MAIL_SENDER_AUTO'));
116 $textAdd = \CUtil::JSEscape(
Loc::getMessage(
'BP_FIELDTYPE_MAIL_SENDER_ADD'));
122 var mailboxSelectorValue = document.getElementById(
'{$controlIdJs}');
123 if (!mailboxSelectorValue)
128 var mailboxes = {$mailboxesJs};
130 var setMailbox =
function(value)
132 mailboxSelectorValue.value = value;
135 var getMenuItems =
function()
137 var i, menuItems = [{
139 onclick:
function(e, item)
141 this.popupWindow.close();
146 for (i = 0; i < mailboxes.length; ++i)
148 var mailbox = mailboxes[i];
149 var mailboxName = mailbox[
'name'].length > 0
150 ? mailbox[
'name'] +
' <' + mailbox[
'email'] +
'>'
154 text:
BX.util.htmlspecialchars(mailboxName),
156 onclick: function(e, item)
158 this.popupWindow.close();
159 setMailbox(item.value);
164 if (window.BXMainMailConfirm)
166 if (menuItems.length > 0)
168 menuItems.push({delimiter:
true});
173 onclick:
function(e, item)
175 this.popupWindow.close();
176 window.BXMainMailConfirm.showForm(
function(mailbox)
178 mailboxes.push(mailbox);
179 setMailbox(mailbox[
'name'].length > 0
180 ? mailbox[
'name'] +
' <' + mailbox[
'email'] +
'>'
190 BX.bind(mailboxSelectorValue,
'click',
function(e)
193 var menuId =
'crm-sma-mailboxes' + Math.random();
200 offsetLeft: (
BX.pos(
this)[
'width'] / 2),
201 angle: { position:
'top', offset: 0 },
202 overlay: { backgroundColor:
'transparent' },
205 onPopupClose:
function()
static getMessage($code, $replace=null, $language=null)