Przeglądaj źródła

Ticket #4167 - Counter for comments in timeline.

AntonLV 3 lat temu
rodzic
commit
5f08550269

+ 12 - 5
inc/classes/BxDolCmts.php

@@ -1300,7 +1300,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
 
     public function actionGetCmt ()
     {
-        if (!$this->isEnabled())
+        if(!$this->isEnabled())
             return '';
 
         if($this->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
@@ -1311,11 +1311,11 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         $sCmtDisplay = isset($_REQUEST['CmtDisplay']) ? bx_process_input($_REQUEST['CmtDisplay'], BX_DATA_TEXT) : '';
 
         $aCmt = $this->getCommentRow($iCmtId);
-        echoJson(array(
+        echoJson([
             'parent_id' => $aCmt['cmt_parent_id'],
             'vparent_id' => $aCmt['cmt_parent_id'],
-            'content' => $this->getComment($aCmt, array('type' => $sCmtBrowse), array('type' => $sCmtDisplay, 'dynamic_mode' => true))
-        ));
+            'content' => $this->getComment($aCmt, ['type' => $sCmtBrowse], ['type' => $sCmtDisplay, 'dynamic_mode' => true])
+        ]);
     }
 
     public function actionGetCmts ()
@@ -1559,7 +1559,14 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
             }
         }
 
-        return array('id' => $iCmtId, 'parent_id' => $iCmtPrntId);
+        $iCount = (int)$this->getCommentsCountAll(0, true);
+
+        return [
+            'id' => $iCmtId, 
+            'parent_id' => $iCmtPrntId,
+            'count' => $iCount,
+            'countf' => $iCount > 0 ? $this->getCounter() : ''
+        ];
     }
 
     public function onEditAfter($iCmtId, $aDp = [])

+ 76 - 39
inc/js/classes/BxDolCmts.js

