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

Ticket #4798 - Add filter by roles for members in context.

AntonLV 2 лет назад
Родитель
Сommit
a2ed9daace

+ 123 - 3
modules/base/groups/classes/BxBaseModGroupsGridConnections.php

@@ -23,6 +23,12 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
     protected $_bPaidJoin;
     protected $_bMember;
     protected $_bManageMembers;
+    
+    protected $_sParamsDivider;
+
+    protected $_sFilter1Name;
+    protected $_sFilter1Value;
+    protected $_aFilter1Values;
 
     public function __construct ($aOptions, $oTemplate = false)
     {
@@ -50,12 +56,32 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
         $this->_bMember = $this->_oModule->isFan($this->_aContentInfo[$CNF['FIELD_ID']]);
         $this->_bManageMembers = $this->_oModule->checkAllowedManageFans($this->_iGroupProfileId) === CHECK_ACTION_RESULT_ALLOWED || $this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId) === CHECK_ACTION_RESULT_ALLOWED;
 
+        $this->_sParamsDivider = '#-#';
+
+        if($this->_bRoles) {
+            $this->_sFilter1Name = 'frole';
+            $this->_aFilter1Values = [];
+            foreach($this->_aRoles as $iRoleId => $sRoleTitle)
+                $this->_aFilter1Values[] = [
+                    'key' => $this->_roleItoS($iRoleId), 
+                    'value' => $sRoleTitle
+                ];
+
+            if(($sFilter1 = bx_get($this->_sFilter1Name))) {
+                $this->_sFilter1Value = bx_process_input($sFilter1);
+                $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
+            }
+        }
+
         $aSQLParts = $this->_oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $this->_iGroupProfileId, $this->_bOwner ? false : true);
-        $this->addMarkers(array(
+        if($this->_bRoles)
+            $aSQLParts['join'] .= $this->_oModule->_oDb->prepareAsString(" LEFT JOIN `" . $CNF['TABLE_ADMINS'] . "` AS `ca` ON (`p`.`id` = `ca`.`fan_id` AND `ca`.`group_profile_id`= ?)", $this->_iGroupProfileId);
+
+        $this->addMarkers([
             'profile_id' => $this->_iGroupProfileId,
             'join_connections' => $aSQLParts['join'],
             'content_module' => $this->_sContentModule,
-        ));
+        ]);
     }
 
     public function getCode ($isDisplayHeader = true)
@@ -470,12 +496,106 @@ class BxBaseModGroupsGridConnections extends BxDolGridConnections
             return array($iId2, $iId1);
     }
 
+    protected function _getFilterControls()
+    {
+        parent::_getFilterControls();
+
+        $sResult = '';
+        if($this->_bRoles && !empty($this->_sFilter1Name))
+            $sResult .= $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
+        $sResult .= $this->_getSearchInput();
+
+        return $sResult;
+    }
+
+    protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $bAddSelectOne = true)
+    {
+        if(empty($sFilterName) || empty($aFilterValues))
+            return '';
+
+        $CNF = &$this->_oModule->_oConfig->CNF;
+        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
+
+        $aInputValues = [];
+        if($bAddSelectOne && ($sLangKey = 'filter_item_select_one_' . $sFilterName))
+            $aInputValues[''] = _t(!empty($CNF['T'][$sLangKey]) ? $CNF['T'][$sLangKey] : '_Select_one');
+
+        foreach($aFilterValues as $aFilterValue)
+            $aInputValues[$aFilterValue['key']] = _t($aFilterValue['value']);
+
+        $aInputModules = [
+            'type' => 'select',
+            'name' => $sFilterName,
+            'attrs' => [
+                'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
+                'onChange' => 'javascript:' . $sJsObject . '.onChangeMembersFilter(this)'
+            ],
+            'value' => $sFilterValue,
+            'values' => $aInputValues
+        ];
+
+        $oForm = new BxTemplFormView([]);
+        return $oForm->genRow($aInputModules);
+    }
+
+    protected function _getSearchInput()
+    {
+        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
+
+        $aInputSearch = [
+            'type' => 'text',
+            'name' => 'search',
+            'attrs' => [
+                'id' => 'bx-grid-search-' . $this->_sObject,
+                'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeMembersFilter(this)',
+                'onBlur' => 'javascript:' . $sJsObject . '.onChangeMembersFilter(this)',
+            ]
+        ];
+
+        $oForm = new BxTemplFormView([]);
+        return $oForm->genRow($aInputSearch);
+    }
+
     protected function _addJsCss()
     {
         parent::_addJsCss();
 
-        if($this->_bRoles)
+        if($this->_bRoles) {
+            $this->_oModule->_oTemplate->addCss(['main.css']);
             $this->_oModule->_oTemplate->addJs(['modules/base/groups/js/|main.js', 'main.js']);
+            $this->_oModule->_oTemplate->addJsTranslation(['_sys_grid_search']);
+        }
+    }
+
+    protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+    {
+        $aFilterParts = explode($this->_sParamsDivider, $sFilter);
+        switch (substr_count($sFilter, $this->_sParamsDivider)) {
+            case 1:
+                list($this->_sFilter1Value, $sFilter) = $aFilterParts;
+                break;
+        }
+
+        if(strpos($this->_aOptions['source'], 'WHERE') === false)
+            $this->_aOptions['source'] .= ' WHERE 1';
+
+        if($this->_bRoles && !empty($this->_sFilter1Value)) {
+            $this->_sFilter1Value = $this->_roleStoI($this->_sFilter1Value);
+
+            $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString($this->_sFilter1Value == 0 ? " AND (ISNULL(`ca`.`role`) OR `ca`.`role` = ?)" : " AND `ca`.`role` = ?", $this->_sFilter1Value);
+        }
+
+        return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
+    }
+
+    protected function _roleItoS($iRole)
+    {
+        return 'r' . $iRole;
+    }
+
+    protected function _roleStoI($sRole)
+    {
+        return (int)substr($sRole, 1);
     }
 }
 

