Revision: 2214
          http://mrbs.svn.sourceforge.net/mrbs/?rev=2214&view=rev
Author:   cimorrison
Date:     2011-12-28 21:41:49 +0000 (Wed, 28 Dec 2011)
Log Message:
-----------
Ensured that the ?\226?\128?\156all day?\226?\128?\157 check box only appears 
if the maximum booking duration allows that length of booking.   Based on a 
patch from Daniel Yule

Modified Paths:
--------------
    mrbs/trunk/web/Themes/default/header.inc
    mrbs/trunk/web/edit_entry.php
    mrbs/trunk/web/internalconfig.inc.php

Modified: mrbs/trunk/web/Themes/default/header.inc
===================================================================
--- mrbs/trunk/web/Themes/default/header.inc    2011-12-28 21:22:35 UTC (rev 
2213)
+++ mrbs/trunk/web/Themes/default/header.inc    2011-12-28 21:41:49 UTC (rev 
2214)
@@ -1009,6 +1009,8 @@
     var startKeepDisabled = ($('#' + startId).attr('class') == 
'keep_disabled');
     var endId = "end_seconds" + area;
     var endSelect = form[endId];
+    var allDayId = "all_day" + area;
+    var allDay = form[allDayId];
     var endKeepDisabled = ($('#' + endId).attr('class') == 'keep_disabled');
     var startIndex, startValue, endIndex, endValue;
     
@@ -1016,7 +1018,7 @@
     // If All Day is checked then just set the start and end values to the 
first
     // and last possible options.
     ?>