@@ -24,6 +24,7 @@ function BxDolCmts (options) {
     this._sBrowseFilter = undefined == options.sBrowseFilter ? 'all' : options.sBrowseFilter;
 
     this._sSP = options.sStylePrefix === undefined ? 'cmt' : options.sStylePrefix;
+    this._aHtmlIds = options.aHtmlIds;
     this._sAnimationEffect = 'fade';
     this._iAnimationSpeed = 'slow';
 
@@ -94,48 +95,67 @@ BxDolCmts.prototype.cmtBeforePostSubmit = function(oCmtForm)
 
 BxDolCmts.prototype.cmtAfterPostSubmit = function (oCmtForm, oData)
 {
-	var $this = this;
-	var fContinue = function() {
-            var oParent = oCmtForm.parents('.cmt-reply:first');
+    var $this = this;
+    var fContinue = function() {
+        var oParent = oCmtForm.parents('.cmt-reply:first');
 
-            if(oData && oData.id != undefined) {
-                var iCmtId = parseInt(oData.id);
-                if(iCmtId > 0) {
-                    $this._getCmt(oCmtForm, iCmtId);
+        if(oData && oData.id != undefined) {
+            var iCmtId = parseInt(oData.id);
+            if(iCmtId > 0) {
+                $this._getCmt(oCmtForm, iCmtId);
 
-                    var iCmtParentId = parseInt(oData.parent_id);
-                    if(iCmtParentId == 0)
-                        $this._getForm(undefined, {CmtParent: iCmtParentId}, function(sFormWrp) {
-                            if(sFormWrp && sFormWrp.length > 0)
-                                sFormWrp = $(sFormWrp).html();
+                //--- Update form
+                var iCmtParentId = parseInt(oData.parent_id);
+                if(iCmtParentId == 0)
+                    $this._getForm(undefined, {CmtParent: iCmtParentId}, function(sFormWrp) {
+                        if(sFormWrp && sFormWrp.length > 0)
+                            sFormWrp = $(sFormWrp).html();
 
-                            oParent.hide().html(sFormWrp).bxProcessHtml().show();
+                        oParent.hide().html(sFormWrp).bxProcessHtml().show();
 
-                            $this.cmtInitFormPost(oParent.find('form'));
-                        });
-                    else
-                        oParent.remove();
-                        
-                }
+                        $this.cmtInitFormPost(oParent.find('form'));
+                    });
+                else
+                    oParent.remove();
 
-                return;
-            }
+                //--- Update counter
+                if(oData && oData.count != undefined && parseInt(oData.count) > 0) {
+                    if(oData.countf != undefined && oData.countf.length != 0) {
+                        var oCounter = $this._getCounter(oCmtForm);
+                        if(oCounter && oCounter.length > 0)
+                            oCounter.html(oData.countf);
+                    }
 
-            if(oData && oData.form != undefined && oData.form_id != undefined) {
-                oParent.find('form').replaceWith(oData.form);
+                    var oCounter = $this._getCounter(oCmtForm, true);
+                    if(oCounter && oCounter.length > 0)
+                        oCounter.html(oData.count);
 
-                $this.cmtInitFormPost(oParent.find('form'));
+                    var sClassHidden = 'sys-ac-hidden';
+                    if(!oCounter.is('.' + sClassHidden))
+                        oCounter = oCounter.parents('.' + sClassHidden + ':first');
 
-                return;
+                    oCounter.toggleClass(sClassHidden);
+                }
             }
-	};
 
-	this._loadingInButton($(oCmtForm).children().find(':submit'), false);
+            return;
+        }
+
+        if(oData && oData.form != undefined && oData.form_id != undefined) {
+            oParent.find('form').replaceWith(oData.form);
 
-	if(oData && oData.msg != undefined)
-            bx_alert(oData.msg, fContinue);
-        else 
-            fContinue();
+            $this.cmtInitFormPost(oParent.find('form'));
+
+            return;
+        }
+    };
+
+    this._loadingInButton($(oCmtForm).children().find(':submit'), false);
+
+    if(oData && oData.msg != undefined)
+        bx_alert(oData.msg, fContinue);
+    else 
+        fContinue();
 };
 
 BxDolCmts.prototype.cmtInitFormEdit = function(sCmtFormId)
@@ -947,15 +967,32 @@ BxDolCmts.prototype._cmtsReplaceContent = function(oParent, sContent, onLoad)
 
 BxDolCmts.prototype._cmtsBlink = function(oParent)
 {
-	var sBlinkClass = 'cmt-blink';
+    var sBlinkClass = 'cmt-blink';
 
-	oParent.find('.' + sBlinkClass + '-plate:visible').animate({
-		opacity: 0
-	}, 
-	5000, 
-	function() {
-		oParent.find('.' + sBlinkClass).removeClass(sBlinkClass);
-	});
+    oParent.find('.' + sBlinkClass + '-plate:visible').animate({
+        opacity: 0
+    }, 5000, function() {
+        oParent.find('.' + sBlinkClass).removeClass(sBlinkClass);
+    });
+};
+
+BxDolCmts.prototype._getCounter = function(oElement, bText)
+{
+    var oCounter = null;
+    var sSelector = '.' + this._sSP + '-counter' + (bText ? '-text' : '');
+
+    if($(oElement).hasClass(this._sSP))
+        oCounter = $(oElement).find(sSelector);
+    else 
+        oCounter = $(oElement).parents('.' + this._sSP + ':first').find(sSelector);
+
+    if(!oCounter.length && this._aHtmlIds['counter'] != undefined) {
+        oCounter = $('#' + this._aHtmlIds['counter']);
+        if(!oCounter.is(sSelector))
+            oCounter = oCounter.find(sSelector);
+    }
+
+    return oCounter;
 };
 
 BxDolCmts.prototype._getDefaultActions = function() {

+ 4 - 1
modules/boonex/artificer/data/template/bx_timeline/css/view.css

@@ -92,9 +92,12 @@ div.bx-tl-item div.bx-tl-item-activity .bx-menu-custom.bx-menu-custom-hor {
     flex-wrap: wrap;
 }
 div.bx-tl-item div.bx-tl-item-activity.bx-tl-ia-counters .bx-menu-custom.bx-menu-custom-hor li > a,
-div.bx-tl-item div.bx-tl-item-activity.bx-tl-ia-counters .bx-menu-custom.bx-menu-custom-hor li > div,
 div.bx-tl-item div.bx-tl-item-activity.bx-tl-ia-counters .bx-menu-custom.bx-menu-custom-hor li > span {
     display: block;
+}
+div.bx-tl-item div.bx-tl-item-activity.bx-tl-ia-counters .bx-menu-custom.bx-menu-custom-hor li > a,
+div.bx-tl-item div.bx-tl-item-activity.bx-tl-ia-counters .bx-menu-custom.bx-menu-custom-hor li > div,
+div.bx-tl-item div.bx-tl-item-activity.bx-tl-ia-counters .bx-menu-custom.bx-menu-custom-hor li > span {
     margin-top: 1.0rem;
 }
 

+ 5 - 0
modules/boonex/artificer/data/template/system/css/general.css

@@ -135,4 +135,9 @@ import url(../../../../../../../template/css/general.css);
         opacity: 1;
         transform: scale(1.0);
     }
+}
+
+/* --------------- System objects like Views, Votes, Comments, etc, */
+.sys-action-counter.sys-ac-hidden {
+    display: none;
 }

+ 1 - 0
modules/boonex/timeline/classes/BxTimelineMenuItemCounters.php

@@ -41,6 +41,7 @@ class BxTimelineMenuItemCounters extends BxTimelineMenuItemActions
             'overwrite_counter_link_onclick' => bx_replace_markers('{comment_onclick}', $this->_aMarkers),
             'show_do_comment_label' => $this->_bShowTitles,
             'show_counter' => $this->_bShowCounters,
+            'show_counter_empty' => $this->_bShowCountersEmpty,
             'show_counter_label_icon' => true,
             'dynamic_mode' => $this->_bDynamicMode,
         );

