BxMsgFormEntry.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Messages Messages
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxBaseModTextFormEntry');
  12. /**
  13. * Create/Edit entry form
  14. */
  15. class BxMsgFormEntry extends BxBaseModTextFormEntry
  16. {
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. self::$MODULE = 'bx_messages';
  20. parent::__construct($aInfo, $oTemplate);
  21. $aJs = array (
  22. 'jquery.ui.all.min.js', // TODO: remake by adding individual files, instead of all
  23. );
  24. BxDolTemplate::getInstance()->addJs($aJs);
  25. }
  26. public function insert ($aValsToAdd = array(), $isIgnore = false)
  27. {
  28. $aValsToAdd['last_reply_timestamp'] = time();
  29. $aValsToAdd['last_reply_profile_id'] = bx_get_logged_profile_id();
  30. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  31. if (!$iContentId)
  32. return 0;
  33. bx_import('BxDolProfile');
  34. // for author place conversation to "sent" folder
  35. $this->_oModule->_oDb->conversationToFolder($iContentId, BX_MSG_FOLDER_SENT, bx_get_logged_profile_id(), 0);
  36. // check for spam
  37. $bSpam = false;
  38. bx_alert('system', 'check_spam', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => $this->getCleanValue('text'), 'where' => 'messages'));
  39. $iFolder = $bSpam ? BX_MSG_FOLDER_SPAM : BX_MSG_FOLDER_INBOX;
  40. // for all collaborators to "inbox" or "spam"
  41. $aRecipients = array_unique($this->getCleanValue('recipients'), SORT_NUMERIC);
  42. foreach ($aRecipients as $iProfile) {
  43. $oProfile = BxDolProfile::getInstance($iProfile);
  44. if ($oProfile)
  45. $this->_oModule->_oDb->conversationToFolder($iContentId, $iFolder, $oProfile->id());
  46. }
  47. return $iContentId;
  48. }
  49. protected function genCustomInputRecipients ($aInput) {
  50. $sVals = '';
  51. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  52. foreach ($aInput['value'] as $sVal) {
  53. $sVals .= '<span class="bx-def-color-bg-hl bx-def-round-corners">' . BxDolProfile::getInstance($sVal)->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></span>';
  54. }
  55. $sVals = trim($sVals, ',');
  56. }
  57. $sId = $aInput['name'] . time();
  58. $sPlaceholderText = bx_html_attribute("Type name here...", BX_ESCAPE_STR_QUOTE); // TODO: lang key
  59. $sUrlGetRecipients = BX_DOL_URL_ROOT . "modules/?r=messages/ajax_get_recipients";
  60. return <<<EOS
  61. <script>
  62. $(function() {
  63. $('#{$sId} input[type=text]').autocomplete({
  64. source: "{$sUrlGetRecipients}",
  65. select: function(e, ui) {
  66. $(this).val(ui.item.label);
  67. $(this).trigger('superselect', ui.item);
  68. e.preventDefault();
  69. }
  70. });
  71. $('#{$sId} input[type=text]').on('superselect', function(e, item) {
  72. if ('undefined' != typeof(item))
  73. $(this).before('<span class="bx-def-color-bg-hl bx-def-round-corners">'+ item.label +'<input type="hidden" name="{$aInput['name']}[]" value="'+ item.value +'" /></span>');
  74. this.value = '';
  75. }).on('keydown', function(e) {
  76. // if: comma,enter (delimit more keyCodes with | pipe)
  77. if (/(13)/.test(e.which))
  78. e.preventDefault();
  79. });
  80. $('#{$sId}').on('click', 'span', function() {
  81. $(this).remove();
  82. });
  83. });
  84. </script>
  85. <style>
  86. .bx-form-input-autotoken {
  87. float:left;
  88. padding:0px;
  89. height:auto;
  90. }
  91. .bx-form-input-autotoken span {
  92. cursor:pointer;
  93. display:block;
  94. float:left;
  95. padding:0.5em;
  96. padding-right:1.5em;
  97. margin:0.1em;
  98. }
  99. .bx-form-input-autotoken span:hover{
  100. opacity:0.7;
  101. }
  102. .bx-form-input-autotoken span:after{
  103. position:absolute;
  104. content:"x";
  105. padding:0 0.5em;
  106. margin:0.2em 0 0.7em 0.5em;
  107. font-size:0.7em;
  108. font-weight:bold;
  109. }
  110. .bx-form-input-autotoken input {
  111. border:0;
  112. margin:0;
  113. padding:0 0 0 5px;
  114. width:auto;
  115. }
  116. </style>
  117. <div id="{$sId}" class="bx-form-input-autotoken bx-def-font-inputs bx-form-input-text">
  118. {$sVals}
  119. <input type="text" value="" placeholder="{$sPlaceholderText}" class="bx-def-font-inputs bx-form-input-text" />
  120. </div>
  121. EOS;
  122. }
  123. }
  124. /** @} */