Revision: 2032
          http://mrbs.svn.sourceforge.net/mrbs/?rev=2032&view=rev
Author:   cimorrison
Date:     2011-09-29 21:08:45 +0000 (Thu, 29 Sep 2011)
Log Message:
-----------
Revamped users table to improve column sizing

Modified Paths:
--------------
    mrbs/branches/datatables/web/Themes/default/header.inc
    mrbs/branches/datatables/web/edit_users.php

Modified: mrbs/branches/datatables/web/Themes/default/header.inc
===================================================================
--- mrbs/branches/datatables/web/Themes/default/header.inc      2011-09-29 
19:58:10 UTC (rev 2031)
+++ mrbs/branches/datatables/web/Themes/default/header.inc      2011-09-29 
21:08:45 UTC (rev 2032)
@@ -193,17 +193,15 @@
         // which are merged with the default options.   If the browser is IE6 
or less
         // we don't bother making a dataTable:  it can be done, but it's not 
worth it.
         //
-        // [We've created a specific function to make a data table rather than 
just 
-        // using the dataTable() method directly, because if we're using 
options such as
-        // FixedColumns we have to set up the FixedColumns using a call back 
function
-        // after initialisation is complete, because the setting of the 
language text
-        // strings, which happens asynchronously, needs to happen first.    
When we're
-        // setting up the call back function we need to know the name of the 
dataTable
-        // object.   Having the makeDataTable() function allows us to keep the 
lines of
-        // code that use the object name together in one place.   It also 
allows us 
-        // to keep the browser conditional code in one place.]
+        // leftFixedMax is an optional third parameter, which if present will 
force the
+        // left hand column to be fixed with a maximum width of leftFixedMax * 
100% of
+        // the total table width (eg leftFixedMax = 0.33 gives you a fixed 
column with a
+        // maximum width of a third of the total table width).
+        //
+        // If you want to do anything else as part of fnInitComplete then 
you'll need
+        // to define fnInitComplete in specificOptions
         ?>