Plik diff jest za duży
+ 0 - 0
plugins_public/tailwind/css/tailwind.min.css


+ 1 - 1
template/comment_counter.html

@@ -2,7 +2,7 @@
     <a class="sys-ac-link group p-1 pl-2" href="__href__"<bx_if:show_onclick> onclick="__onclick__"</bx_if:show_onclick>>
         <bx_repeat:profiles>__icon__</bx_repeat:profiles>
         <bx_if:show_icon>
-            <div class="sys-action-counter-icon __style_prefix__-counter-icon bx-def-icon-size flex items-center justify-center z-10 h-6 w-6 ring-1 ring-white dark:ring-gray-700 h-6 w-6 bg-gray-200 dark:bg-gray-700 rounded-full">__icon__</div>
+            <div class="sys-action-counter-icon __style_prefix__-counter-icon flex items-center justify-center z-10 h-6 w-6 ring-1 ring-white dark:ring-gray-700 h-6 w-6 bg-gray-200 dark:bg-gray-700 rounded-full">__icon__</div>
         </bx_if:show_icon>
         <div class="sys-action-counter-text __style_prefix__-counter-text ml-1.5 first:ml-0">__content__</div>
     </a>

+ 1 - 1
template/comment_reply_box.html

@@ -4,7 +4,7 @@
             <bx_if:show_form_min>
                 <div class="__style_prefix__-body-min__class_body_min__ flex items-center">
                     <div class="__style_prefix__-bm-user">__author_unit__</div>
