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

#42 - messages module: new look for convos in grid

Alex Trofimov 12 лет назад
Родитель
Сommit
1dca7563f7

+ 15 - 21
modules/boonex/convos/classes/BxCnvGrid.php

@@ -59,25 +59,14 @@ class BxCnvGrid extends BxTemplGrid
 
 
     protected function _getCellPreview ($mixedValue, $sKey, $aField, $aRow) 
     protected function _getCellPreview ($mixedValue, $sKey, $aField, $aRow) 
     {
     {
-        bx_import('BxDolModule');
-        $oModule = BxDolModule::getInstance($this->MODULE);
-        $CNF = &$oModule->_oConfig->CNF;
-
-        bx_import('BxDolPermalinks');
-        $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]);
-
-        $s = strmaxtextlen($aRow['text'], 100);
-        $s = '<a href="' . $sUrl . '">' . $s . '</a>';
-        if ($aRow['comments'] - $aRow['read_comments'] > 0)
-            $s = '<b>' . $s . '</b>';
-        return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
+        return parent::_getCellDefault ('', $sKey, $aField, $aRow);
     }
     }
 
 
     protected function _getCellLastReplyTimestamp ($mixedValue, $sKey, $aField, $aRow) 
     protected function _getCellLastReplyTimestamp ($mixedValue, $sKey, $aField, $aRow) 
     {
     {
-        $s = bx_time_js($mixedValue, BX_FORMAT_DATE);
-        if ($aRow['comments'] - $aRow['read_comments'] > 0)
-            $s = '<b>' . $s . '</b>';
+        bx_import('BxDolModule');
+        $oModule = BxDolModule::getInstance($this->MODULE);
+        $s = $oModule->_oTemplate->entryMessagePreviewInGrid ($aRow);
         return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
         return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
     }
     }
 
 
@@ -91,12 +80,10 @@ class BxCnvGrid extends BxTemplGrid
 
 
     protected function _getCellComments ($mixedValue, $sKey, $aField, $aRow) 
     protected function _getCellComments ($mixedValue, $sKey, $aField, $aRow) 
     {
     {
-        if ($aRow['comments'] - $aRow['read_comments'] > 0)
-            $mixedValue = _t('_bx_cnv_x_new_messages', 1 + $mixedValue, $aRow['comments'] - $aRow['read_comments']);
-        else
-            $mixedValue = 1 + $mixedValue;
-
-        return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
+        bx_import('BxDolModule');
+        $oModule = BxDolModule::getInstance($this->MODULE);
+        $s = $oModule->_oTemplate->getMessageLabel ($aRow);
+        return parent::_getCellDefault ('<div class="bx-cnv-grid-field-messages"><span>' . (1 + $mixedValue) . '</span>' . $s . '</div>', $sKey, $aField, $aRow);
     }
     }
 
 
     protected function _delete ($mixedId) 
     protected function _delete ($mixedId) 
@@ -109,6 +96,13 @@ class BxCnvGrid extends BxTemplGrid
     
     
         return $oModule->_oDb->moveConvo((int)$mixedId, bx_get_logged_profile_id(), BX_CNV_FOLDER_TRASH);
         return $oModule->_oDb->moveConvo((int)$mixedId, bx_get_logged_profile_id(), BX_CNV_FOLDER_TRASH);
     }
     }
