Alexander Nicolaysen Sørnes : filter_ui: Improve display of filters with only one operator

Chris Morgan cmorgan at winehq.org
Sat Jun 14 16:16:51 CDT 2008


Module: appdb
Branch: master
Commit: 7a138bd2c2ad80cb75f7b2cb2bb0d8514e08fbb5
URL:    http://source.winehq.org/git/appdb.git/?a=commit;h=7a138bd2c2ad80cb75f7b2cb2bb0d8514e08fbb5

Author: Alexander Nicolaysen Sørnes <alex at thehandofagony.com>
Date:   Fri Jun 13 23:18:07 2008 +0200

filter_ui: Improve display of filters with only one operator

---

 include/db_filter_ui.php |   49 +++++++++++++++++++++++++++++----------------
 1 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/include/db_filter_ui.php b/include/db_filter_ui.php
index d928b84..ed2f270 100644
--- a/include/db_filter_ui.php
+++ b/include/db_filter_ui.php
@@ -165,32 +165,45 @@ class FilterInterface
         $oColumn = $this->aFilterInfo[$oFilter->getColumn()];
 
         $sId = ($iId == -1) ? '' : $iId;
-        $shEditor = $oColumn->getDisplayName();
+        $shEditor = $oColumn->getDisplayName().' ';
 
-        $shEditor .= " <select name='i{$sColumn}Op$sId'>";
+        $aTypes = $oColumn->getTypes();
 
-        if($iId == -1)
+        /* It doesn't make sense to show a dropdown menu of choices if there is only one
+           If the filter is already active then there are more than one; one to remove */
+        if($iId == -1 && sizeof($aTypes) == 1)
         {
-            $sText = 'select';
-            $sSel = " selected='selected'";
+            echo "<input type=\"hidden\" name=\"i{$sColumn}Op$sId\" value=\"{$aTypes[0]}\" />";
+
+            /* Printing 'equal to' sounds weird if it is the only choice */
+            if($aTypes[0] != FILTER_EQUALS)
+                $shEditor .= $oColumn->getOpName($aTypes[0]);
         } else
         {
-            $sSel = '';
-            $sText = 'remove';
-        }
-
-        $shEditor .= "<option value='0'$sSel>-- $sText --</option>";
+            $shEditor .= "<select name='i{$sColumn}Op$sId'>";
 
-        foreach($oColumn->getTypes() as $iType)
-        {
-            if($oFilter->getOperatorId() == $iType)
+            if($iId == -1)
+            {
+                $sText = 'select';
                 $sSel = " selected='selected'";
-            else
+            } else
+            {
                 $sSel = '';
-            $shEditor .= "<option value='$iType'$sSel>".$oColumn->getOpName($iType).'</option><br />';
-        }
+                $sText = 'remove';
+            }
+
+            $shEditor .= "<option value='0'$sSel>-- $sText --</option>";
 
-        $shEditor .= '</select> ';
+            foreach($aTypes as $iType)
+            {
+                if($oFilter->getOperatorId() == $iType)
+                    $sSel = " selected='selected'";
+                else
+                    $sSel = '';
+                $shEditor .= "<option value='$iType'$sSel>".$oColumn->getOpName($iType).'</option><br />';
+            }
+            $shEditor .= '</select> ';
+        }
 
         switch($oColumn->getValueType())
         {
@@ -344,7 +357,7 @@ class FilterInterface
             $sData = $aClean["s{$sColumn}Data"];
             $iOp = $aClean["i{$sColumn}Op"];
 
-            if($iOp)
+            if($iOp && $sData)
             {
                 $oFilter = new Filter($oOption->getColumn(), $iOp, $sData);
                 $aReturn[] = $oFilter;




More information about the wine-cvs mailing list