PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/activities/bitrix/mailactivity/robot_properties_dialog.php

https://gitlab.com/alexprowars/bitrix
PHP | 241 lines | 216 code | 22 blank | 3 comment | 10 complexity | df67a68e7207ee2dd2ec43d01fdc3958 MD5 | raw file
  1. <?php
  2. if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();
  3. /** @var \Bitrix\Bizproc\Activity\PropertiesDialog $dialog */
  4. /** @global \CMain $APPLICATION $map */
  5. global $APPLICATION;
  6. $map = $dialog->getMap();
  7. $messageText = $map['MailText'];
  8. $subject = $map['MailSubject'];
  9. $messageType = $dialog->getCurrentValue($map['MailMessageType']['FieldName'], 'html');
  10. $attachmentType = isset($map['FileType']) ? $map['FileType'] : null;
  11. $attachment = isset($map['File']) ? $map['File'] : null;
  12. $from = isset($map['MailUserFrom']) ? $map['MailUserFrom'] : null;
  13. $fromValue = $from ? $dialog->getCurrentValue($from['FieldName'],'') : null;
  14. $fromValue = \CBPHelper::UsersArrayToString($fromValue, $dialog->getWorkflowTemplate(), $dialog->getDocumentType());
  15. $runtimeData = $dialog->getRuntimeData();
  16. $mailboxes = $runtimeData['mailboxes'];
  17. if ($from):?>
  18. <div style="display:none;">
  19. <?
  20. $APPLICATION->IncludeComponent('bitrix:main.mail.confirm', '');
  21. ?>
  22. </div>
  23. <div class="bizproc-automation-popup-settings bizproc-automation-popup-settings-text">
  24. <span class="bizproc-automation-popup-settings-title"><?=htmlspecialcharsbx($from['Name'])?>:</span>
  25. <input type="hidden" name="<?=htmlspecialcharsbx($from['FieldName'])?>" value="<?=htmlspecialcharsbx($fromValue)?>" data-role="mailbox-selector-value">
  26. <a class="bizproc-automation-popup-settings-link" data-role="mailbox-selector"></a>
  27. </div>
  28. <?
  29. endif;
  30. ?>
  31. <div class="bizproc-automation-popup-settings">
  32. <span class="bizproc-automation-popup-settings-title bizproc-automation-popup-settings-title-autocomplete">
  33. <?=htmlspecialcharsbx($map['MailUserTo']['Name'])?>:
  34. </span>
  35. <?=$dialog->renderFieldControl($map['MailUserTo'])?>
  36. </div>
  37. <div class="bizproc-automation-popup-settings">
  38. <?=$dialog->renderFieldControl($subject)?>
  39. </div>
  40. <div class="bizproc-automation-popup-settings" data-role="inline-selector-html">
  41. <div class="bizproc-automation-popup-select"><?php
  42. $emailEditor = new CHTMLEditor;
  43. $content = $dialog->getCurrentValue($messageText['FieldName'], '');
  44. if ($dialog->getCurrentValue('mail_message_encoded'))
  45. {
  46. $content = \CBPMailActivity::decodeMailText($content);
  47. $content = \Bitrix\Bizproc\Automation\Helper::convertExpressions($content, $dialog->getDocumentType());
  48. }
  49. if ($messageType !== 'html')
  50. {
  51. $parser = new CTextParser();
  52. $content = $parser->convertText($content);
  53. }
  54. $emailEditor->show(array(
  55. 'name' => $messageText['FieldName'],
  56. 'content' => $content,
  57. 'siteId' => SITE_ID,
  58. 'width' => '100%',
  59. 'minBodyWidth' => 630,
  60. 'normalBodyWidth' => 630,
  61. 'height' => 198,
  62. 'minBodyHeight' => 198,
  63. 'showTaskbars' => false,
  64. 'showNodeNavi' => false,
  65. 'autoResize' => true,
  66. 'autoResizeOffset' => 40,
  67. 'bbCode' => false,
  68. 'saveOnBlur' => false,
  69. 'bAllowPhp' => false,
  70. 'limitPhpAccess' => false,
  71. 'setFocusAfterShow' => false,
  72. 'askBeforeUnloadPage' => true,
  73. 'useFileDialogs' => false,
  74. 'controlsMap' => array(
  75. array('id' => 'Bold', 'compact' => true, 'sort' => 10),
  76. array('id' => 'Italic', 'compact' => true, 'sort' => 20),
  77. array('id' => 'Underline', 'compact' => true, 'sort' => 30),
  78. array('id' => 'Strikeout', 'compact' => true, 'sort' => 40),
  79. array('id' => 'RemoveFormat', 'compact' => true, 'sort' => 50),
  80. array('id' => 'Color', 'compact' => true, 'sort' => 60),
  81. array('id' => 'FontSelector', 'compact' => false, 'sort' => 70),
  82. array('id' => 'FontSize', 'compact' => false, 'sort' => 80),
  83. array('separator' => true, 'compact' => false, 'sort' => 90),
  84. array('id' => 'OrderedList', 'compact' => true, 'sort' => 100),
  85. array('id' => 'UnorderedList', 'compact' => true, 'sort' => 110),
  86. array('id' => 'AlignList', 'compact' => false, 'sort' => 120),
  87. array('separator' => true, 'compact' => false, 'sort' => 130),
  88. array('id' => 'InsertLink', 'compact' => true, 'sort' => 140),
  89. array('id' => 'InsertImage', 'compact' => false, 'sort' => 150),
  90. array('id' => 'InsertTable', 'compact' => false, 'sort' => 170),
  91. array('id' => 'Code', 'compact' => true, 'sort' => 180),
  92. array('id' => 'Quote', 'compact' => true, 'sort' => 190),
  93. array('separator' => true, 'compact' => false, 'sort' => 200),
  94. array('id' => 'Fullscreen', 'compact' => false, 'sort' => 210),
  95. array('id' => 'ChangeView', 'compact' => true, 'sort' => 220),
  96. array('id' => 'More', 'compact' => true, 'sort' => 400)
  97. ),
  98. ));
  99. ?></div>
  100. </div>
  101. <input type="hidden" name="<?=htmlspecialcharsbx($map['MailMessageType']['FieldName'])?>" value="html">
  102. <input type="hidden" name="<?=htmlspecialcharsbx($map['MailCharset']['FieldName'])?>" value="<?=htmlspecialcharsbx(SITE_CHARSET)?>">
  103. <input type="hidden" name="<?=htmlspecialcharsbx($map['DirrectMail']['FieldName'])?>" value="Y">
  104. <input type="hidden" name="<?=htmlspecialcharsbx($map['MailSite']['FieldName'])?>" value="<?=htmlspecialcharsbx(SITE_ID)?>">
  105. <?
  106. $config = array(
  107. 'type' => $dialog->getCurrentValue($attachmentType['FieldName']),
  108. 'typeInputName' => $attachmentType['FieldName'],
  109. 'valueInputName' => $attachment['FieldName'],
  110. 'multiple' => $attachment['Multiple'],
  111. 'required' => !empty($attachment['Required']),
  112. 'useDisk' => CModule::IncludeModule('disk'),
  113. 'label' => $attachment['Name'],
  114. 'labelFile' => $attachmentType['Options']['file'],
  115. 'labelDisk' => $attachmentType['Options']['disk']
  116. );
  117. if ($dialog->getCurrentValue($attachmentType['FieldName']) === 'disk')
  118. {
  119. $config['selected'] = \Bitrix\Bizproc\Automation\Helper::prepareDiskAttachments(
  120. $dialog->getCurrentValue($attachment['FieldName'])
  121. );
  122. }
  123. else
  124. {
  125. $config['selected'] = \Bitrix\Bizproc\Automation\Helper::prepareFileAttachments(
  126. $dialog->getDocumentType(),
  127. $dialog->getCurrentValue($attachment['FieldName'])
  128. );
  129. }
  130. $configAttributeValue = htmlspecialcharsbx(\Bitrix\Main\Web\Json::encode($config));
  131. ?>
  132. <div class="bizproc-automation-popup-settings" data-role="file-selector" data-config="<?=$configAttributeValue?>"></div>
  133. <?if ($from):?>
  134. <script>
  135. BX.ready(function ()
  136. {
  137. var dialog = BX.Bizproc.Automation.Designer.getRobotSettingsDialog();
  138. if (!dialog)
  139. {
  140. return;
  141. }
  142. var mailboxes = <?=\Bitrix\Main\Web\Json::encode($mailboxes);?>;
  143. var mailboxSelector = dialog.form.querySelector('[data-role="mailbox-selector"]');
  144. var mailboxSelectorValue = dialog.form.querySelector('[data-role="mailbox-selector-value"]');
  145. var setMailbox = function(value)
  146. {
  147. mailboxSelector.textContent = value ? value : '<?=GetMessageJS('BPMA_RPD_FROM_EMPTY')?>';
  148. mailboxSelectorValue.value = value;
  149. };
  150. var getMenuItems = function()
  151. {
  152. var i, menuItems = [];
  153. for (i = 0; i < mailboxes.length; ++i)
  154. {
  155. var mailbox = mailboxes[i];
  156. var mailboxName = mailbox['name'].length > 0
  157. ? mailbox['name'] + ' <' + mailbox['email'] + '>'
  158. : mailbox['email'];
  159. menuItems.push({
  160. text: BX.util.htmlspecialchars(mailboxName),
  161. value: mailboxName,
  162. onclick: function(e, item)
  163. {
  164. this.popupWindow.close();
  165. setMailbox(item.value);
  166. }
  167. });
  168. }
  169. if (window.BXMainMailConfirm)
  170. {
  171. if (menuItems.length > 0)
  172. {
  173. menuItems.push({delimiter: true});
  174. }
  175. menuItems.push({
  176. text: '<?=GetMessageJS('BPMA_RPD_FROM_ADD')?>',
  177. onclick: function(e, item)
  178. {
  179. this.popupWindow.close();
  180. window.BXMainMailConfirm.showForm(function(mailbox)
  181. {
  182. mailboxes.push(mailbox);
  183. setMailbox(mailbox['name'].length > 0
  184. ? mailbox['name'] + ' <' + mailbox['email'] + '>'
  185. : mailbox['email']);
  186. });
  187. }
  188. });
  189. }
  190. return menuItems;
  191. };
  192. BX.bind(mailboxSelector, 'click', function(e)
  193. {
  194. var menuId = 'bpma-mailboxes' + Math.random();
  195. BX.PopupMenu.show(
  196. menuId,
  197. this,
  198. getMenuItems(),
  199. {
  200. autoHide: true,
  201. offsetLeft: (BX.pos(this)['width'] / 2),
  202. angle: { position: 'top', offset: 0 },
  203. overlay: { backgroundColor: 'transparent' },
  204. events:
  205. {
  206. onPopupClose: function()
  207. {
  208. this.destroy();
  209. }
  210. }
  211. },
  212. );
  213. }
  214. );
  215. //init
  216. setMailbox(mailboxSelectorValue.value);
  217. });
  218. </script>
  219. <?endif;