+ 17 - 0
modules/base/groups/js/main.js

@@ -16,6 +16,7 @@ function BxBaseModGroupsMain(oOptions) {
     
     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;
 
@@ -92,6 +93,22 @@ BxBaseModGroupsMain.prototype.onApplyBrowsingFilter = function(oData) {
     oContainer.html(oData.content).bxProcessHtml();
 };
 
+BxBaseModGroupsMain.prototype.onChangeMembersFilter = function(oFilter) {
+    var $this = this;
+    var oFilter1 = $('#bx-grid-frole-' + 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);
+};
+
 BxBaseModGroupsMain.prototype.connAction = function(oElement, sObject, sAction, iContentId) {
     var $this = this;
     var oParams = this._getDefaultData();

+ 18 - 0
modules/base/groups/template/css/main.css

@@ -5,6 +5,24 @@
     -webkit-border-radius:0.1875rem;
 }
 
+/*--- Role filter ---*/
+div.bx-grid-header div.bx-grid-header-controls-filter {
+    position: relative;
+    display: -webkit-flex;
+    display: flex;
+    -webkit-align-items: center;
+    align-items: center;
+}
+div.bx-grid-header div.bx-form-element-wrapper {
+    margin: 0 0.5rem 0 0;
+}
+div.bx-grid-header div.bx-form-element-wrapper:last-child {
+    margin-right: 0;
+}
+div.bx-grid-header div#bx-form-element-role,
+div.bx-grid-header div#bx-form-element-search {
+    margin-top: 0px;
+}
 
 /*--- Set Role popup ---*/
 .bx-base-group-sr-role-cnt {

+ 19 - 0
modules/boonex/artificer/data/template/mod_groups/css/main.css

@@ -2,4 +2,23 @@
 .bx-base-groups-unit-with-cover .bx-base-pofile-unit-info .bx-base-general-unit-meta ul.bx-menu-custom.bx-menu-custom-hor {
     -webkit-justify-content: flex-start;
     justify-content: flex-start;
+}
+
+/*--- Role filter ---*/
+div.bx-grid-header div.bx-grid-header-controls-filter {
+    position: relative;
+    display: -webkit-flex;
+    display: flex;
+    -webkit-align-items: center;
+    align-items: center;
+}
+div.bx-grid-header div.bx-form-element-wrapper {
+    margin: 0 0.5rem 0 0;
+}
+div.bx-grid-header div.bx-form-element-wrapper:last-child {
+    margin-right: 0;
+}
+div.bx-grid-header div#bx-form-element-role,
+div.bx-grid-header div#bx-form-element-search {
+    margin-top: 0px;
 }

+ 4 - 27
modules/boonex/courses/js/main.js

@@ -9,35 +9,12 @@
  */
 
 function BxCoursesMain(oOptions) {
-    this._sActionsUrl = oOptions.sActionUrl;
-    this._sObjName = oOptions.sObjName == undefined ? 'oBxCoursesMain' : oOptions.sObjName;
-    this._sObjNameGrid = oOptions.sObjNameGrid == undefined ? '' : oOptions.sObjNameGrid;
+    BxBaseModGroupsMain.call(this, oOptions);
     
-    this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
-    this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
-
-    this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
+    this._sObjName = oOptions.sObjName == undefined ? 'oBxCoursesMain' : oOptions.sObjName;
 }
 