+
+    protected function _addJsCss() {
+        parent::_addJsCss();
+        bx_import('BxDolModule');
+        $oModule = BxDolModule::getInstance($this->MODULE);
+        $oModule->_oTemplate->addJs('main.js');
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 74 - 24
modules/boonex/convos/classes/BxCnvTemplate.php

@@ -41,6 +41,7 @@ class BxCnvTemplate extends BxBaseModTextTemplate
 
 
         // prepare template variables
         // prepare template variables
         $aVarsPopup = array (
         $aVarsPopup = array (
+            'float' => 'none',
             'bx_repeat:collaborators' => array(),
             'bx_repeat:collaborators' => array(),
             'bx_if:collaborators_more' => array(
             'bx_if:collaborators_more' => array(
                 'condition' => false,
                 'condition' => false,
@@ -48,6 +49,7 @@ class BxCnvTemplate extends BxBaseModTextTemplate
             ),
             ),
         );
         );
         $aVars = array (
         $aVars = array (
+            'float' => $sFloat,
             'bx_repeat:collaborators' => array(),
             'bx_repeat:collaborators' => array(),
             'bx_if:collaborators_more' => array(
             'bx_if:collaborators_more' => array(
                 'condition' => $iCollaboratorsNum > $iMaxVisible,
                 'condition' => $iCollaboratorsNum > $iMaxVisible,
@@ -119,6 +121,51 @@ class BxCnvTemplate extends BxBaseModTextTemplate
         return _t('_bx_cnv_author_desc', bx_time_js($aData[$oModule->_oConfig->CNF['FIELD_ADDED']], BX_FORMAT_DATE), bx_time_js($aData['last_reply_timestamp'], BX_FORMAT_DATE));
         return _t('_bx_cnv_author_desc', bx_time_js($aData[$oModule->_oConfig->CNF['FIELD_ADDED']], BX_FORMAT_DATE), bx_time_js($aData['last_reply_timestamp'], BX_FORMAT_DATE));
     }
     }
 
 
+    function getMessageLabel ($r, $oProfileLast = null)
+    {
+        $oModule = BxDolModule::getInstance($this->MODULE);
+
+        if (!$oProfileLast) {
+            $oProfileLast = BxDolProfile::getInstance($r['last_reply_profile_id']);
+            if (!$oProfileLast)
+                $oProfileLast = BxDolProfileUndefined::getInstance();
+        }
+
+        if (!isset($r['unread_messages']))
+            $r['unread_messages'] = $r['comments'] - $r['read_comments'];
+
+        $bReadByAll = true;
+        $aCollaborators = $oModule->_oDb->getCollaborators($r['id']);
+        foreach ($aCollaborators as $iReadComments) {
+            if ($r['comments'] - $iReadComments) {
+                $bReadByAll = false;
+                break;
+            }
+        }
+
+        if (!isset($r['unread_messages']))
+            $r['unread_messages'] = $r['comments'] - $r['read_comments'];
+
+        $aVars = array (
+            'bx_if:unread_messages' => array (
+                'condition' => $r['unread_messages'] > 0,
+                'content' => array (
+                    'unread_messages' => $r['unread_messages'],
+                ),
+            ),
+            'bx_if:viewer_is_last_replier' => array (
+                'condition' => !$bReadByAll && $oProfileLast->id() == bx_get_logged_profile_id(),
+                'content' => array (),
+            ),
+            'bx_if:is_read_by_all' => array (
+                'condition' => $bReadByAll,
+                'content' => array (),
+            ),
+        );
+
+        return $this->parseHtmlByName('message_label.html', $aVars);
+    }
+
     function getMessagesPreviews ($a)
     function getMessagesPreviews ($a)
     {
     {
         bx_import('BxDolProfile');
         bx_import('BxDolProfile');
@@ -133,15 +180,6 @@ class BxCnvTemplate extends BxBaseModTextTemplate
         );
         );
         foreach ($a as $r) {
         foreach ($a as $r) {
 
 
-            $bReadByAll = true;
-            $aCollaborators = $oModule->_oDb->getCollaborators($r['id']);
-            foreach ($aCollaborators as $iReadComments) {
-                if ($r['comments'] - $iReadComments) {
-                    $bReadByAll = false;
-                    break;
-                }
-            }
-
             $oProfileAuthor = BxDolProfile::getInstance($r['author']);
             $oProfileAuthor = BxDolProfile::getInstance($r['author']);
             if (!$oProfileAuthor)
             if (!$oProfileAuthor)
                 $oProfileAuthor = BxDolProfileUndefined::getInstance();
                 $oProfileAuthor = BxDolProfileUndefined::getInstance();
@@ -161,21 +199,7 @@ class BxCnvTemplate extends BxBaseModTextTemplate
                 'unread_messages' => $r['unread_messages'],
                 'unread_messages' => $r['unread_messages'],
                 'last_reply_time_and_replier' => _t('_bx_cnv_x_date_by_x_replier', bx_time_js($r['last_reply_timestamp'], BX_FORMAT_DATE), $oProfileLast->getDisplayName()),
                 'last_reply_time_and_replier' => _t('_bx_cnv_x_date_by_x_replier', bx_time_js($r['last_reply_timestamp'], BX_FORMAT_DATE), $oProfileLast->getDisplayName()),
                 'font_weight' => $r['unread_messages'] > 0 ? 'bold' : 'normal',
                 'font_weight' => $r['unread_messages'] > 0 ? 'bold' : 'normal',
-
-                'bx_if:unread_messages' => array (
-                    'condition' => $r['unread_messages'] > 0,
-                    'content' => array (
-                        'unread_messages' => $r['unread_messages'],
-                    ),
-                ),
-                'bx_if:viewer_is_last_replier' => array (
-                    'condition' => !$bReadByAll && $oProfileLast->id() == bx_get_logged_profile_id(),
-                    'content' => array (),
-                ),
-                'bx_if:is_read_by_all' => array (
-                    'condition' => $bReadByAll,
-                    'content' => array (),
-                ),
+                'label' => $this->getMessageLabel($r, $oProfileLast),
 
 
                 'author_id' => $oProfileAuthor->id(),
                 'author_id' => $oProfileAuthor->id(),
                 'author_url' => $oProfileAuthor->getUrl(),
                 'author_url' => $oProfileAuthor->getUrl(),
@@ -192,6 +216,32 @@ class BxCnvTemplate extends BxBaseModTextTemplate
         }
         }
         return $this->parseHtmlByName('messages_previews.html', $aVars);
         return $this->parseHtmlByName('messages_previews.html', $aVars);
     } 
     } 
+
+    function entryMessagePreviewInGrid ($r)
+    {
+        $oProfileLast = BxDolProfile::getInstance($r['last_reply_profile_id']);
+        if (!$oProfileLast)
+            $oProfileLast = BxDolProfileUndefined::getInstance();
+
+        $sText = strmaxtextlen($r['text'], 100);
+        $sTextCmt = strmaxtextlen($r['cmt_text'], 100);
+
+        if (!isset($r['unread_messages']))
+            $r['unread_messages'] = $r['comments'] - $r['read_comments'];
+
+        $aVars = array (
+            'text' => $sText,
+            'cmt_text' => $sTextCmt,
+            'last_reply_time_and_replier' => _t('_bx_cnv_x_date_by_x_replier', bx_time_js($r['last_reply_timestamp'], BX_FORMAT_DATE), $oProfileLast->getDisplayName()),
+            'bx_if:unread_messages' => array (
+                'condition' => $r['unread_messages'] > 0,
+                'content' => array (),
+            ),
+        );
+        $aVars['bx_if:unread_messages2'] = $aVars['bx_if:unread_messages'];
+        return $this->parseHtmlByName('message_preview_in_grid.html', $aVars);
+    }
+    
 }
 }
 
 
 /** @} */ 
 /** @} */ 

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

