Explorar el Código

#2091 Conversations: add filter for unread messages.

RomanL hace 7 años
padre
commit
4970e5b2dc

+ 8 - 0
modules/boonex/convos/classes/BxCnvConfig.php

@@ -92,6 +92,14 @@ class BxCnvConfig extends BxBaseModTextConfig
 	            'txt_folder_' . BX_CNV_FOLDER_TRASH => '_bx_cnv_folder_trash',
             ),
         );
+        
+        $this->_aJsClasses = array_merge($this->_aJsClasses, array(
+           'manage_tools' => 'BxCnvManageTools'
+        ));
+
+        $this->_aJsObjects = array_merge($this->_aJsObjects, array(
+            'manage_tools' => 'oBxCnvManageTools'
+        ));
 
     }
 }

+ 64 - 1
modules/boonex/convos/classes/BxCnvGrid.php

@@ -11,9 +11,12 @@
 
 require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
 
-class BxCnvGrid extends BxTemplGrid
+class BxCnvGrid extends BxBaseModGeneralGridAdministration
 {
     protected $MODULE;
+    protected $_sFilter1Name;
+	protected $_sFilter1Value;
+	protected $_aFilter1Values;
 
     public function __construct ($aOptions, $oTemplate = false)
     {
@@ -26,6 +29,66 @@ class BxCnvGrid extends BxTemplGrid
                 'folder_id' => $iFolderId,
                 'profile_id' => bx_get_logged_profile_id(),
             ));
+        
+        $this->_sFilter1Name = 'filter1';
+        $this->_aFilter1Values = array(
+        	'' => _t('_bx_cnv_grid_filter_item_title_adm_all'),
+            'unread' => _t('_bx_cnv_grid_filter_item_title_adm_unread'),
+		);
+        
+    	$sFilter1 = bx_get($this->_sFilter1Name);
+        if(!empty($sFilter1)) {
+            $this->_sFilter1Value = bx_process_input($sFilter1);
+            $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
+        }
+        $this->_sManageType = BX_DOL_MANAGE_TOOLS_COMMON;
+    }
+    
+    protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+    {
+        if(strpos($sFilter, $this->_sParamsDivider) !== false)
+            list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
+
+    	if(!empty($this->_sFilter1Value)){
+            $CNF = &$this->_oModule->_oConfig->CNF;
+        	$this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" WHERE `c`.`comments` > `f`.`read_comments` ");
+        }
+    
+        return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
+    }
+    
+    //--- Layout methods ---//
+	protected function _getFilterControls()
+    {
+        parent::_getFilterControls();
+
+        return  $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
+    }
+    
+    protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
+    {
+        if(empty($sFilterName) || empty($aFilterValues))
+            return '';
+
+		$CNF = &$this->_oModule->_oConfig->CNF;
+		$sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
+
+		foreach($aFilterValues as $sKey => $sValue)
+			$aFilterValues[$sKey] = _t($sValue);
+
+        $aInputModules = array(
+            'type' => 'select',
+            'name' => $sFilterName,
+            'attrs' => array(
+                'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
+                'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
+            ),
+            'value' => $sFilterValue,
+            'values' => $aFilterValues
+        );
+
+        $oForm = new BxTemplFormView(array());
+        return $oForm->genRow($aInputModules);
     }
 
     public function performActionCompose()

+ 5 - 1
modules/boonex/convos/classes/BxCnvModule.php

@@ -208,7 +208,11 @@ class BxCnvModule extends BxBaseModTextModule
             'profile_id' => bx_get_logged_profile_id(),
         ));
 
-        return $oGrid->getCode();
+        $this->_oTemplate->addCss(array('manage_tools.css'));
+        $this->_oTemplate->addJs(array('manage_tools.js'));
+        $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
+        
+        return $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->CNF['OBJECT_GRID'])) . $oGrid->getCode();
     }
 
     public function serviceMessagesPreviews ($iProfileId = 0, $bEmptyMessage = true)

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

@@ -100,7 +100,9 @@
     <string name="_bx_cnv_field_collaborators"><![CDATA[Participants]]></string>
 
     <string name="_bx_cnv_grid_action_delete"><![CDATA[Delete]]></string>
-    <string name="_bx_cnv_grid_action_compose"><![CDATA[New conversation]]></string>
+    <string name="_bx_cnv_grid_action_compose"><![CDATA[Compose]]></string>
+	<string name="_bx_cnv_grid_filter_item_title_adm_all"><![CDATA[All]]></string>
+	<string name="_bx_cnv_grid_filter_item_title_adm_unread"><![CDATA[Unread]]></string>
 
     <string name="_bx_cnv_collaborator_author"><![CDATA[author]]></string>
     <string name="_bx_cnv_collaborator_last_replier"><![CDATA[last replier]]></string>

+ 57 - 0
modules/boonex/convos/js/manage_tools.js

@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Convos Convos
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+function BxCnvManageTools(oOptions) {
+	this._iSearchTimeoutId = false;
+	this._sActionsUrl = oOptions.sActionUrl;
+	this._sObjNameGrid = oOptions.sObjNameGrid;
+	this._sObjName = oOptions.sObjName == undefined ? 'oBxCnvManageTools' : oOptions.sObjName;
+
+    this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
+    this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
+    this._sParamsDivider = oOptions.sParamsDivider == undefined ? '#-#' : oOptions.sParamsDivider;
+
+    this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
+    this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;
+}
+
+BxCnvManageTools.prototype.onChangeFilter = function (oFilter) {
+    var $this = this;
+    console.log($this._sObjNameGrid+"vcb");
+	var oFilter1 = $('#bx-grid-filter1-' + this._sObjNameGrid);
+	var sValueFilter1 = oFilter1.length > 0 ? oFilter1.val() : '';
+
+	var oSearch = $('#bx-grid-search-' + this._sObjNameGrid);
+	var sValueSearch = oSearch.length > 0 ? oSearch.val() : '';
+	if(sValueSearch == _t('_sys_grid_search'))
+		sValueSearch = '';
+
+	clearTimeout($this._iSearchTimeoutId);
+    $this._iSearchTimeoutId = setTimeout(function () {
+        glGrids[$this._sObjNameGrid].setFilter(sValueFilter1 + $this._sParamsDivider + sValueSearch, true);
+    }, 500);
+};
+
+BxCnvManageTools.prototype.onClickSettings = function (sMenuObject, oButton) {
+	if($(oButton).hasClass('bx-btn-disabled'))
+		return false;
+
+	bx_menu_popup(sMenuObject, oButton, {}, {
+		content_id: $(oButton).attr('bx_grid_action_data')
+	});
+};
+
+BxCnvManageTools.prototype.onClickDelete = function (iContentId) {
+	$('.bx-popup-applied:visible').dolPopupHide();
+
+	glGrids[this._sObjNameGrid].actionWithId(iContentId, 'delete', {}, '', false, 1);
+};
+
+/** @} */

+ 1 - 0
modules/boonex/convos/template/css/manage_tools.css

@@ -0,0 +1 @@
+@import url(../../../../base/general/template/css/manage_tools.css);