BxCnvFormEntry.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 Convos Convos
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxBaseModTextFormEntry');
  12. /**
  13. * Create/Edit entry form
  14. */
  15. class BxCnvFormEntry extends BxBaseModTextFormEntry
  16. {
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. $this->MODULE = 'bx_convos';
  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. // check for spam
  35. $bSpam = false;
  36. bx_alert('system', 'check_spam', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => $this->getCleanValue('text'), 'where' => $this->MODULE));
  37. $iFolder = $bSpam ? BX_CNV_FOLDER_SPAM : BX_CNV_FOLDER_INBOX;
  38. // place conversation to "inbox" (or "spam" - in case of spam) folder
  39. $aRecipients = array_unique(array_merge($this->getCleanValue('recipients'), array(bx_get_logged_profile_id())), SORT_NUMERIC);
  40. foreach ($aRecipients as $iProfile) {
  41. $oProfile = BxDolProfile::getInstance($iProfile);
  42. if ($oProfile)
  43. $this->_oModule->_oDb->conversationToFolder($iContentId, $iFolder, $oProfile->id());
  44. }
  45. return $iContentId;
  46. }
  47. protected function genCustomInputRecipients ($aInput) {
  48. $sVals = '';
  49. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  50. foreach ($aInput['value'] as $sVal) {
  51. $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>';
  52. }
  53. $sVals = trim($sVals, ',');
  54. }
  55. $sId = $aInput['name'] . time();
  56. $sPlaceholderText = bx_html_attribute("Type name here...", BX_ESCAPE_STR_QUOTE); // TODO: lang key
  57. $sUrlGetRecipients = BX_DOL_URL_ROOT . "modules/?r=convos/ajax_get_recipients";
  58. return <<<EOS
  59. <script>
  60. $(function() {
  61. $('#{$sId} input[type=text]').autocomplete({
  62. source: "{$sUrlGetRecipients}",
  63. select: function(e, ui) {
  64. $(this).val(ui.item.label);
  65. $(this).trigger('superselect', ui.item);
  66. e.preventDefault();
  67. }
  68. });
  69. $('#{$sId} input[type=text]').on('superselect', function(e, item) {
  70. if ('undefined' != typeof(item))
  71. $(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>');
  72. this.value = '';
  73. }).on('keydown', function(e) {
  74. // if: comma,enter (delimit more keyCodes with | pipe)
  75. if (/(13)/.test(e.which))
  76. e.preventDefault();
  77. });
  78. $('#{$sId}').on('click', 'span', function() {
  79. $(this).remove();
  80. });
  81. });
  82. </script>
  83. <style>
  84. .bx-form-input-autotoken {
  85. float:left;
  86. padding:0px;
  87. height:auto;
  88. }
  89. .bx-form-input-autotoken span {
  90. cursor:pointer;
  91. display:block;
  92. float:left;
  93. padding:0.5em;
  94. padding-right:1.5em;
  95. margin:0.1em;
  96. }
  97. .bx-form-input-autotoken span:hover{
  98. opacity:0.7;
  99. }
  100. .bx-form-input-autotoken span:after{
  101. position:absolute;
  102. content:"x";
  103. padding:0 0.5em;
  104. margin:0.2em 0 0.7em 0.5em;
  105. font-size:0.7em;
  106. font-weight:bold;
  107. }
  108. .bx-form-input-autotoken input {
  109. border:0;
  110. margin:0;
  111. padding:0 0 0 5px;
  112. width:auto;
  113. }
  114. </style>
  115. <div id="{$sId}" class="bx-form-input-autotoken bx-def-font-inputs bx-form-input-text">
  116. {$sVals}
  117. <input type="text" value="" placeholder="{$sPlaceholderText}" class="bx-def-font-inputs bx-form-input-text" />
  118. </div>
  119. EOS;
  120. }
  121. }
  122. /** @} */