@@ -79,8 +79,7 @@
     <string name="_bx_cnv_folder_spam"><![CDATA[Spam]]></string>
     <string name="_bx_cnv_folder_spam"><![CDATA[Spam]]></string>
     <string name="_bx_cnv_folder_trash"><![CDATA[Trash]]></string>
     <string name="_bx_cnv_folder_trash"><![CDATA[Trash]]></string>
 
 
-    <string name="_bx_cnv_field_comments"><![CDATA[Messages]]></string>
-    <string name="_bx_cnv_field_updated"><![CDATA[Updated]]></string>
+    <string name="_bx_cnv_field_comments"><![CDATA[#]]></string>
     <string name="_bx_cnv_field_preview"><![CDATA[Preview]]></string>
     <string name="_bx_cnv_field_preview"><![CDATA[Preview]]></string>
     <string name="_bx_cnv_field_collaborators"><![CDATA[Participants]]></string>
     <string name="_bx_cnv_field_collaborators"><![CDATA[Participants]]></string>
 
 
@@ -93,7 +92,6 @@
     <string name="_bx_cnv_more"><![CDATA[{0} more]]></string>
     <string name="_bx_cnv_more"><![CDATA[{0} more]]></string>
 
 
     <string name="_bx_cnv_author_desc"><![CDATA[{0} (updated {1})]]></string>
     <string name="_bx_cnv_author_desc"><![CDATA[{0} (updated {1})]]></string>
-    <string name="_bx_cnv_x_new_messages"><![CDATA[<b>{0} ({1} new)</b>]]></string>
     <string name="_bx_cnv_x_date_by_x_replier"><![CDATA[{0} by {1}]]></string>
     <string name="_bx_cnv_x_date_by_x_replier"><![CDATA[{0} by {1}]]></string>
 
 
     <string name="_bx_cnv_read_by_all"><![CDATA[Read by all]]></string>
     <string name="_bx_cnv_read_by_all"><![CDATA[Read by all]]></string>

+ 2 - 3
modules/boonex/convos/install/sql/enable.sql

@@ -128,9 +128,8 @@ INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `fie
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `order`) VALUES
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `order`) VALUES
 ('bx_convos', 'checkbox', '_sys_select', '2%', '', 1),
 ('bx_convos', 'checkbox', '_sys_select', '2%', '', 1),
 ('bx_convos', 'collaborators', '_bx_cnv_field_collaborators', '25%', '', 2),
 ('bx_convos', 'collaborators', '_bx_cnv_field_collaborators', '25%', '', 2),
-('bx_convos', 'preview', '_bx_cnv_field_preview', '48%', '', 3),
-('bx_convos', 'comments', '_bx_cnv_field_comments', '12%', '', 4),
-('bx_convos', 'last_reply_timestamp', '_bx_cnv_field_updated', '13%', '', 5);
+('bx_convos', 'last_reply_timestamp', '_bx_cnv_field_preview', '68%', '', 3),
+('bx_convos', 'comments', '_bx_cnv_field_comments', '5%', '', 4);
 
 
 INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `confirm`, `order`) VALUES
 INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `confirm`, `order`) VALUES
 ('bx_convos', 'bulk', 'delete', '_bx_cnv_grid_action_delete', '', 1, 1),
 ('bx_convos', 'bulk', 'delete', '_bx_cnv_grid_action_delete', '', 1, 1),

+ 31 - 0
modules/boonex/convos/js/main.js

@@ -20,3 +20,34 @@ function bx_cnv_action(sAction, e, iConvoId, isConfirm) {
             alert(s);
             alert(s);
     });
     });
 }
 }
+
+$(document).ready(function () {
+    var ePreviews = $('.bx-cnv-grid-preview');
+    if (!ePreviews.length)
+        return;
+
+    var f = function () {
+
+        // calculate width of all table rows, except the one which contains messages preview
+        var iInnerWidth = $('.bx-grid-table').parent().innerWidth();
+        var iCalcWidth = 0;
+        $('.bx-grid-table tbody tr:first-child td').each(function () {
+            if (!$(this).find('.bx-cnv-grid-preview').length)
+                iCalcWidth += $(this).outerWidth();
+        });
+
+        // set width for messages previews
+        $('.bx-cnv-grid-preview').each(function () {
+            var eWrapper = $(this).parent();
+            var w = iInnerWidth - iCalcWidth - parseInt(eWrapper.css('padding-left')) - parseInt(eWrapper.css('padding-right'));
+            $(this).width(w + 'px');
+        }); 
+    };
+
+    $(window).resize(function() {
+        f();
+    });
+    f();
+});
+
+

+ 4 - 4
modules/boonex/convos/template/collaborators.html

@@ -1,7 +1,7 @@
-<div class="bx-cnv-collaborators bx-clearfix">
+<div class="bx-cnv-collaborators bx-def-margin-sec-right bx-clearfix" style="float:__float__;">
 
 
     <bx_repeat:collaborators>
     <bx_repeat:collaborators>
-        <div class="bx-cnv-collaborator bx-def-unit bx-def-margin-sec-__float__-auto" style="float:__float__;">
+        <div class="bx-cnv-collaborator bx-def-unit bx-def-margin-sec-__float__-auto">
             <a href="__url__" title="__title_attr__"><img class="bx-def-thumb bx-def-thumb-size" src="__thumb_url__" /></a>
             <a href="__url__" title="__title_attr__"><img class="bx-def-thumb bx-def-thumb-size" src="__thumb_url__" /></a>
             <bx_if:last_replier>
             <bx_if:last_replier>
                 <div class="bx-def-unit-alert bg-col-blue2-dark" style="left:0; right:auto;"><i class="sys-icon comments"></i></div>
                 <div class="bx-def-unit-alert bg-col-blue2-dark" style="left:0; right:auto;"><i class="sys-icon comments"></i></div>
@@ -11,9 +11,9 @@
             </bx_if:author>
             </bx_if:author>
         </div>
         </div>
     </bx_repeat:collaborators>
     </bx_repeat:collaborators>
-
+   
     <bx_if:collaborators_more>
     <bx_if:collaborators_more>
-        <div class="bx-cnv-collaborator bx-def-unit bx-def-thumb-size bx-def-margin-sec-__float__-auto" style="float:__float__;">
+        <div class="bx-cnv-collaborator bx-def-unit bx-def-thumb-size bx-def-margin-sec-__float__-auto">
             <a href="javascript:void(0);" onclick="$('#__id__').dolPopup({pointer:{el:$(this)}})">__title_more__</a>            
             <a href="javascript:void(0);" onclick="$('#__id__').dolPopup({pointer:{el:$(this)}})">__title_more__</a>            
         </div>
         </div>
         <div id="__id__" style="display:none;">__popup__</div>
         <div id="__id__" style="display:none;">__popup__</div>

+ 31 - 1
modules/boonex/convos/template/css/main.css

@@ -1,8 +1,17 @@
 
 
 @import url(../../../../base/text/template/css/main.css);
 @import url(../../../../base/text/template/css/main.css);
 
 
+.bx-cnv-collaborators {
+    white-space:nowrap;
+}
+
+.bx-popup-content .bx-cnv-collaborators {
+    margin-right:0px;
+}
+
 .bx-cnv-collaborator {
 .bx-cnv-collaborator {
-    float:right;
+    display:inline;
+    display:inline-block;
     white-space:nowrap;
     white-space:nowrap;
 }
 }
 
 
@@ -22,6 +31,27 @@
     top:0;
     top:0;
 }
 }
 
 
+.bx-cnv-grid-field-messages .bx-def-unit-alert-middle {
+    position:static;
+    display:inline-block;
+    vertical-align:middle;
+}
+
+.bx-cnv-grid-field-messages > span {
+    vertical-align:middle;
+}
+
+.bx-cnv-grid-field-messages {
+    white-space:nowrap;
+}
+
 .bx-cnv-preview .bx-def-unit-info {
 .bx-cnv-preview .bx-def-unit-info {
     line-height:1.15em;
     line-height:1.15em;
 }
 }
+
+.bx-cnv-grid-preview div {
+    white-space:nowrap;
+    text-overflow:ellipsis;
+    overflow:hidden;
+    line-height:1.4em;
+}

+ 4 - 0
modules/boonex/convos/template/message_label.html

@@ -0,0 +1,4 @@
+
+<bx_if:unread_messages><div class="bx-def-unit-alert-middle bg-col-blue2-dark">__unread_messages__</div></bx_if:unread_messages>
+<bx_if:viewer_is_last_replier><div class="bx-def-unit-alert-middle"><i title="<bx_text_attribute:_bx_cnv_you_are_last_replier />" class="sys-icon reply bx-def-font-grayed"></i></div></bx_if:viewer_is_last_replier>
+<bx_if:is_read_by_all><div class="bx-def-unit-alert-middle"><i title="<bx_text_attribute:_bx_cnv_read_by_all />" class="sys-icon check bx-def-font-grayed"></i></div></bx_if:is_read_by_all>

+ 9 - 0
modules/boonex/convos/template/message_preview_in_grid.html

@@ -0,0 +1,9 @@
+<div class="bx-cnv-grid-preview">
+    <div class="bx-def-font">
+        <bx_if:unread_messages><b></bx_if:unread_messages>
+        <a href="__url__">__text__</a>
+        <bx_if:unread_messages2></b></bx_if:unread_messages2>
+    </div>
+    <div class="bx-def-font-middle">__cmt_text__</div>
+    <div class="bx-def-font-small bx-def-font-grayed">__last_reply_time_and_replier__</div>
+</div>

+ 1 - 3
modules/boonex/convos/template/messages_previews.html

@@ -3,9 +3,7 @@
 
 
 <div class="bx-cnv-preview bx-def-margin-top-auto">
 <div class="bx-cnv-preview bx-def-margin-top-auto">
     <div class="bx-cnv-title bx-def-font-h3"><a href="__url__" style="font-weight:__font_weight__;">__text__</a></div>
     <div class="bx-cnv-title bx-def-font-h3"><a href="__url__" style="font-weight:__font_weight__;">__text__</a></div>
-    <bx_if:unread_messages><div class="bx-def-unit-alert-middle bg-col-blue2-dark">__unread_messages__</div></bx_if:unread_messages>
-    <bx_if:viewer_is_last_replier><div class="bx-def-unit-alert-middle"><i title="<bx_text_attribute:_bx_cnv_you_are_last_replier />" class="sys-icon reply bx-def-font-grayed"></i></div></bx_if:viewer_is_last_replier>
-    <bx_if:is_read_by_all><div class="bx-def-unit-alert-middle"><i title="<bx_text_attribute:_bx_cnv_read_by_all />" class="sys-icon check bx-def-font-grayed"></i></div></bx_if:is_read_by_all>
+    __label__
 
 
     <div class="bx-def-unit bx-def-margin-thd-top">
     <div class="bx-def-unit bx-def-margin-thd-top">
         <a href="__last_replier_url__" title="__last_replier_title_attr__"><img class="bx-def-icon bx-def-icon-size" src="__last_replier_thumb_url__" /></a><div class="bx-def-unit-info bx-def-thumb-size-max-height bx-def-padding-sec-left bx-def-font-middle">__cmt_text__<div class="bx-def-font-grayed bx-def-font-small">__last_reply_time_and_replier__</div></div>
         <a href="__last_replier_url__" title="__last_replier_title_attr__"><img class="bx-def-icon bx-def-icon-size" src="__last_replier_thumb_url__" /></a><div class="bx-def-unit-info bx-def-thumb-size-max-height bx-def-padding-sec-left bx-def-font-middle">__cmt_text__<div class="bx-def-font-grayed bx-def-font-small">__last_reply_time_and_replier__</div></div>