Explorar o código

#281 Groups: invite members functionality

Alex Trofimov %!s(int64=10) %!d(string=hai) anos
pai
achega
f907398322

+ 1 - 1
inc/classes/BxDolPrivacy.php

@@ -209,7 +209,7 @@ class BxDolPrivacy extends BxDol implements iBxDolFactoryObject
      */
     public function getContentPublicAsCondition($iProfileIdOwner = 0, $aCustomGroups = array())
     {
-        $mixedPrivacyGroups = BX_DOL_PG_ALL;
+        $mixedPrivacyGroups = array(BX_DOL_PG_ALL);
         if(isLogged()) {
             $iProfileIdLogged = bx_get_logged_profile_id();
             if($iProfileIdLogged == $iProfileIdOwner)

+ 2 - 99
modules/boonex/convos/classes/BxCnvFormEntry.php

@@ -20,10 +20,6 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
         parent::__construct($aInfo, $oTemplate);
 
         $oTemplate = BxDolTemplate::getInstance();
-        $oTemplate->addJs(array (
-            'jquery-ui/jquery-ui.custom.min.js',
-            'jquery.form.min.js',
-        ));
         $oTemplate->addJsTranslation(array(
             '_bx_cnv_draft_saving_error',
             '_bx_cnv_draft_saved_success',
@@ -88,101 +84,8 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
 
     protected function genCustomInputRecipients ($aInput)
     {
-        $sVals = '';
-        if (!empty($aInput['value']) && is_array($aInput['value'])) {
-            foreach ($aInput['value'] as $sVal) {
-                if (!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
-                    continue;
-               $sVals .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . $oProfile->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></b>';
-            }
-            $sVals = trim($sVals, ',');
-        }
-        $sId = $aInput['name'] . time();
-        $sPlaceholderText = bx_html_attribute(_t('_bx_cnv_form_entry_input_recipients_placeholder'), BX_ESCAPE_STR_QUOTE);
-        $sUrlGetRecipients = BX_DOL_URL_ROOT . "modules/?r=convos/ajax_get_recipients";
-        return <<<EOS
-<script>
-    $(function() {
-
-        $('#{$sId} input[type=text]').autocomplete({
-            source: "{$sUrlGetRecipients}",
-            select: function(e, ui) {
-                $(this).val(ui.item.label);
-                $(this).trigger('superselect', ui.item);
-                e.preventDefault();
-            }
-        });
-
-        $('#{$sId} input[type=text]').on('superselect', function(e, item) {
-            $(this).hide();
-            if ('undefined' != typeof(item))
-                $(this).before('<b class="bx-def-color-bg-hl bx-def-round-corners">'+ item.label +'<input type="hidden" name="{$aInput['name']}[]" value="'+ item.value +'" /></b>');
-            fAutoShrinkInput();
-            $(this).show();
-            this.value = '';
-
-        }).on('keydown', function(e) {
-
-            // if: comma,enter (delimit more keyCodes with | pipe)
-            if (/(13)/.test(e.which))
-                e.preventDefault();
-
-        });
-
-        $('#{$sId}').on('click', 'b', function() {
-            $(this).remove();
-            fAutoShrinkInput();
-        });
-
-        fAutoShrinkInput = function () {
-            var iWidthCont = $('#{$sId}.bx-form-input-autotoken').innerWidth();
-            var iWidthExisting = 0;
-            $('#{$sId}.bx-form-input-autotoken b').each(function () {
-                iWidthExisting += $(this).outerWidth(true);
-            });
-            $('#{$sId}.bx-form-input-autotoken input').width(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
-        };
-
-        fAutoShrinkInput();
-    });
-</script>
-<style>
-    .bx-form-value .bx-form-input-autotoken {
-        float:left;
-        padding:0px;
-        height:auto;
-    }
-    .bx-form-value .bx-form-input-autotoken b {
-        cursor:pointer;
-        display:block;
-        float:left;
-        padding:0.3em 1.5em 0.3em 0.5em;
-        margin:0.1em;
-        font-weight:normal;
-    }
-    .bx-form-value .bx-form-input-autotoken b:hover {
-        opacity:0.7;
-    }
-    .bx-form-value .bx-form-input-autotoken b:after {
-        position:absolute;
-        content:"x";
-        padding:0 0.5em;
-        margin:0.2em 0 0.7em 0.5em;
-        font-size:0.7em;
-        font-weight:bold;
-    }
-    .bx-form-value .bx-form-input-autotoken input {
-        border:0;
-        margin:0;
-        padding:0 0 0 5px;
-        width:auto;
-    }
-</style>
-<div id="{$sId}" class="bx-form-input-autotoken bx-def-font-inputs bx-form-input-text">
-    {$sVals}
-    <input type="text" value="" placeholder="{$sPlaceholderText}" class="bx-def-font-inputs bx-form-input-text" />
-</div>
-EOS;
+        $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=convos/ajax_get_recipients";
+        return $this->genCustomInputUsernamesSuggestions($aInput);
     }
 
     protected function genCustomInputSubmitText ($aInput)

+ 0 - 1
modules/boonex/convos/install/langs/en.xml

@@ -23,7 +23,6 @@
     <string name="_bx_cnv_form_entry_input_recipients"><![CDATA[Recipients]]></string>
     <string name="_bx_cnv_form_entry_input_sys_recipients"><![CDATA[Recipients]]></string>
     <string name="_bx_cnv_form_entry_input_recipients_err"><![CDATA[Recipients is mandatory]]></string>
-    <string name="_bx_cnv_form_entry_input_recipients_placeholder"><![CDATA[Type name here...]]></string>
     <string name="_bx_cnv_form_entry_input_sys_submit_text"><![CDATA[Draft status]]></string>
     <string name="_bx_cnv_form_entry_input_sys_submit_block"><![CDATA[Submit block]]></string>
 

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1693,6 +1693,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_form_login_input_password"><![CDATA[Password]]></string>
 	<string name="_sys_form_login_input_remember_me"><![CDATA[Remember me]]></string>
 	<string name="_sys_form_login_input_submit"><![CDATA[Sign in]]></string>
+	<string name="_sys_form_paceholder_profiles_suggestions"><![CDATA[Type name here...]]></string>
 	<string name="_sys_form_report"><![CDATA[Report]]></string>
 	<string name="_sys_form_report_input_caption_submit"><![CDATA[Post]]></string>
 	<string name="_sys_form_report_input_caption_text"><![CDATA[Report Text]]></string>

+ 6 - 0
modules/boonex/groups/classes/BxGroupsFormEntry.php

@@ -27,6 +27,12 @@ class BxGroupsFormEntry extends BxBaseModProfileFormEntry
 			$this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]['db']['pass'] = 'Xss';
 		}
     }
+
+    protected function genCustomInputInitialMembers ($aInput)
+    {
+        $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=groups/ajax_get_initial_members";
+        return $this->genCustomInputUsernamesSuggestions($aInput);
+    }
 }
 
 /** @} */

+ 16 - 0
modules/boonex/groups/classes/BxGroupsFormsEntryHelper.php

@@ -27,6 +27,22 @@ class BxGroupsFormsEntryHelper extends BxBaseModProfileFormsEntryHelper
 
         return $sMsg;
     }
+
+    public function onDataAddAfter ($iAccountId, $iContentId)
+    {
+        if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
+            return $s;
+
+        // insert invited members, so they will join without confirmation
+        $aInitialProfiles = bx_get('initial_members');
+        foreach ($aInitialProfiles as $iProfileId) {
+            if (!($oProfile = BxDolProfile::getInstance($iProfileId)))
+                continue;
+            $this->_oModule->serviceAddMutualConnection ($iContentId, $oProfile->id(), true);
+        }
+        
+        return '';
+    }
 }
 
 /** @} */