-BxCoursesMain.prototype.onClickSetRole = function(iFanProfileId, iRole) {
-    $('.bx-popup-applied:visible').dolPopupHide();
-
-    if(glGrids[this._sObjNameGrid] != undefined)
-        glGrids[this._sObjNameGrid].actionWithId(iFanProfileId, 'set_role_submit', {role: iRole}, '', false, false);
-};
-
-BxCoursesMain.prototype.onClickSetRoleMulti = function(oElement, iFanProfileId, iRole) {
-    if(!glGrids[this._sObjNameGrid])
-        return;
-
-    var oSiblings = $(oElement).parents('.bx-base-group-sr-role:first').siblings();
-    if(iRole == 0)
-        oSiblings.find('input:checked').removeAttr('checked');
-    else
-        oSiblings.find("input[value = '0']:checked").removeAttr('checked');
-
-    var sRoles = $(oElement).parents('.bx-base-group-sr-roles:first').find('input:checked').serialize();
-    glGrids[this._sObjNameGrid].actionWithId(iFanProfileId, 'set_role_submit', {}, sRoles, false, false);
-};
+BxCoursesMain.prototype = Object.create(BxBaseModGroupsMain.prototype);
+BxCoursesMain.prototype.constructor = BxCoursesMain;
 
 /** @} */

+ 4 - 27
modules/boonex/groups/js/main.js

@@ -9,35 +9,12 @@
  */
 
 function BxGroupsMain(oOptions) {
-    this._sActionsUrl = oOptions.sActionUrl;
-    this._sObjName = oOptions.sObjName == undefined ? 'oBxGroupsMain' : oOptions.sObjName;
-    this._sObjNameGrid = oOptions.sObjNameGrid == undefined ? '' : oOptions.sObjNameGrid;
-    
-    this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
-    this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
+    BxBaseModGroupsMain.call(this, oOptions);
 
-    this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
+    this._sObjName = oOptions.sObjName == undefined ? 'oBxGroupsMain' : oOptions.sObjName;
 }
 
-BxGroupsMain.prototype.onClickSetRole = function(iFanProfileId, iRole) {
-    $('.bx-popup-applied:visible').dolPopupHide();
-
-    if(glGrids[this._sObjNameGrid] != undefined)
-        glGrids[this._sObjNameGrid].actionWithId(iFanProfileId, 'set_role_submit', {role: iRole}, '', false, false);
-};
-
-BxGroupsMain.prototype.onClickSetRoleMulti = function(oElement, iFanProfileId, iRole) {
-    if(!glGrids[this._sObjNameGrid])
-        return;
-
-    var oSiblings = $(oElement).parents('.bx-base-group-sr-role:first').siblings();
-    if(iRole == 0)
-        oSiblings.find('input:checked').removeAttr('checked');
-    else
-        oSiblings.find("input[value = '0']:checked").removeAttr('checked');
-
-    var sRoles = $(oElement).parents('.bx-base-group-sr-roles:first').find('input:checked').serialize();
-    glGrids[this._sObjNameGrid].actionWithId(iFanProfileId, 'set_role_submit', {}, sRoles, false, false);
-};
+BxGroupsMain.prototype = Object.create(BxBaseModGroupsMain.prototype);
+BxGroupsMain.prototype.constructor = BxGroupsMain;
 
 /** @} */

+ 4 - 27
modules/boonex/spaces/js/main.js

@@ -9,35 +9,12 @@
  */
 
 function BxSpacesMain(oOptions) {
-    this._sActionsUrl = oOptions.sActionUrl;
-    this._sObjName = oOptions.sObjName == undefined ? 'oBxSpacesMain' : oOptions.sObjName;
-    this._sObjNameGrid = oOptions.sObjNameGrid == undefined ? '' : oOptions.sObjNameGrid;
-    
-    this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
-    this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
+    BxBaseModGroupsMain.call(this, oOptions);
 
-    this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
+    this._sObjName = oOptions.sObjName == undefined ? 'oBxSpacesMain' : oOptions.sObjName;
 }
 
-BxSpacesMain.prototype.onClickSetRole = function(iFanProfileId, iRole) {
-    $('.bx-popup-applied:visible').dolPopupHide();
-
-    if(glGrids[this._sObjNameGrid] != undefined)
-        glGrids[this._sObjNameGrid].actionWithId(iFanProfileId, 'set_role_submit', {role: iRole}, '', false, false);
-};
-
-BxSpacesMain.prototype.onClickSetRoleMulti = function(oElement, iFanProfileId, iRole) {
-    if(!glGrids[this._sObjNameGrid])
-        return;
-
-    var oSiblings = $(oElement).parents('.bx-base-group-sr-role:first').siblings();
-    if(iRole == 0)
-        oSiblings.find('input:checked').removeAttr('checked');
-    else
-        oSiblings.find("input[value = '0']:checked").removeAttr('checked');
-
-    var sRoles = $(oElement).parents('.bx-base-group-sr-roles:first').find('input:checked').serialize();
-    glGrids[this._sObjNameGrid].actionWithId(iFanProfileId, 'set_role_submit', {}, sRoles, false, false);
-};
+BxSpacesMain.prototype = Object.create(BxBaseModGroupsMain.prototype);
+BxSpacesMain.prototype.constructor = BxSpacesMain;
 
 /** @} */