Revision: 2521
          https://sourceforge.net/p/mrbs/code/2521/
Author:   cimorrison
Date:     2012-10-24 10:27:27 +0000 (Wed, 24 Oct 2012)
Log Message:
-----------
Restructured code

Modified Paths:
--------------
    mrbs/trunk/web/edit_entry.php
    mrbs/trunk/web/functions.inc

Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2012-10-24 09:26:27 UTC (rev 2520)
+++ mrbs/trunk/web/edit_entry.php       2012-10-24 10:27:27 UTC (rev 2521)
@@ -139,31 +139,41 @@
   {
     $format = hour_min_format();
   }
-  $html .= "<select" .
-           (($display_none) ? " style=\"display: none\"" : "") .
-           // If $display_none or $disabled are set then we'll also disable 
the select so
-           // that there is only one select passing through the variable to 
the handler
-           (($display_none || $disabled) ? " disabled=\"disabled\"" : "") .
-           // and if $disabled is set, give the element a class so that the 
JavaScript
-           // knows to keep it disabled
-           (($disabled) ? " class=\"keep_disabled\"" : "") .
-           " id=\"${prefix}seconds${area['id']}\" name=\"${prefix}seconds\" 
onChange=\"adjustSlotSelectors()\">\n";
- 
-  for ($s = $first; $s <= $last; $s += $resolution)
+  
+  // Build the attributes
+  $attributes = array();
+  $attributes[] = 'onChange="adjustSlotSelectors()"';
+  if ($disabled)
   {
-    $slot_string = ($enable_periods) ? $periods[intval(($s-$base)/60)] : 
hour_min($s);
-    $html .= "<option value=\"$s\"";
-    $html .= ($s == $current_s) ? " selected=\"selected\"" : "";
-    $html .= ">$slot_string</option>\n";
+    // If $disabled is set, give the element a class so that the JavaScript
+    // knows to keep it disabled
+    $attributes[] = 'class="keep_disabled"';
   }
-  $html .= "</select>\n";
-  // Add in a hidden input if the select is disabled but displayed
-  if ($disabled && !$display_none)
+  if ($display_none)
   {
-    $html .= "<input type=\"hidden\" name=\"${prefix}seconds\" 
value=\"$current_s\">\n";
+    $attributes[] = 'style="display: none"';
   }
   
-  echo $html;
+  // Build the options
+  $options = array();
+  for ($s = $first; $s <= $last; $s += $resolution)
+  {
+    $slot_string = ($enable_periods) ? $periods[intval(($s-$base)/60)] : 
hour_min($s);
+    $options[$s] = $slot_string;
+  }
+  
+  // If $display_none or $disabled are set then we'll also disable the select 
so
+  // that there is only one select passing through the variable to the handler
+  $params = array('name'         => $prefix . 'seconds',
+                  'id'           => $prefix . 'seconds' . $area['id'],
+                  'disabled'     => $disabled || $display_none,
+                  'create_hiden' => $disabled && !$display_none,
+                  'attributes'   => implode(' ', $attributes),
+                  'value'        => $current_s,
+                  'options'      => $options,
+                  'force_assoc'  => TRUE);
+
+  generate_select($params);
 }
 
 

Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc        2012-10-24 09:26:27 UTC (rev 2520)
+++ mrbs/trunk/web/functions.inc        2012-10-24 10:27:27 UTC (rev 2521)
@@ -521,7 +521,7 @@
 //        'value'       The value of the input.  Default ''
 //        'disabled'    Whether the field should be disabled.  Default FALSE
 //        'mandatory'   Whether the field is a required field.  Default FALSE