-                    <div class="__style_prefix__-bm-content w-full sm:pl-2 lg:pl-4 text-sm text-gray-500 dark:text-gray-400 box-border">__placeholder__</div>
+                    <div class="__style_prefix__-bm-content w-full pl-2 lg:pl-4 text-sm text-gray-500 dark:text-gray-400 box-border">__placeholder__</div>
                 </div>
             </bx_if:show_form_min>
             <div class="__style_prefix__-body__class_body__">__form__</div>

+ 9 - 0
template/css/general.css

@@ -215,6 +215,15 @@
 	display: inline-block;
 }
 
+/* --------------- System objects like Views, Votes, Comments, etc, */
+.sys-action-counter.sys-ac-hidden {
+    display: none;
+}
+.sys-action-counter .bx-def-icon-size {
+    width: 1.5rem;
+    height: 1.5rem;
+}
+
 /* --------------- 'Add to Homescreen' popup */
 .ath-container {
     color: #333;

+ 6 - 1
template/css/vote.css

@@ -30,6 +30,11 @@
 .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-divided a.bx-vote-counter {
     margin-right: 0.5rem;
 }
+.bx-media-phone .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound .sys-ac-link,
+.bx-media-tablet .bx-layout-column-thin .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound .sys-ac-link,
+.bx-media-tablet .bx-layout-column-half .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound .sys-ac-link {
+    padding-left: 1.0rem;
+}
 .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound a.bx-vote-counter.total-count,
 .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound span.bx-vote-counter.total-count {
     width: auto;
@@ -47,7 +52,7 @@
 .bx-media-phone .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound span.bx-vote-counter:not(.total-count),
 .bx-media-tablet .bx-layout-column-thin .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound span.bx-vote-counter:not(.total-count),
 .bx-media-tablet .bx-layout-column-half .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound span.bx-vote-counter:not(.total-count) {
-    margin-left: -1.0rem;
+    margin-left: -0.75rem;
 }
 .bx-vote-counter-wrapper-reactions.bx-vote-counter-wrapper-reactions-compound .bx-vote-counter-label {
     padding: 0;

+ 40 - 31
template/scripts/BxBaseCmts.php

@@ -127,6 +127,7 @@ class BxBaseCmts extends BxDolCmts
             'iDisplayStructure' => isset($aDp['structure']) && !empty($aDp['structure']) ? 1 : 0,
             'iMinPostForm' => $bMinPostForm ? 1 : 0,
             'sStylePrefix' => $this->_sStylePrefix,
+            'aHtmlIds' => $this->_aHtmlIds,
         );
 
         $this->addCssJs();
@@ -777,14 +778,14 @@ class BxBaseCmts extends BxDolCmts
         $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
         $bRecalculateCounter = isset($aParams['recalculate_counter']) && $aParams['recalculate_counter'] == true;
 
-        $iCount = (int)$this->getCommentsCountAll(0, $bRecalculateCounter);
-        if($iCount == 0 && !$bShowEmpty)
-            return '';
-
         $sClass = 'sys-action-counter';
         if(isset($aParams['show_counter_only']) && (bool)$aParams['show_counter_only'] === true)
             $sClass .= ' sys-ac-only';
 
+        $iCount = (int)$this->getCommentsCountAll(0, $bRecalculateCounter);        
+        if($iCount == 0 && !$bShowEmpty)
+            $sClass .= ' sys-ac-hidden';
+
         $sClass .= ' ' . $this->_sStylePrefix . '-counter';
         if($bShowDoCommentAsButtonSmall)
             $sClass .= ' bx-btn-small-height';
@@ -795,7 +796,7 @@ class BxBaseCmts extends BxDolCmts
         $aCmts = $this->_getCounterItems($iCmtsLimit);
         $aCmts = array_reverse($aCmts);
 
-        $aTmplVarsProfiles = array();
+        $aTmplVarsProfiles = [];
         foreach($aCmts as $aCmt) {
             $iAuthor = (int)$aCmt['cmt_author_id'];
             if(array_key_exists($iAuthor, $aTmplVarsProfiles))
@@ -805,9 +806,9 @@ class BxBaseCmts extends BxDolCmts
             if(!$oAuthor)
                 continue;
 
-            $aTmplVarsProfiles[$iAuthor] = array(
-                'icon' => $oAuthor->getUnit(0, array('template' => array('name' => 'unit_wo_info_links', 'size' => 'icon'))) 
-            );
+            $aTmplVarsProfiles[$iAuthor] = [
+                'icon' => $oAuthor->getUnit(0, ['template' => ['name' => 'unit_wo_info_links', 'size' => 'icon']]) 
+            ];
 
             if(count($aTmplVarsProfiles) >= $iCmtsLimit)
                 break;
@@ -819,53 +820,61 @@ class BxBaseCmts extends BxDolCmts
         if(!empty($aParams['overwrite_counter_link_onclick']))
             $sOnclick = $aParams['overwrite_counter_link_onclick'];
 
-        return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), array(
+        return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), [
             'style_prefix' => $this->_sStylePrefix,
             'id' => $this->_aHtmlIds['counter'],
             'class' => $sClass,
             'href' => $sHref,
-            'bx_if:show_onclick' => array(
+            'bx_if:show_onclick' => [
                 'condition' => !empty($sOnclick),
-                'content' => array(
+                'content' => [
                     'onclick' => $sOnclick
-                )
-            ),
+                ]
+            ],
             'content' => $this->_getCounterLabel($iCount, $aParams),
             'bx_repeat:profiles' => $aTmplVarsProfiles,
-            'bx_if:show_icon' => array(
+            'bx_if:show_icon' => [
                 'condition' => ($bShowEmpty || !empty($aTmplVarsProfiles)) && (!isset($aParams['show_icon']) || $aParams['show_icon']),
-                'content' => array(
+                'content' => [
                     'style_prefix' => $this->_sStylePrefix,
                     'icon' => !empty($aParams['custom_icon']) ? $aParams['custom_icon'] : $this->_oTemplate->getImageAuto('comment|' . $this->_sStylePrefix . '-counter-icon')
-                )
-            )
-        ));
+                ]
+            ]
+        ]);
     }
 
