Code

Allow multiple lists on one page
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 7 Nov 2007 14:51:39 +0000 (14:51 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 7 Nov 2007 14:51:39 +0000 (14:51 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-playground@7747 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_ObjectListViewport.inc
test.php

index 7ff0e655f0cddf1043281a7e5b36c679f436aae9..1968cd1899b94b83365af6190cb37df6f9d2c393 100644 (file)
@@ -45,7 +45,9 @@ class ObjectListViewport {
    */
        private $multiselect;
 
-
+  /*! \brief ID used to identify objects of same list */
+  private $id = "";
+  
   /*! \brief ObjectListViewport constructor
 
     The ObjectListViewport class renders/handles the ObjectList defined by $config.
@@ -64,6 +66,9 @@ class ObjectListViewport {
 
     /* Load and instanciate classes, extract filter, icons, view hooks, etc. */
     $this->objects= new ObjectList($config);
+
+    /* generate an unique id */
+    $this->id = preg_replace("/[^0-9]/","",microtime());
   }
 
        /*! \brief Handles _POST / _GET events
@@ -204,30 +209,28 @@ class ObjectListViewport {
       $entries .= $this->renderEntry($value);
     }
 
-    
-
     /* Generate fixed headline */
     $buffer = "
-    <table class='ObjectListViewport' id='ObjectListViewport' cellspacing=o cellpadding=0>
+    <table class='ObjectListViewport' id='ObjectListViewport".$this->id."' cellspacing=o cellpadding=0>
       <tr>
         <td>
-              <table class='ObjectListViewport_Table' id='ObjectListViewport_Table' cellpadding=0 cellspacing=0 >
+              <table class='ObjectListViewport_Table' id='ObjectListViewport_Table".$this->id."' cellpadding=0 cellspacing=0 >
                 <tr>
-                  <td class='ObjectListViewport_TD_Header' id='ObjectListViewport_TD_Header'>
+                  <td class='ObjectListViewport_TD_Header' id='ObjectListViewport_TD_Header".$this->id."'>
                     ".$header."
                   </td>
                 </tr>
                 <tr>
-                  <td class='ObjectListViewport_TD_Entries' id='ObjectListViewport_TD_Entries'>
-                    <div style='overflow:auto' id='ObjectListViewport_Entry_Cover'> 
-                      <table class='ObjectListViewport_Entry_Table' id='ObjectListViewport_Entry_Table'>
+                  <td class='ObjectListViewport_TD_Entries' id='ObjectListViewport_TD_Entries".$this->id."'>
+                    <div class='ObjectListViewport_Entry_Cover' id='ObjectListViewport_Entry_Cover".$this->id."'> 
+                      <table class='ObjectListViewport_Entry_Table' id='ObjectListViewport_Entry_Table".$this->id."'>
                         ".$entries."
                       </table> 
                     </div>
                   </td>
                 </tr>
                 <tr>
-                  <td class='ObjectListViewport_TD_Footer' id='ObjectListViewport_TD_Footer'>
+                  <td class='ObjectListViewport_TD_Footer' id='ObjectListViewport_TD_Footer".$this->id."'>
                     ".$footer."
                   </td>
                 </tr>
index 286956722df29ba9a99965ccdbd5f616e42bf4a4..86e63fd2742b645c1e0fb6e4de988c1ec50b586d 100644 (file)
--- a/test.php
+++ b/test.php
@@ -64,6 +64,9 @@
        margin:0px;
        padding:0px;
 }
+.ObjectListViewport_Entry_Cover{
+       overflow:auto;
+}
 .ObjectListViewport_Entry_Cell {
        border-left: solid 1px;
        font-size:10px;
@@ -82,36 +85,56 @@ window.onresize = updateObjectListViewportSize;
        function updateObjectListViewportSize() {
 
                var dbg = document.getElementById('debug');
-
+               
                /* Somehow IE do not need to be resized 
          *  So skip the following part if the client uses ie
          */
                if(document.all){
-                       document.getElementById('ObjectListViewport_Entry_Cover').style.height= "100%";
+                       var all = getElementsByStyleClass('ObjectListViewport_Entry_Cover');
+                       for (var i = 0; i < all.length; ++i){
+                               document.getElementById(all[i].id).style.height= "100%";
+                       }
                        return;
                }
        
-               /* Set Viewport to min height, to ensure 
-         *  that resize will work correctly in konqueror 
-         */
-               document.getElementById('ObjectListViewport_Entry_Cover').style.height= "50px";
-
-               /* Get values of displayed header and footer heights to be 
-                *  able to recalculate the Viewport 
-         */
-               var viewport    = getObjectHeight('ObjectListViewport_Table');
-               var header      = getObjectHeight('ObjectListViewport_TD_Header');
-               var footer      = getObjectHeight('ObjectListViewport_TD_Footer');
-
-               /* Calculate the new visible entry part height. */
-               var calc = (viewport  - ( header + footer ));
-               document.getElementById('ObjectListViewport_Entry_Cover').style.height = calc;
+               var all = getElementsByStyleClass('ObjectListViewport');
+               for (var i = 0; i < all.length; ++i){
+
+                       var id_pref = all[i].id.replace(/[^0-9]*/,"");
+
+                       /* Set Viewport to min height, to ensure 
+                        *  that resize will work correctly in konqueror 
+                        */
+                       document.getElementById('ObjectListViewport_Entry_Cover' + id_pref).style.height= "50px";
+
+                       /* Get values of displayed header and footer heights to be 
+                        *  able to recalculate the Viewport 
+                        */
+                       var viewport    = getObjectHeight('ObjectListViewport_Table' + id_pref);
+                       var header      = getObjectHeight('ObjectListViewport_TD_Header' + id_pref);
+                       var footer      = getObjectHeight('ObjectListViewport_TD_Footer' + id_pref);
+
+                       /* Calculate the new visible entry part height. */
+                       var calc = (viewport  - ( header + footer ));
+                       document.getElementById('ObjectListViewport_Entry_Cover' + id_pref).style.height = calc;
+
+                       /* Reduce width of entry list, we need some space to 
+                        *  display the scrollbar without breaking the layout
+                        */
+                       var viewport = getObjectWidth('ObjectListViewport_Table' + id_pref);
+                       document.getElementById('ObjectListViewport_Entry_Table' + id_pref).style.width = (viewport - 16) + 'px';
+               }
+       }
 
-               /* Reduce width of entry list, we need some space to 
-         *  display the scrollbar without breaking the layout
-         */
-               var viewport = getObjectWidth('ObjectListViewport_Table');
-               document.getElementById('ObjectListViewport_Entry_Table').style.width = (viewport - 16) + 'px';
+       
+       /* Return all elements of a specific class */   
+       function getElementsByStyleClass (className) {
+               var all = document.all ? document.all : document.getElementsByTagName('*');
+               var elements = new Array();
+               for (var e = 0; e < all.length; e++)
+                       if (all[e].className == className)
+                               elements[elements.length] = all[e];
+               return elements;
        }
 
 
@@ -142,14 +165,13 @@ window.onresize = updateObjectListViewportSize;
                                hallo<br>
                        </td>
                        <td style='background-color:#EEEEEE;'>
-                               <?php
-                               echo passthru("./test");
-                               ?>
+                               <?php echo passthru("./test"); ?>
                        </td>
                </tr>
                <tr>
                        <td style='background-color:#999777;'>
                                hallo<br>
+                               <?php echo passthru("./test"); ?>
                                hallo<br>
                        </td>
                        <td style='background-color:#AAA006;'>
@@ -159,7 +181,7 @@ window.onresize = updateObjectListViewportSize;
                </tr>
        </table>
 <script type="text/javascript">
-       document.getElementById('ObjectListViewport_Entry_Cover').style.height= "50px";
+updateObjectListViewportSize();
 </script>
 </body>
 </html>