+ 15 - 2
modules/boonex/groups/classes/BxGroupsModule.php

@@ -19,6 +19,19 @@ class BxGroupsModule extends BxBaseModProfileModule
         parent::__construct($aModule);
     }
 
+    /**
+     * Get possible recipients for start conversation form
+     */
+    public function actionAjaxGetInitialMembers ()
+    {
+        $sTerm = bx_get('term');
+
+        $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
+
+        header('Content-Type:text/javascript; charset=utf-8');
+        echo(json_encode($a));
+    }
+
     public function serviceActAsProfile ()
     {
         return false;
@@ -33,10 +46,10 @@ class BxGroupsModule extends BxBaseModProfileModule
         return $aFieldsProfile;
     }
 
-    public function serviceAddMutualConnection ($iContentId, $iInitiatorId)
+    public function serviceAddMutualConnection ($iContentId, $iInitiatorId, $iIgnoreJoinConfirmation = false)
     {
         $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
-        if (!$aContentInfo || $aContentInfo['join_confirmation'])
+        if (!$aContentInfo || (!$iIgnoreJoinConfirmation && $aContentInfo['join_confirmation']))
             return false;
 
         if (!($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])))

+ 0 - 1
modules/boonex/russian/data/langs/bx_convos/ru.xml

@@ -23,7 +23,6 @@
     <string name="_bx_cnv_form_entry_input_recipients"><![CDATA[Получатели]]></string>
     <string name="_bx_cnv_form_entry_input_sys_recipients"><![CDATA[Получатели]]></string>
     <string name="_bx_cnv_form_entry_input_recipients_err"><![CDATA[Необходимо указать хотя бы одного получателя]]></string>