-    protected function _getLabelDo($aParams = array())
+    protected function _getLabelDo($aParams = [])
     {
-        return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), array(
+        return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), [
             'style_prefix' => $this->_sStylePrefix,
-            'bx_if:show_icon' => array(
+            'bx_if:show_icon' => [
                 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
-                'content' => array(
+                'content' => [
                     'style_prefix' => $this->_sStylePrefix,
                     'icon' => $this->_oTemplate->getImageAuto($this->_getIconDo())
-                )
-            ),
-            'bx_if:show_text' => array(
+                ]
+            ],
+            'bx_if:show_text' => [
                 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
-                'content' => array(
+                'content' => [
                     'style_prefix' => $this->_sStylePrefix,
                     'text' => _t($this->_getTitleDo())
-                )
-            )
-        ));
+                ]
+            ]
+        ]);
     }
 
-    protected function _getCounterLabel($iCount, $aParams = array())
+    protected function _getCounterLabel($iCount, $aParams = [])
     {
-        return (int)$iCount != 0 ? _t(isset($aParams['caption']) ? $aParams['caption'] : '_cmt_txt_counter', $iCount) : _t(isset($aParams['caption_empty']) ? $aParams['caption_empty'] : '_cmt_txt_counter_empty').'';
+        $aParams = array_merge($this->_aElementDefaults, $aParams);
+
+        $sResult = '';
+        if((int)$iCount != 0)
+            $sResult = _t(isset($aParams['caption']) ? $aParams['caption'] : '_cmt_txt_counter', $iCount);
+        else
+            $sResult = _t(isset($aParams['caption_empty']) ? $aParams['caption_empty'] : '_cmt_txt_counter_empty');
+        
+        return $sResult;
     }
 
     protected function _getTmplElementBlock()

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików