Code

Added styles from currently used list.
[gosa.git] / include / class_ObjectListViewport.inc
index 84cf37c648691f8fb3530196d27cecfd218ea7f9..693e424c187ace3e761b94494359dd80c0ef5f72 100644 (file)
@@ -30,6 +30,7 @@ class ObjectListViewport {
   private $footer;
   private $entryFormat;
   private $attributes= array('cn', '_icon', '_actions', 'dn');
+
   /* <---- Dummy here */
 
   /*!
@@ -44,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.
@@ -63,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
@@ -83,10 +89,14 @@ class ObjectListViewport {
       \return HTML rendered headline
         */
   private function renderHeadline(){
-    # Dummy implementation. Use pre-defined headline.
-    $buffer= $this->headline."\n";
-
-    #TODO: Make $buffer a proper HTML table output
+    $buffer ="<table class='ObjectListViewport_Header_Table'>\n";
+    $buffer.="<tr>\n";
+    foreach($this->headline as $key => $value){
+      $buffer .= "<td class='ObjectListViewport_Header_Cell' style='".$value['style']."'>".$value['name']."</td>\n";
+    }
+    $buffer.="<td class='ObjectListViewport_Header_Cell' style='border-right:0px;width:14px;'>&nbsp;</td>";
+    $buffer.="</tr>\n";
+    $buffer.="</table>\n";
     return $buffer;
   }
 
@@ -98,18 +108,22 @@ class ObjectListViewport {
       \return HTML rendered footer
         */
   private function renderFooter(){
-    # Dummy implementation. Use pre-defined footer.
-    $buffer= "|".$this->footer."|";
+    $buffer ="<table class='ObjectListViewport_Footer_Table'>\n"; 
+    $buffer.="<tr>\n";
+    $buffer.= "<td class='ObjectListViewport_Footer_Cell' colspan='".count($this->headline)."'>".$this->footer."</td>\n";
+    $buffer.="</tr>\n";
+    $buffer.="</table>\n";
+    return $buffer;
+  }
 
-    #TODO: Make $buffer a proper HTML table output
-    return $buffer."|\n";
+
+  private function getEntryIcon($entry,$alt = ""){
+    return("<img src='images/".$entry['_icon']."' alt='".$alt."' class='center'>");
   }
 
 
        /*! \brief Renders entries from the ObjectList iterator into a string
-
            Gets the entry descriptions from the ObjectList object and renders them.
-
       \return HTML rendered list entries
         */
   private function renderEntry($entry){
@@ -117,20 +131,17 @@ class ObjectListViewport {
     /* Copy template */
     $buffer= $this->entryFormat;
 
-    $tmp = split("\|",trim($this->entryFormat,"|"));  
-
-    $buffer ="<tr>\n";
-    foreach($tmp as $key => $value){
-      $buffer .= "<td style='".$this->headline[$key]['style']."'>".$value."</td>\n";
-    }
-    $buffer.="</tr>\n";
-
     /* Replace set of attributes */
     foreach ($this->attributes as $attribute){
       if (!isset($entry[$attribute])){
         throw new ObjectListViewportException(sprintf(_("Can't locate attribute '%s' to replace in entry!"), $attribute));
       } else {
-        $buffer= preg_replace('/\{'.$attribute.'\}/', $entry[$attribute],$buffer);
+
+        if(preg_match("/_icon/i",$attribute)){
+          $buffer= preg_replace('/\{'.$attribute.'\}/', $this->getEntryIcon($entry),$buffer); 
+        }else{
+          $buffer= preg_replace('/\{'.$attribute.'\}/', $entry[$attribute],$buffer);
+        }
       }
     }
 
@@ -144,6 +155,19 @@ class ObjectListViewport {
 
     #TODO: Make $buffer a proper HTML table output
 
+    $tmp = split("\|",trim($buffer,"|"));  
+
+
+    $buffer="<tr>\n";
+    foreach($tmp as $key => $value){
+        $buffer .= "<td class='ObjectListViewport_Entry_Cell' style='".$this->headline[$key]['style']."'>".
+          "<div style='width:100%;overflow:hidden;".$this->headline[$key]['style']."'>".
+            $value.
+          "</div>".
+          "</td>\n";
+    }
+    $buffer.="</tr>\n";
+
     return $buffer."\n";
   }
 
@@ -168,19 +192,49 @@ class ObjectListViewport {
         */
   public function render() {
 
-    /* Generate fixed headline */
-    $buffer= $this->renderHeadline();
+    $header = $this->renderHeadline();
+    $footer = $this->renderFooter();
 
     /* Apply current filter */
+    $entries = "";
     $objects= new ObjectListFilterIterator($this->objects->getIterator());
     foreach ($objects as $value){
-      $buffer.= $this->renderEntry($value);
+      $entries .= $this->renderEntry($value);
     }
 
-    /* Generate footer */
-    $buffer.= $this->renderFooter();
-
-    return ("<table border=1 style='width:100%'>".$buffer."</table>");
+    /* Generate fixed headline */
+    $buffer = "
+    <table class='ObjectListViewport' id='ObjectListViewport".$this->id."' cellspacing=0 cellpadding=0>
+      <tr>
+        <td>
+              <table class='ObjectListViewport_Table' id='ObjectListViewport_Table".$this->id."' cellpadding=0 cellspacing=0 >
+                <tr>
+                  <td class='ObjectListViewport_TD_Header' id='ObjectListViewport_TD_Header".$this->id."'>
+                    ".$header."
+                  </td>
+                </tr>
+                <tr>
+                  <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".$this->id."'>
+                    ".$footer."
+                  </td>
+                </tr>
+              </table>
+
+        </td>
+      </tr>
+    </table>
+";
+
+    return ($buffer);
   }
 
 
@@ -193,14 +247,14 @@ class ObjectListViewport {
     /* Each cell definition is seperated by | 
      *  split by and go through each definition
      */
-    $tmp = split("\|",trim($data,"|"));  
+    $tmp = split("\|",trim($data,"|")); 
     $cell_formats = array();
     foreach($tmp as $key => $data){
 
       $s_width    = "";
       $s_alignment= "";
       $s_name     = preg_replace("/\{[^\}]*+\}/","",$data);
-      $s_style    = "height:40px;";
+      $s_style    = "";
     
       /* Parse format string and detect width & alignment */
       if(preg_match("/\{.*\}/",$data)){
@@ -233,14 +287,16 @@ class ObjectListViewport {
         /* Get width */
         $s_width = preg_replace("/^([^:]*).*$/","\\1",$s_format);
         if(!empty($s_width)){
-          $s_style = "width: ".$s_width.";";
+          $s_style.= "width: ".$s_width.";";
         }
-        
-        $cell_formats[$key] = array("name" => $s_name, "width" => $s_width, "alignment" => $s_alignment,"style" => $s_style);
       }
+      $cell_formats[$key] = array("name" => $s_name, "width" => $s_width, "alignment" => $s_alignment,"style" => $s_style);
     }
     return($cell_formats);
   }
+
+
+  
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: