Code

Smarty Template for List generation
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 13 Nov 2007 08:01:50 +0000 (08:01 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 13 Nov 2007 08:01:50 +0000 (08:01 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-playground@7783 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_ObjectList.inc
include/class_ObjectListViewport.inc
tests/ListTest/ObjectListViewport.js
tests/ListTest/ObjectListViewport.tpl

index f9f7dd3bd6686e5e39795f507dc1ddf0a4523a4a..a82eef4615a53907ac22da9fa63e8a3fe6437d0c 100644 (file)
@@ -79,7 +79,7 @@ class ObjectList implements IteratorAggregate {
 '<img src="images/edittrash.png" alt="">';
 
     # Crap filling
-    $this->objects= array(
+    $tmp= array(
 
  array("dn" => "cn=1aherbertskiste,ou=workstations,ou=systems,o=Landeshauptstadt München,c=de",
               "cn" => "1aherbertskiste",
@@ -357,6 +357,15 @@ class ObjectList implements IteratorAggregate {
               "objectClass" => array('gotoWorkstation'))
 
         );
+
+    $tmp2 = array();
+    foreach($tmp as $entry){
+      $id = uniqid();
+      $entry['id']= $id;
+      $tmp2[] = $entry;
+    }
+
+    $this->objects = $tmp2;
   }
 
 
index eb454a53f16c4f88d596d8a2286b4156a8b82e66..60b11d294600f17336025087c6e9307885b34c2f 100644 (file)
@@ -181,39 +181,31 @@ class ObjectListViewport extends GOsaGuiElement {
 
     #TODO: Make $buffer a proper HTML table output
     $tmp = split("\|",trim($buffer,"|"));  
+    $cols = array();
 
-    /* Define entry template */
-    $tpl = "<td class='ObjectListViewport_Entry_Cell' style='{style_1}'>
-              <div style='{style_2}'>
-                {content}
-              </div>
-            </td>
-            ";
-    /* Template vriables to replace */
-    $attrs = array("/\{style_1\}/","/\{style_2\}/","/\{content\}/");
-
-    /* Append template for each given col */
-    $buffer ="";
     for($i= 0; $i < $this->numberOfCols; $i++){
 
       /* If current entry is the last to appen, then skip adding styles */
       if($i == ($this->numberOfCols-1)){
-        $buffer.= preg_replace( $attrs,
-            array($this->headline[$i]['style'],"width:100%;overflow:hidden;",$tmp[$i]),$tpl);
+        $cols[$i]['style1'] = $this->headline[$i]['style'];
+        $cols[$i]['style2'] = "width:100%;overflow:hidden;";
+        $cols[$i]['value']   = $tmp[$i];
       }else{
-        $buffer.= preg_replace( $attrs,
-            array($this->headline[$i]['style'],"width:100%;overflow:hidden;".$this->headline[$i]['style'],$tmp[$i]),$tpl);
+        $cols[$i]['style1'] = $this->headline[$i]['style'];
+        $cols[$i]['style2'] = "width:100%;overflow:hidden;".$this->headline[$i]['style'];
+        $cols[$i]['value']   = $tmp[$i];
       }
     }
 
     /* Add class depending on given id, to alternate background colors */
     if($this->colorAlternator++ & 1){
-      $a = "class='ObjectListViewport_Entry_Row1'";
+      $data['row']['class'] = "ObjectListViewport_Entry_Row1";
     }else{
-      $a = "class='ObjectListViewport_Entry_Row2'";
+      $data['row']['class'] = "ObjectListViewport_Entry_Row2";
     }
 
-    return "<tr ".$a.">\n".$buffer."</tr>\n";
+    $data['cols'] = $cols;
+    return($data);
   }
 
 
@@ -241,10 +233,9 @@ class ObjectListViewport extends GOsaGuiElement {
     $entries = "";
     $objects= new ObjectListFilterIterator($this->objects->getIterator());
     foreach ($objects as $value){
-      $entries .= $this->renderEntry($value);
+      $entries[] = $this->renderEntry($value);
     }
 
-    return "README ;-)\n";
 
     #Fabian: _POST/_GET Variablen bitte mit $this->createVariable('name');
     #        erstellen.
@@ -255,20 +246,20 @@ class ObjectListViewport extends GOsaGuiElement {
     #        smarty eingebunden, dann kann Sie nach einem _POST oder _GET via
     #        $this->getRequestVariable_cn() wieder abgefragt werden.
 
-    #$smarty = get_smarty();
-    #$smarty->assign("OLV_Entries",array("Doesn't work" => "Does not work."));//$objects);
-    #$smarty->assign("OLV_List_Id",$this->id);
+    $smarty = get_smarty();
+    $smarty->assign("OLV_Entries",$entries);
+    $smarty->assign("OLV_List_Id",$this->id);
 
-    #/* Footer variables */
-    #$smarty->assign("OLV_Footer_Enabled",$this->displayFooterFlag);
-    #$smarty->assign("OLV_Footer_Message",$this->footer);
-    #$smarty->assign("OLV_Num_Cols",$this->numberOfCols);
+    /* Footer variables */
+    $smarty->assign("OLV_Footer_Enabled",$this->displayFooterFlag);
+    $smarty->assign("OLV_Footer_Message",$this->footer);
+    $smarty->assign("OLV_Num_Cols",$this->numberOfCols);
 
-    #/* Assign Headline values */
-    #$smarty->assign("OLV_Header_Enabled",$this->displayHeaderFlag);
-    #$smarty->assign("OLV_Header",$this->headline);
+    /* Assign Headline values */
+    $smarty->assign("OLV_Header_Enabled",$this->displayHeaderFlag);
+    $smarty->assign("OLV_Header",$this->headline);
  
-    #return($smarty->fetch("ObjectListViewport.tpl"));
+    return($smarty->fetch("ObjectListViewport.tpl"));
   }
 
 
index 3404deb2a6e1ca2721d1aa7267ee047aa8f8ec6a..3327ce1b954fb0db635b7948201f8a276046b20e 100644 (file)
@@ -30,7 +30,7 @@ window.onresize = updateObjectListViewportSize;
         all = getElementsByStyleClass('ObjectListViewport');
         for (i = 0; i < all.length; ++i){
 
-            list_id = all[i].id.replace(/^.*_/,"_");
+            list_id = all[i].id.replace(/^ObjectListViewport/,"");
 
             /* Set Viewport to min height, to ensure
              *  that resize will work correctly in konqueror
index 1c529f84e6d4f34c4e850a4dbb39b755521e8bd7..5619ce35e017791c78c71df0169381cd252b7294 100644 (file)
@@ -1,43 +1,51 @@
 <table class='ObjectListViewport' id='ObjectListViewport_{$OLV_List_Id}' cellspacing=0 cellpadding=0>
-      <tr>
-        <td>
-                 <table class='ObjectListViewport_Table' id='ObjectListViewport_Table_{$OLV_List_Id}' cellpadding=0 cellspacing=0 >
-                       <tr>
-              <td class='ObjectListViewport_TD_Header' id='ObjectListViewport_TD_Header_{$OLV_List_Id}'>
-                <table class='ObjectListViewport_Header_Table' id='ObjectListViewport_Header_Table_{$OLV_List_Id}'>
-                  <tr>
-
-                                       {foreach from=$OLV_Header key=key item=item}
-                                               <td class='ObjectListViewport_Header_Cell' style='{$item.style}'>{$item.name}</td>
-                                       {/foreach}
+  <tr>
+    <td>
+      <table class='ObjectListViewport_Table' id='ObjectListViewport_Table_{$OLV_List_Id}' cellpadding=0 cellspacing=0 >
+        <tr>
+          <td class='ObjectListViewport_TD_Header' id='ObjectListViewport_TD_Header_{$OLV_List_Id}'>
+            <table class='ObjectListViewport_Header_Table' id='ObjectListViewport_Header_Table_{$OLV_List_Id}'>
+              <tr>
+                {foreach from=$OLV_Header key=key item=item}
+                  <td class='ObjectListViewport_Header_Cell' style='{$item.style}'>{$item.name}</td>
+                {/foreach}
+              </tr>
+            </table>
+          </td>
+        </tr>
+        <tr>
+          <td class='ObjectListViewport_TD_Entries' id='ObjectListViewport_TD_Entries_{$OLV_List_Id}'>
+            <div class='ObjectListViewport_Entry_Cover' id='ObjectListViewport_Entry_Cover_{$OLV_List_Id}'>
+              <table class='ObjectListViewport_Entry_Table' id='ObjectListViewport_Entry_Table_{$OLV_List_Id}'>
+                {foreach from=$OLV_Entries key=key item=item}
+                  <tr class="{$item.row.class}">
+                    {foreach from=$item.cols key=key2 item=item2}
+                      <td class='ObjectListViewport_Entry_Cell' style='{$item2.style1}'>
+                        <div style='{$item2.style2}'>
+                          {$item2.value}
+                        </div>
+                      </td>
+                    {/foreach}
                   </tr>
-                </table>
-              </td>
-            </tr>
-                       <tr>
-                         <td class='ObjectListViewport_TD_Entries' id='ObjectListViewport_TD_Entries_{$OLV_List_Id}'>
-                               <div class='ObjectListViewport_Entry_Cover' id='ObjectListViewport_Entry_Cover_{$OLV_List_Id}'>
-                                 <table class='ObjectListViewport_Entry_Table' id='ObjectListViewport_Entry_Table_{$OLV_List_Id}'>
+                {/foreach}
+              </table>
+            </div>
+          </td>
+        </tr>
+        <tr>
+          <td class='ObjectListViewport_TD_Footer' id='ObjectListViewport_TD_Footer_{$OLV_List_Id}'>
+            <table class='ObjectListViewport_Footer_Table'>
+              <tr>
+                <td class='ObjectListViewport_Footer_Cell' colspan='{$OLV_Num_Cols}'>{$OLV_Footer_Message}</td>
+              </tr>
+            </table>
+          </td>
+        </tr>
+      </table>
+    </td>
+  </tr>
+</table>
 <!--
-                                       {foreach from=$OLV_Entries key=key item=item}
-                                               {$key}
-                                       {/foreach}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 -->
-                                 </table>
-                               </div>
-                         </td>
-                       </tr>
-                       <tr>
-              <td class='ObjectListViewport_TD_Footer' id='ObjectListViewport_TD_Footer_{$OLV_List_Id}'>
-                <table class='ObjectListViewport_Footer_Table'>
-                  <tr>
-                    <td class='ObjectListViewport_Footer_Cell' colspan='{$OLV_Num_Cols}'>{$OLV_Footer_Message}</td>
-                  </tr>
-                </table>
-              </td>
-            </tr>
-                 </table>
-        </td>
-      </tr>
-    </table>