-//        'attributes'  Additional attributes, allowing HTML5 attributes.  
Default ''.
+//        'attributes'  Additional attributes, allowing HTML5 attributes.  
Default NULL.
 //
 function generate_checkbox($params)
 {
@@ -537,7 +537,6 @@
           trigger_error('Missing mandatory parameters', E_USER_NOTICE);
           break;
         case 'value':
-        case 'attributes':
           $params[$key] = '';
           break;
         case 'disabled':
@@ -558,7 +557,8 @@
   $html .= (empty($params['value'])) ? "" : " checked=\"checked\"";
   $html .= ($params['disabled']) ? " disabled=\"disabled\"" : "";
   $html .= ($params['mandatory']) ? " required aria-required=\"true\"" : "";
-  $html .= " " . $params['attributes'] . ">\n";
+  $html .= (isset($params['attributes'])) ? " " . $params['attributes'] : '';
+  $html .= ">\n";
   echo $html;
 }
 
@@ -578,7 +578,7 @@
 //        'attributes'  Additional attributes, allowing HTML5 input types such 
as number and
 //                      email to be used.   Note that additional attributes 
such as min, etc.
 //                      can also be included in the string, eg 'type="number" 
min="1" step="1"'.
-//                      Default ''.
+//                      Default NULL.
 //
 function generate_input($params)
 {
@@ -593,7 +593,6 @@
           trigger_error('Missing mandatory parameters', E_USER_NOTICE);
           break;
         case 'value':
-        case 'attributes':
           $params[$key] = '';
           break;
         case 'disabled':
@@ -613,14 +612,17 @@
     // no HTML escaping for the label - it is trusted
     $html .= "<label for=\"" . $params['name'] . "\">" . $params['label'] . 
"</label>\n";
   }
-  $html .= "<input " . $params['attributes'];
+  $html .= "<input";
+  $html .= (isset($params['attributes'])) ? " " . $params['attributes'] : "";
   $html .= " id=\"" . $params['name'] . "\" name=\"" . $params['name'] . "\"";
   $html .= ($params['disabled']) ? " disabled=\"disabled\"" : '';
   $html .= ($params['mandatory']) ? " required aria-required=\"true\"" : '';
   $html .= (isset($params['maxlength'])) ? " maxlength=\"" . 
$params['maxlength'] . "\"" : '';
   // Don't give an empty string if it's a number as that's not a valid 
floating point number
   // and will fail HTML5 validation
-  if ((strpos($params['attributes'], 'type="number"') === FALSE) || 
($params['value'] != '') )
+  if (!(isset($params['attributes'])) ||
+      (strpos($params['attributes'], 'type="number"') === FALSE) ||
+      ($params['value'] != '') )
   {
     $html .= " value=\"" . htmlspecialchars($params['value']) . "\"";
   }
@@ -841,25 +843,30 @@
 //
 //   $params    an associative array holding the function parameters:
 //      MANDATORY
-//        'name'        The name of the input.
+//        'name'          The name of the element.
 //      OPTIONAL
