Kaynağa Gözat

Ticket #4558 - Build-in API support: Grids.

AntonLV 2 yıl önce
ebeveyn
işleme
d66e7da904

+ 10 - 12
modules/base/general/classes/BxBaseModGeneralGridAdministration.php

@@ -158,22 +158,20 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
     protected function _getFilterControlsAPI($aFilters = [])
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
-        
-        if(empty($aFilters) || !is_array($aFilters))
-            return [];
 
-        foreach($aFilters as $sName => &$aValues) {
-            $aValues[] = ['value' => '', 'title' => _t($CNF['T']['filter_item_select_one_' . $sName])];
+        if(!empty($aFilters) && is_array($aFilters))
+            foreach($aFilters as $sName => &$aValues) {
+                $aValues[] = ['value' => '', 'title' => _t($CNF['T']['filter_item_select_one_' . $sName])];
 
-            $aFilterValues = $this->{'_a' . ucfirst($sName) . 'Values'};
-            if(empty($aFilterValues) || !is_array($aFilterValues))
-                continue;
+                $aFilterValues = $this->{'_a' . ucfirst($sName) . 'Values'};
+                if(empty($aFilterValues) || !is_array($aFilterValues))
+                    continue;
 
-            foreach($aFilterValues as $sKey => $sValue) 
-                $aValues[] = ['value' => $sKey, 'title' => _t($sValue)];
-        }
+                foreach($aFilterValues as $sKey => $sValue) 
+                    $aValues[] = ['value' => $sKey, 'title' => _t($sValue)];
+            }
 
-        return $aFilters;
+        return parent::_getFilterControlsAPI($aFilters);
     }
 
     protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $bAddSelectOne = true)

+ 15 - 1
template/scripts/BxBaseGrid.php

@@ -17,6 +17,7 @@ class BxBaseGrid extends BxDolGrid
     protected $_aPopupOptions = false;
     protected $_aQueryAppend = [];
     protected $_aQueryAppendExclude = false; // an array of keys which shouldn't be pathed in http requests, but can be stored (used) in 'Query Append' array.
+    protected $_aQueryAppendExcludeApi = false;
     protected $_aQueryReset = false;
     protected $_aConfirmMessages = false;
     protected $_bSelectAll = false;
@@ -37,6 +38,7 @@ class BxBaseGrid extends BxDolGrid
             $this->_oTemplate->getCodeKey() => $this->_oTemplate->getCode()
         ];
         $this->_aQueryAppendExclude = [];
+        $this->_aQueryAppendExcludeApi = [$this->_oTemplate->getCodeKey()];
 
         $this->_aQueryReset = [
             $this->_aOptions['filter_get'], 
@@ -316,6 +318,14 @@ class BxBaseGrid extends BxDolGrid
         if(!empty($aData) && is_array($aData))
             $aData = $this->decodeDataAPI($aData);
 
+        $aQueryAppend = [];
+        if(!empty($this->_aQueryAppend) && is_array($this->_aQueryAppend))
+            $aQueryAppend = array_merge($aQueryAppend, $this->_aQueryAppend);
+        if(!empty($this->_aQueryAppendExclude) && is_array($this->_aQueryAppendExclude))
+            $aQueryAppend = array_diff_key($aQueryAppend, array_flip($this->_aQueryAppendExclude));
+        if(!empty($this->_aQueryAppendExcludeApi) && is_array($this->_aQueryAppendExcludeApi))
+            $aQueryAppend = array_diff_key($aQueryAppend, array_flip($this->_aQueryAppendExcludeApi));       
+
         return [
             'settings' => [
                 'object' => $this->_aOptions['object'], 
@@ -323,6 +333,7 @@ class BxBaseGrid extends BxDolGrid
                 'start' => $iStart, 
                 'per_page' => $iPerPage,
                 'filters' => $this->_getFilterControlsAPI(),
+                'query_append' => $aQueryAppend
             ],
             'header' => $this->_getRowHeadAPI(),
             'data' => $aData,
@@ -765,7 +776,10 @@ class BxBaseGrid extends BxDolGrid
 
     protected function _getFilterControlsAPI($aFilters = [])
     {
-        return [];
+        if(!empty($this->_aOptions['filter_fields']) || !empty($this->_aOptions['filter_fields_translatable']))
+            $aFilters['search'] = [];
+
+        return $aFilters;
     }
 
     protected function _getCounter()