-        function makeDataTable(id, specificOptions)
+        function makeDataTable(id, specificOptions, leftFixedMax)
         {
           if (lteIE6)
           {
@@ -212,6 +210,7 @@
           }
           else
           {
+            var table = $(id);
             <?php // Set up the default options ?>
             var defaultOptions = {};
             <?php
@@ -241,12 +240,43 @@
                                       buttonText: '<?php echo 
get_vocab("show_hide_columns") ?>',
                                       bRestore: true,
                                       sRestore: '<?php echo 
get_vocab("restore_original") ?>'};
+            if (leftFixedMax !== undefined)
+            {
+              <?php 
+              // Fix the left hand column.  This has to be done when 
+              // initialisation is complete as the language files are loaded
+              // asynchronously
+
+              // Try and get a sensible value for the fixed column width, 
which is the
+              // smaller of the actual column width and a proportion of the 
overall table
+              // width.   (Unfortunately the actual column width is just the 
width of the
+              // column on the first page)
+              ?>
+              var tableWidth = table.outerWidth();
+              var leftWidth = table.find('th:first-child').outerWidth();
+              leftWidth = Math.min(leftWidth, tableWidth*leftFixedMax);
+              defaultOptions.fnInitComplete = function(){
+                  new FixedColumns(oTable, {"iLeftColumns": 1,
+                                            "iLeftWidth": leftWidth,
+                                            "sLeftWidth": "fixed"});
+                  $('.js div.datatable_container').css('visibility', 
'visible');
+                };
+              <?php
+              // Remove the first column from the column visibility
+              // list because it is fixed
+              ?>
+              defaultOptions.oColVis = {aiExclude: [0]};
+              <?php
+              // and stop it being reordered
+              ?>
+              defaultOptions.oColReorder = {iFixedColumns: 1};
+            }
             <?php
             // Merge the specific options with the default options.  We do a 
deep
             // merge.
             ?>
             var mergedOptions = $.extend(true, {}, defaultOptions, 
specificOptions);
-            var oTable = $(id).dataTable(mergedOptions);
+            var oTable = table.dataTable(mergedOptions);
             <?php // Need to redraw the datatable when the browser window is 
resized ?>
             $(window).bind('resize', function () {
                 oTable.fnDraw();
@@ -1333,42 +1363,11 @@
     ?>
     var tableOptions = new Object();
     <?php
-    // Set the initial order of columns (we want it to go
-    // "Action - Name - Rights" and not "Action - Rights - Name"
-    ?>
-    var nColumns = $('#users_table tr:first th').length;
-    tableOptions.oColReorder = {aiOrder: [0, 2, 1]};
-    for (var i=3; i < nColumns; i++)
-    {
-      tableOptions.oColReorder.aiOrder.push(i);
-    }
-    <?php
     // The Rights column has a span with title for sorting
     ?>
     tableOptions.aoColumnDefs = [{"sType": "title-numeric", "aTargets": [1]}]; 
-    <?php 
-    // Fix the left hand two columns.  This has to be done when 
-    // initialisation is complete as the language files are loaded
-    // asynchronously
-    ?>
-    tableOptions.fnInitComplete = function(){
-        new FixedColumns(usersTable, {"iLeftColumns": 2,
-                                      "iLeftWidth": 30,
-                                      "sLeftWidth": "relative"});
-        $('.js div.datatable_container').css('visibility', 'visible');
-      };
-    <?php
-    // Remove the first two columns from the column visibility
-    // list because these two are fixed
-    ?>
-    tableOptions.oColVis = {aiExclude: [0,1]};
-    <?php
-    // and stop those first two columns being reordered
-    ?>
-    tableOptions.oColReorder.iFixedColumns = 2;
     
-    var usersTable = makeDataTable('#users_table', tableOptions);
-
+    var usersTable = makeDataTable('#users_table', tableOptions, 0.33);
     <?php
   }
   

Modified: mrbs/branches/datatables/web/edit_users.php
===================================================================
--- mrbs/branches/datatables/web/edit_users.php 2011-09-29 19:58:10 UTC (rev 
2031)
+++ mrbs/branches/datatables/web/edit_users.php 2011-09-29 21:08:45 UTC (rev 
2032)
@@ -752,7 +752,7 @@
   $res = sql_query("SELECT * FROM $tbl_users ORDER BY level DESC, name");
   
   // Display the data in a table
-  $ignore_columns = array('id', 'password'); // We don't display these columns
+  $ignore_columns = array('id', 'password', 'name'); // We don't display these 
columns or they get special treatment
   
   echo "<div id=\"user_list\" class=\"datatable_container\">\n";
   echo "<table class=\"admin_table display\" id=\"users_table\">\n";
@@ -760,9 +760,11 @@
   // The table header
   echo "<thead>\n";
   echo "<tr>";
-  // First column which is an action button
-  echo "<th><div>" . get_vocab("action") . "</div></th>";
-  // Column headers
+  
+  // First column which is the name
+  echo "<th>" . get_vocab("users.name") . "</th>\n";
+  
+  // Other column headers
   foreach ($fields as $field)
   {
     $fieldname = $field['name'];
@@ -772,12 +774,12 @@
       echo "<th><div>" . get_loc_field_name($tbl_users, $fieldname) . 
"</div></th>";
     }
   }
+  
   echo "</tr>\n";
   echo "</thead>\n";
   
   // The table body
   echo "<tbody>\n";
-  $row_class = "odd_row";
   for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
   {
     // Check whether ordinary users are allowed to see other users' details.  
If not,
@@ -789,28 +791,20 @@
       continue;
     }
     
-    $row_class = ($row_class == "even_row") ? "odd_row" : "even_row";
-    echo "<tr class=\"$row_class\">\n";
-
-    // First column (the action button)
-    echo "<td class=\"action\"><div>\n";
+    echo "<tr>\n";
+    
+    // First column, which is the name
+    $html_name = htmlspecialchars($row['name']);
     // You can only edit a user if you have sufficient admin rights, or else 
if that user is yourself
     if (($level >= $min_user_editing_level) || (strcasecmp($row['name'], 
$user) == 0))
     {
-      echo "<form method=\"post\" action=\"" . 
htmlspecialchars(basename($PHP_SELF)) . "\">\n";
-      echo "<div>\n";
-      echo "<input type=\"hidden\" name=\"Action\" value=\"Edit\">\n";
-      echo "<input type=\"hidden\" name=\"Id\" value=\"" . $row['id'] . 
"\">\n";
-      echo "<input type=\"image\" class=\"button\" src=\"images/edit.png\"
-                 title=\"" . get_vocab("edit") . "\" alt=\"" . 
get_vocab("edit") . "\">\n";
-      echo "</div>\n";
-      echo "</form>\n";
+      $link = htmlspecialchars(basename($PHP_SELF)) . "?Action=Edit&amp;Id=" . 
$row['id'];
+      echo "<td><a title=\"$html_name\" href=\"$link\">$html_name</a></td>\n";
     }
     else
     {
-      echo "&nbsp;\n";
+      echo "<td title=\"$html_name\">$html_name</td>\n";
     }
-    echo "</div></td>\n";
     
     // Other columns
     foreach ($fields as $field)
@@ -865,6 +859,27 @@
         }  // end switch
       }
     }  // end foreach
+    /*
+    // Last column (the action button)
+    echo "<td class=\"action\"><div>\n";
+    // You can only edit a user if you have sufficient admin rights, or else 
if that user is yourself
+    if (($level >= $min_user_editing_level) || (strcasecmp($row['name'], 
$user) == 0))
+    {
+      echo "<form method=\"post\" action=\"" . 
htmlspecialchars(basename($PHP_SELF)) . "\">\n";
+      echo "<div>\n";
+      echo "<input type=\"hidden\" name=\"Action\" value=\"Edit\">\n";
+      echo "<input type=\"hidden\" name=\"Id\" value=\"" . $row['id'] . 
"\">\n";
+      echo "<input type=\"image\" class=\"button\" src=\"images/edit.png\"
+                 title=\"" . get_vocab("edit") . "\" alt=\"" . 
get_vocab("edit") . "\">\n";
+      echo "</div>\n";
+      echo "</form>\n";
+    }
+    else
+    {
+      echo "&nbsp;\n";
+    }
+    echo "</div></td>\n";
+    */
     
     echo "</tr>\n";
     

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to