-    <string name="_bx_cnv_form_entry_input_recipients_placeholder"><![CDATA[Введите имя здесь...]]></string>
     <string name="_bx_cnv_form_entry_input_sys_submit_text"><![CDATA[Статус черновика]]></string>
     <string name="_bx_cnv_form_entry_input_sys_submit_block"><![CDATA[Блок отправки сообщения]]></string>
 

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1693,6 +1693,7 @@
 	<string name="_sys_form_login_input_password"><![CDATA[Пароль]]></string>
 	<string name="_sys_form_login_input_remember_me"><![CDATA[Запомнить меня]]></string>
 	<string name="_sys_form_login_input_submit"><![CDATA[Вход]]></string>
+	<string name="_sys_form_paceholder_profiles_suggestions"><![CDATA[Введите имя...]]></string>
 	<string name="_sys_form_report"><![CDATA[Пожаловаться]]></string>
 	<string name="_sys_form_report_input_caption_submit"><![CDATA[Пожаловаться]]></string>
 	<string name="_sys_form_report_input_caption_text"><![CDATA[Текст жалобы]]></string>

+ 34 - 1
template/css/forms.css

@@ -473,4 +473,37 @@
 
 	border-radius: 20px;
 	border-radius: 1.25rem;
-}
+}
+
+/* auto-siggestion input */
+
+.bx-form-value .bx-form-input-autotoken {
+    float:left;
+    padding:0px;
+    height:auto;
+}
+.bx-form-value .bx-form-input-autotoken b {
+    cursor:pointer;
+    display:block;
+    float:left;
+    padding:0.3em 1.5em 0.3em 0.5em;
+    margin:0.1em;
+    font-weight:normal;
+}
+.bx-form-value .bx-form-input-autotoken b:hover {
+    opacity:0.7;
+}
+.bx-form-value .bx-form-input-autotoken b:after {
+    position:absolute;
+    content:"x";
+    padding:0 0.5em;
+    margin:0.2em 0 0.7em 0.5em;
+    font-size:0.7em;
+    font-weight:bold;
+}
+.bx-form-value .bx-form-input-autotoken input {
+    border:0;
+    margin:0;
+    padding:0 0 0 5px;
+    width:auto;
+}

+ 49 - 0
template/form_field_custom_suggestions.html

@@ -0,0 +1,49 @@
+<script>
+    $(function() {
+
+        $('#__id__ input[type=text]').autocomplete({
+            source: "__url_get_recipients__",
+            select: function(e, ui) {
+                $(this).val(ui.item.label);
+                $(this).trigger('superselect', ui.item);
+                e.preventDefault();
+            }
+        });
+
+        $('#__id__ input[type=text]').on('superselect', function(e, item) {
+            $(this).hide();
+            if ('undefined' != typeof(item))
+                $(this).before('<b class="bx-def-color-bg-hl bx-def-round-corners">'+ item.label +'<input type="hidden" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" name="__name__[]" value="'+ item.value +'" /></b>');
+            fAutoShrinkInput();
+            $(this).show();
+            this.value = '';
+
+        }).on('keydown', function(e) {
+
+            // if: comma,enter (delimit more keyCodes with | pipe)
+            if (/(13)/.test(e.which))
+                e.preventDefault();
+
+        });
+
+        $('#__id__').on('click', 'b', function() {
+            $(this).remove();
+            fAutoShrinkInput();
+        });
+
+        fAutoShrinkInput = function () {
+            var iWidthCont = $('#__id__.bx-form-input-autotoken').innerWidth();
+            var iWidthExisting = 0;
+            $('#__id__.bx-form-input-autotoken b').each(function () {
+                iWidthExisting += $(this).outerWidth(true);
+            });
+            $('#__id__.bx-form-input-autotoken input').width(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
+        };
+
+        fAutoShrinkInput();
+    });
+</script>
+<div id="__id__" class="bx-form-input-autotoken bx-def-font-inputs bx-form-input-text">
+    __vals__
+    <input type="text" value="" placeholder="__placeholder__" class="bx-def-font-inputs bx-form-input-text" />
+</div>

+ 26 - 0
template/scripts/BxBaseFormView.php

@@ -872,6 +872,32 @@ BLAH;
         ));
     }
 
+    protected function genCustomInputUsernamesSuggestions ($aInput)
+    {
+        $this->oTemplate->addJs(array(
+            'jquery-ui/jquery-ui.custom.min.js',
+            'jquery.form.min.js',
+        ));
+
+        $sVals = '';
+        if (!empty($aInput['value']) && is_array($aInput['value'])) {
+            foreach ($aInput['value'] as $sVal) {
+                if (!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
+                    continue;
+               $sVals .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . $oProfile->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></b>';
+            }
+            $sVals = trim($sVals, ',');
+        }
+
+        return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
+            'id' => $aInput['name'] . time(),
+            'url_get_recipients' => $aInput['ajax_get_suggestions'],
+            'name' => $aInput['name'],
+            'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
+            'vals' => $sVals,
+        ));
+    }
+
     /**
      * Generate Select Element
      *