-//        'label'       The text to be used for the field label.
-//        'options'     An array of options for the select element.   Can be a 
simple
-//                      array or an associative array with value => text 
members for
-//                      each <option> in the <select> element.   Default is an 
empty array.
-//        'force_assoc' Boolean.  Forces the options array to be treated as an
-//                      associative array.  Default FALSE, ie it is treated as 
whatever
-//                      it looks like.  (This parameter is necessary because 
if you
-//                      index an array with strings that look like integers 
then PHP
-//                      casts the keys to integers and the array becomes a 
simple array)
-//        'value'       The value of the input.  Default ''
-//        'disabled'    Whether the field should be disabled.  Default FALSE
-//        'mandatory'   Whether the field is a required field.  Default FALSE
+//        'id'            The id of the element.  Defaults to the same as the 
name.
+//        'label'         The text to be used for the field label.
+//        'options'       An array of options for the select element.   Can be 
a simple
+//                        array or an associative array with value => text 
members for
+//                        each <option> in the <select> element.   Default is 
an empty array.
+//        'force_assoc'   Boolean.  Forces the options array to be treated as 
an
+//                        associative array.  Default FALSE, ie it is treated 
as whatever
+//                        it looks like.  (This parameter is necessary because 
if you
+//                        index an array with strings that look like integers 
then PHP
+//                        casts the keys to integers and the array becomes a 
simple array)
+//        'value'         The value of the input.  Default ''
+//        'disabled'      Whether the field should be disabled.  Default FALSE
+//        'create_hidden' Boolean.  If TRUE hidden inputs are created if 
'disabled' is set
+//                        Default TRUE
+//        'mandatory'     Whether the field is a required field.  Default FALSE
+//        'attributes'    Can be used for passing other attributes.  Default 
NULL
 //
 function generate_select($params)
 {
   // some sanity checking on params
-  foreach (array('label', 'name', 'options', 'force_assoc', 'value', 
'disabled', 'mandatory') as $key)
+  foreach (array('label', 'name', 'id', 'options', 'force_assoc', 'value',
+                 'disabled', 'create_hidden', 'mandatory', 'attributes') as 
$key)
   {
     if (!isset($params[$key]))
     {
@@ -868,6 +875,9 @@
         case 'name':
           trigger_error('Missing mandatory parameters', E_USER_NOTICE);
           break;
+        case 'id':
+          $params[$key] = $params['name'];
+          break;
         case 'options':
           $params[$key] = array();
           break;
@@ -879,6 +889,9 @@
         case 'mandatory':
           $params[$key] = FALSE;
           break;
+        case 'create_hidden':
+          $params[$key] = TRUE;
+          break;
         default:
           break;
       }
@@ -889,11 +902,12 @@
   $html = '';
   if (isset($params['label']))
   {
-    $html .= "<label for=\"" .$params['name'] . "\">" . $params['label'] . 
"</label>\n";
+    $html .= "<label for=\"" .$params['id'] . "\">" . $params['label'] . 
"</label>\n";
   }
-  $html .= "<select id=\"" . $params['name'] . "\" name=\"" . $params['name'] 
. "\"";
+  $html .= "<select id=\"" . $params['id'] . "\" name=\"" . $params['name'] . 
"\"";
   $html .= ($params['disabled']) ? " disabled=\"disabled\"" : "";
   $html .= ($params['mandatory']) ? " required aria-required=\"true\"" : "";
+  $html .= (isset($params['attributes'])) ? " " . $params['attributes'] : "";
   $html .= ">\n";
 
   foreach ($params['options'] as $value => $text)
@@ -911,7 +925,7 @@
   $html .= "</select>\n";
   
   // and a hidden input if the select box is disabled
-  if ($params['disabled'])
+  if ($params['disabled'] && $params['create_hidden'])
   {
     $html .= "<input type=\"hidden\" name=\"" . $params['name'] . "\" 
value=\"".
       htmlspecialchars($params['value'])."\">\n";
@@ -930,7 +944,7 @@
 //        'value'       The value of the input.  Default ''
 //        'disabled'    Whether the field should be disabled.  Default FALSE
 //        'mandatory'   Whether the field is a required field.  Default FALSE
-//        'attributes'  Additional attributes, allowing HTML5 attributes.  
Default ''.
+//        'attributes'  Additional attributes, allowing HTML5 attributes.  
Default NULL.
 //
 function generate_textarea($params)
 {
@@ -946,7 +960,6 @@
           trigger_error('Missing mandatory parameters', E_USER_NOTICE);
           break;
         case 'value':
-        case 'attributes':
           $params[$key] = '';
           break;
         case 'disabled':
@@ -963,7 +976,7 @@
   $html  = "<label for=\"" . $params['name'] . "\">" . $params['label'] . 
"</label>\n";
   // textarea rows and cols are overridden by CSS height and width
   $html .= "<textarea id=\"" . $params['name'] . "\" name=\"" . 
$params['name'] . "\" rows=\"8\" cols=\"40\"";
-  $html .= " " . $params['attributes'];
+  $html .= (isset($params['attributes'])) ? " " . $params['attributes'] : "";
   $html .= ($params['disabled']) ? " disabled=\"disabled\"" : '';
   $html .= ($params['mandatory']) ? " required aria-required=\"true\"" : '';
   $html .= ">" . htmlspecialchars($params['value']) . "</textarea>\n";
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to