Просмотр исходного кода

#1497 Labels: display "following" labels by deafult, display "show more" for the rest

Alex Trofimov 8 лет назад
Родитель
Сommit
898ce27895

+ 1 - 1
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -66,7 +66,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         }
 
         if (isset($CNF['FIELD_LABELS']) && isset($this->aInputs[$CNF['FIELD_LABELS']])) {
-            $this->aInputs[$CNF['FIELD_LABELS']]['values'] = array_map('trim', explode(',', getParam($CNF['PARAM_LABELS'])));
+            $this->aInputs[$CNF['FIELD_LABELS']]['values'] = array_map('trim', getParam($CNF['PARAM_LABELS']) ? explode(',', getParam($CNF['PARAM_LABELS'])) : array());
         }
     }
 

+ 19 - 0
modules/boonex/channels/classes/BxCnlModule.php

@@ -209,6 +209,25 @@ class BxCnlModule extends BxBaseModGroupsModule
         return true;
     }
 
+    public function serviceGetFollowingChannelsNames($iProfileId)
+    {
+        if (!($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')))
+            return array();
+
+        if (!($aIds = $oConn->getConnectedContent($iProfileId)))
+            return array();
+
+        $a = array();
+        foreach ($aIds as $iId) {
+            if (!($oProfile = BxDolProfile::getInstance($iId)))
+                continue;
+            if ($oProfile->getModule() != $this->getName())
+                continue;
+            $a[] = $oProfile->getDisplayName();
+        }
+        return $a;
+    }
+
     public function followLabels($sModule, $iContentId)
     {
         if (!getParam('bx_channels_labels_autofollow'))

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

@@ -2521,6 +2521,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_select"><![CDATA[Select]]></string>
 	<string name="_sys_send"><![CDATA[Send]]></string>
     <string name="_sys_search_placeholder"><![CDATA[Search...]]></string>
+	<string name="_sys_show_more"><![CDATA[Show more]]></string>    
 	<string name="_sys_spam_detected"><![CDATA[Your activity triggered automated block]]></string>
 	<string name="_sys_spam_detected_contact"><![CDATA[Your activity triggered automated block, please contact us to investigate: {0}]]></string>
 	<string name="_sys_splash_btn_start"><![CDATA[Start]]></string>

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

@@ -2520,6 +2520,7 @@
 	<string name="_sys_select"><![CDATA[Выбрать]]></string>
 	<string name="_sys_send"><![CDATA[Послать]]></string>
     <string name="_sys_search_placeholder"><![CDATA[Поиск...]]></string>
+    <string name="_sys_show_more"><![CDATA[Показать ещё]]></string>
 	<string name="_sys_spam_detected"><![CDATA[Ваше действие привело к блокировке]]></string>
 	<string name="_sys_spam_detected_contact"><![CDATA[Ваше действие привело к блокировке, сзяжитесь с нами для проверки происходящего: {0}]]></string>
 	<string name="_sys_splash_btn_start"><![CDATA[Начало]]></string>

+ 13 - 5
template/css/forms.css

@@ -558,14 +558,22 @@
 .bx-form-value .bx-form-input-autotoken-labels b {
     padding-left: 1em;
 }
+.bx-form-value .bx-form-input-autotoken-labels-show-more,
 .bx-form-value .bx-form-input-autotoken-labels-sel b {
-    padding-right: 1em;
-    margin-top: 0.625rem;
+    display:inline-block;
+    line-height:1.5rem;
+    font-size:85%;    
+    padding-right:1em;
+    margin-top:0.625rem;
+    font-style:normal;
+}
+.bx-form-value .bx-form-input-autotoken-labels-show-more {
+    margin-left:0.1em;
+    margin-right:0.1em;
 }
 .bx-form-value .bx-form-input-autotoken-labels-sel b:after {
     display:none;
 }
-.bx-form-value .bx-form-input-autotoken-labels-sel b {
-    line-height:1.5rem;
-    font-size:85%;
+.bx-form-input-autotoken-labels-more {
+    display:none;
 }

+ 7 - 0
template/form_field_labels.html

@@ -22,4 +22,11 @@
         }
     };
     $("#__id__wrapper b").on('click', fCallack);
+
+    // show more
+    $("#__id__wrapper .bx-form-input-autotoken-labels-show-more").on('click', function () {
+        $(this).hide();
+        $("#__id__wrapper .bx-form-input-autotoken-labels-more").show();
+        return false;
+    });
 </script>

+ 30 - 4
template/scripts/BxBaseFormView.php

@@ -1120,23 +1120,49 @@ BLAH;
     
     protected function genCustomInputLabels ($aInput)
     {
+        // generate currently selected labels
         $sValue = '';
         if (!empty($aInput['value']) && is_array($aInput['value'])) {
+            sort($aInput['value'], SORT_LOCALE_STRING);
             foreach ($aInput['value'] as $sVal) {
                $sValue .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . trim($sVal) . '" /></b>';
             }
             $sValue = trim($sValue, ',');
         }
 
+        // generate "following" labels
+
+        $aFollowingLabels = bx_srv('bx_channels', 'get_following_channels_names', array(bx_get_logged_profile_id()));
+        if (!is_array($aFollowingLabels))
+            $aFollowingLabels = array();
+        $aFollowingLabels = array_intersect($aFollowingLabels, $aInput['values']);
+        $aFollowingLabels = array_diff($aFollowingLabels, !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array());
+        $aValues = array_diff($aInput['values'], 
+            !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array(), 
+            !empty($aFollowingLabels) && is_array($aFollowingLabels) ? $aFollowingLabels : array());
+
         $sValues = '';
-        if (!empty($aInput['values']) && is_array($aInput['values'])) {
-            $a = array_diff($aInput['values'], !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array());
-            foreach ($a as $sVal) {
+        if (!empty($aFollowingLabels)) {
+            sort($aFollowingLabels, SORT_LOCALE_STRING);
+            foreach ($aFollowingLabels as $sVal) {
+               $sValues .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '</b>';
+            }
+            if (!empty($aValues))
+                $sValues .= '<a href="#" class="bx-form-input-autotoken-labels-show-more">' . _t('_sys_show_more') . '</a><i class="bx-form-input-autotoken-labels-more">';
+        }
+
+        // generate all possible labels 
+        if (!empty($aValues)) {
+            sort($aValues, SORT_LOCALE_STRING);
+            foreach ($aValues as $sVal) {
                $sValues .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '</b>';
             }
             $sValues = trim($sValues, ',');
         }
-        
+
+        if (!empty($aFollowingLabels) && !empty($aValues))
+            $sValues .= '</i>';
+
         return $this->oTemplate->parseHtmlByName('form_field_labels.html', array(
             'id' => $aInput['name'] . time() . mt_rand(0, 100),
             'name' => $aInput['name'],