-    if (form.all_day && form.all_day.checked)
+    if (allDay && allDay.checked)
     {
       startValue = startOptions[area][0]['value']
       endValue = endOptions[area][nEndOptions[area] - 1]['value'];
@@ -1138,14 +1140,14 @@
     // then we disable all the time selectors (start, end and All Day) until
     // the dates are fixed.
     ?>
-    if (!form.all_day || !form.all_day.checked)
+    if (!allDay || !allDay.checked)
     {
       var newState = (dateDifference < 0);
       startSelect.disabled = newState || startKeepDisabled;
       endSelect.disabled = newState || endKeepDisabled;
-      if (form.all_day)
+      if (allDay)
       {
-        form.all_day.disabled = newState;
+        allDay.disabled = newState;
       }
     }
 
@@ -2578,12 +2580,13 @@
     ?>
     startSelect = form["start_seconds" + currentArea];
     endSelect = form["end_seconds" + currentArea];
-    if (form.all_day &&
-        !form.all_day.disabled && 
+    allDay = form["all_day" + currentArea];
+    if (allDay &&
+        !allDay.disabled && 
         (parseInt(startSelect.options[startSelect.selectedIndex].value) == 
startOptions[currentArea][0]['value']) &&
         (parseInt(endSelect.options[endSelect.selectedIndex].value) == 
endOptions[currentArea][nEndOptions[currentArea] - 1]['value']))
     {
-      form.all_day.checked = true;
+      allDay.checked = true;
       startSelect.disabled = true;
       endSelect.disabled = true;
       old_start = startSelect.options[startSelect.selectedIndex].value;

Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2011-12-28 21:22:35 UTC (rev 2213)
+++ mrbs/trunk/web/edit_entry.php       2011-12-28 21:41:49 UTC (rev 2214)
@@ -163,6 +163,7 @@
 function create_field_entry_start_date($disabled=FALSE)
 {
   global $start_time, $areas, $area_id, $periods, $default_duration_all_day, 
$id, $drag;
+  global $periods;
   
   echo "<div id=\"div_start_date\">\n";
   echo "<label>" . get_vocab("start") . ":</label>\n";
@@ -190,22 +191,30 @@
     $start_last = ($a['enable_periods']) ? $last : $last - $a['resolution'];
     $display_none = ($a['id'] != $area_id);
     genSlotSelector($a, "start_", $first, $start_last, $start_time, 
$display_none, $disabled);
+    
+    echo "<div class=\"group\">\n";
+    echo "<div id=\"ad{$a['id']}\"".($display_none ? " style=\"display: none\" 
" : "") .">\n";
+    // We don't show the all day checkbox if it's going to result in bookings 
that
+    // contravene the policy - ie if max_duration is enabled and an all day 
booking
+    // would be longer than the maximum duration allowed
+    $show_all_day = $is_admin || !$a['max_duration_enabled'] ||
+                    ( ($a['enable_periods'] && ($a['max_duration_periods'] >= 
count($periods))) ||
+                        (!$a['enable_periods'] && ($a['max_duration_secs'] >= 
($last - $first))) );
+    echo "<input id=\"all_day{$a['id']}\" class=\"checkbox\"" .
+         // If this is an existing booking that we are editing or copying, 
then we do
+         // not want the default duration applied
+         (($default_duration_all_day && !isset($id) && !$drag) ? " 
checked=\"checked\"" : "") .
+         " name=\"all_day\" type=\"checkbox\" value=\"yes\" 
onclick=\"OnAllDayClick(this)\"".
+         ($show_all_day? "" : " style=\"display: none;\" ").
+         ">\n";
+    if($show_all_day)
+    {
+      echo "<label for=\"all_day\">" . get_vocab("all_day") . "</label>\n";
+    }
+    echo "</div>\n";
+    echo "</div>\n";
   }
-
-  echo "<div class=\"group\">\n";
-  echo "<div id=\"ad\">\n";
-  echo "<input id=\"all_day\" class=\"checkbox\"" .
-    // If this is an existing booking that we are editing or copying, then we 
do
-    // not want the default duration applied
-    (($default_duration_all_day && !isset($id) && !$drag) ? " 
checked=\"checked\"" : "") .
-    " name=\"all_day\" type=\"checkbox\" value=\"yes\" 
onclick=\"OnAllDayClick(this)\"" .
-    ($disabled ? " disabled=\"disabled\"" : "") .
-    ">\n";
-  echo "<label for=\"all_day\">" . get_vocab("all_day") . "</label>\n";
   echo "</div>\n";
-  echo "</div>\n";
-
-  echo "</div>\n";
 }
 
 
@@ -314,11 +323,21 @@
         // area id because we'll need that when trying to match up slots: it 
only
         // makes sense to match up slots if both old and new area used the same
         // mode (periods/times).
+        
+        // For the "all day" checkbox, the process is slightly different.  This
+        // is because the checkboxes themselves are visible or not depending on
+        // the time restrictions for that particular area. (1) We set the 
display 
+        // for the old *container* element to "none" and the new elements to 
+        // "block".  (2) We disable the old checkboxes and enable the new ones 
for
+        // the same reasons as above.  (3) We copy the value of the old check 
box
+        // to the new check box
         ?>
         var oldStartId = "start_seconds" + currentArea;
         var oldEndId = "end_seconds" + currentArea;
         var newStartId = "start_seconds" + area;
         var newEndId = "end_seconds" + area;
+        var oldAllDayId = "ad" + currentArea;
+        var newAllDayId = "ad" + area;
         var oldAreaStartValue = 
formObj[oldStartId].options[formObj[oldStartId].selectedIndex].value;
         var oldAreaEndValue = 
formObj[oldEndId].options[formObj[oldEndId].selectedIndex].value;
         $("#" + oldStartId).hide()
@@ -329,6 +348,17 @@
                            .removeAttr('disabled');
         $("#" + newEndId).show()
                          .removeAttr('disabled');
+                         +        $("#" + oldAllDayId).hide();
+        $("#" + newAllDayId).show();
+        if($("#all_day" + currentArea).attr('checked') == 'checked')
+        { 
+          $("#all_day" + area).attr('checked', 
'checked').removeAttr('disabled');
+        }
+        else
+        {
+          $("#all_day" + area).removeAttr('checked').removeAttr('disabled');
+        }
+        $("#all_day" + currentArea).removeAttr('disabled');
         var oldArea = currentArea;
         currentArea = area;
         prevStartValue = undefined;
@@ -1003,6 +1033,14 @@
   for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
   {
     $areas[$row['id']] = $row;
+    // The following config settings aren't yet per-area, but we'll treat them 
as if
+    // they are to make it easier to change them to per-area settings in the 
future.
+    $areas[$row['id']]['max_duration_enabled'] = $max_duration_enabled;
+    $areas[$row['id']]['max_duration_secs']    = $max_duration_secs;
+    $areas[$row['id']]['max_duration_periods'] = $max_duration_periods;
+    // Generate some derived settings
+    $areas[$row['id']]['max_duration_qty'] = 
$areas[$row['id']]['max_duration_secs'];
+    toTimeString($areas[$row['id']]['max_duration_qty'], 
$areas[$row['id']]['max_duration_units']);
   }
 }
 
@@ -1020,7 +1058,7 @@
   echo "areas[${area['id']}] = new Array();\n";
   foreach ($area as $key => $value)
   {
-    if ($key == "area_name")
+    if (in_array($key, array('area_name', 'max_duration_units')))
     {
       // Enclose strings in quotes
       $value = "'" . escape_js($value) . "'";
@@ -1032,15 +1070,6 @@
     }
     echo "areas[${area['id']}]['$key'] = $value;\n";
   }
-  // Add in the maximum durations.   These are not per area at the moment
-  // but they might be in the future
-  echo "areas[${area['id']}]['max_duration_enabled'] = " . 
(($max_duration_enabled) ? "true" : "false") . ";\n";
-  echo "areas[${area['id']}]['max_duration_secs'] = $max_duration_secs;\n";
-  echo "areas[${area['id']}]['max_duration_periods'] = 
$max_duration_periods;\n";
-  $max_duration_qty = $max_duration_secs;
-  toTimeString($max_duration_qty, $max_duration_units);
-  echo "areas[${area['id']}]['max_duration_qty'] = $max_duration_qty;\n";
-  echo "areas[${area['id']}]['max_duration_units'] = '$max_duration_units';\n";
 }
 ?>
 
@@ -1168,15 +1197,16 @@
 var old_start, old_end;
 
 // Executed when the user clicks on the all_day checkbox.
-function OnAllDayClick(allday)
+function OnAllDayClick(el)
 {
   var form = document.forms["main"];
   if (form)
   {
     var startSelect = form["start_seconds" + currentArea];
     var endSelect = form["end_seconds" + currentArea];
+    var allDay = form["all_day" + currentArea];
     var i;
-    if (form.all_day.checked) // If checking the box...
+    if (allDay.checked) // If checking the box...
     {
       <?php
       // Save the old values, disable the inputs and, to avoid user confusion,

Modified: mrbs/trunk/web/internalconfig.inc.php
===================================================================
--- mrbs/trunk/web/internalconfig.inc.php       2011-12-28 21:22:35 UTC (rev 
2213)
+++ mrbs/trunk/web/internalconfig.inc.php       2011-12-28 21:41:49 UTC (rev 
2214)
@@ -216,6 +216,7 @@
                                 'private_mandatory',
                                 'min_book_ahead_enabled',
                                 'max_book_ahead_enabled',
+                                'max_duration_enabled',  // not yet a per-area 
setting, but will be sometime
                                 'approval_enabled',
                                 'reminders_enabled',
                                 'enable_periods',

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


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to