]> git.mjollnir.org Git - moodle.git/commitdiff
added Sam's 'enabled' checkbox functionality
authorjamiesensei <jamiesensei>
Thu, 7 Dec 2006 10:39:28 +0000 (10:39 +0000)
committerjamiesensei <jamiesensei>
Thu, 7 Dec 2006 10:39:28 +0000 (10:39 +0000)
lib/form/dateselector.php
lib/form/datetimeselector.php
lib/formslib.php
mod/data/lib.php
mod/data/mod_form.php

index f59108d5d8c78d6dd723f70df2a2beea479da3e9..ed006f2cc288cd9198b253979e5a68fd793ace96 100644 (file)
@@ -79,15 +79,25 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
         $this->_elements[] =& MoodleQuickForm::createElement('select', 'day', get_string('day', 'form'), $days, $this->getAttributes(), true);
         $this->_elements[] =& MoodleQuickForm::createElement('select', 'month', get_string('month', 'form'), $months, $this->getAttributes(), true);
         $this->_elements[] =& MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $this->getAttributes(), true);
-        // If optional we add a checkbox (no text) which the user can use to turn if on
+        // If optional we add a checkbox which the user can use to turn if on
         if($this->_options['optional']) {
-            $this->_elements[] =& MoodleQuickForm::createElement('checkbox','on', null, get_string('enable'), $this->getAttributes(), true);
+            $this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'on', null, get_string('enable'), $this->getAttributes(), true);
         }
         $this->setValue();
 
     }
 
     // }}}
+    // {{{ onQuickFormEvent()
+
+    function onQuickFormEvent($event, $arg, &$caller)
+    {
+        if ('updateValue' == $event) {
+            return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
+        } else {
+            return parent::onQuickFormEvent($event, $arg, $caller);
+        }
+    }
     // {{{ setValue()
 
     function setValue($value=0)
@@ -131,16 +141,7 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
     }
 
     // }}}
-    // {{{ onQuickFormEvent()
 
-    function onQuickFormEvent($event, $arg, &$caller)
-    {
-        if ('updateValue' == $event) {
-            return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
-        } else {
-            return parent::onQuickFormEvent($event, $arg, $caller);
-        }
-    }
     /**
      * Output a timestamp. Give it the name of the group.
      *
index 1152e0325fccf1e0d52f5d4865853ad4cd32f3c1..d9fb834218dee937f21139ba70e762af7d2d0822 100644 (file)
@@ -22,7 +22,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
     * step     => step to increment minutes by
     */
     var $_options = array('startyear'=>1970, 'stopyear'=>2020,
-                    'timezone'=>99, 'applydst'=>true, 'step'=>5);
+                    'timezone'=>99, 'applydst'=>true, 'step'=>5, 'optional'=>false);
 
    /**
     * These complement separators, they are appended to the resultant HTML
@@ -88,15 +88,31 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
         $this->_elements[] =& MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $this->getAttributes(), true);
         $this->_elements[] =& MoodleQuickForm::createElement('select', 'hour', get_string('hour', 'form'), $hours, $this->getAttributes(), true);
         $this->_elements[] =& MoodleQuickForm::createElement('select', 'minute', get_string('minute', 'form'), $minutes, $this->getAttributes(), true);
+        // If optional we add a checkbox which the user can use to turn if on
+        if($this->_options['optional']) {
+            $this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'on', null, get_string('enable'), $this->getAttributes(), true);
+        }
 
         $this->setValue();
     }
 
     // }}}
+    // {{{ onQuickFormEvent()
+
+    function onQuickFormEvent($event, $arg, &$caller)
+    {
+        if ('updateValue' == $event) {
+            return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
+        } else {
+            return parent::onQuickFormEvent($event, $arg, $caller);
+        }
+    }
+
     // {{{ setValue()
 
     function setValue($value=0)
     {
+        $requestvalue=$value;
         if (!($value)) {
             $value = time();
         }
@@ -108,7 +124,9 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
                 'day' => $currentdate['mday'],
                 'month' => $currentdate['mon'],
                 'year' => $currentdate['year']);
-
+            if($this->_options['optional']) {
+                $value['on'] = $requestvalue ? true : false;
+            }
         }
         parent::setValue($value);
     }
@@ -134,16 +152,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
     }
 
     // }}}
-    // {{{ onQuickFormEvent()
 
-    function onQuickFormEvent($event, $arg, &$caller)
-    {
-        if ('updateValue' == $event) {
-            return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
-        } else {
-            return parent::onQuickFormEvent($event, $arg, $caller);
-        }
-    }
     /**
      * Output a timestamp. Give it the name of the group.
      *
@@ -161,22 +170,30 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
                 $valuearray += $thisexport;
             }
         }
-        if (count($valuearray)==0){
+        if (count($valuearray)){
+            if($this->_options['optional']) {
+                // If checkbox is not on, the value is zero, so go no further
+                if(empty($valuearray['on'])) {
+                    $value[$this->getName()]=0;
+                    return $value;
+                }
+            }
+            $valuearray=$valuearray + array('year'=>1970, 'month'=>1, 'day'=>1, 'hour'=>0, 'minute'=>0);
+            $value[$this->getName()]=make_timestamp(
+                                   $valuearray['year'],
+                                   $valuearray['month'],
+                                   $valuearray['day'],
+                                   $valuearray['hour'],
+                                   $valuearray['minute'],
+                                   0,
+                                   $this->_options['timezone'],
+                                   $this->_options['applydst']);
+
+            return $value;
+        } else {
+
             return null;
         }
-
-        $valuearray=$valuearray + array('year'=>1970, 'month'=>1, 'day'=>1, 'hour'=>0, 'minute'=>0);
-        $value[$this->getName()]=make_timestamp(
-                               $valuearray['year'],
-                               $valuearray['month'],
-                               $valuearray['day'],
-                               $valuearray['hour'],
-                               $valuearray['minute'],
-                               0,
-                               $this->_options['timezone'],
-                               $this->_options['applydst']);
-
-        return $value;
     }
 
     // }}}
index d3667614f08adde02a401d6725ab2488d9a963b3..021c3ab335ff6b6cd97d8acf06aca2450f5890b6 100644 (file)
@@ -843,7 +843,7 @@ function validate_' . $this->_attributes['id'] . '(frm) {
         $js = '<script type="text/javascript" language="javascript">'."\n";
         $js .= "var ".$this->getAttribute('id')."items= {";
         foreach ($this->_dependencies as $dependentOn => $elements){
-            $js .= $dependentOn.' : {dependents :[';
+            $js .= "'$dependentOn'".' : {dependents :[';
             foreach ($elements as $element){
                 $js.="'".$element['dependent']."', ";
             }
index 8a0d2a0ea46f03bc66acd132eb0932e5aa24d3a9..1fe7b9e7d79c5f6ed2a59fd34064f685dedb92e0 100755 (executable)
@@ -598,23 +598,6 @@ function data_add_instance($data) {
 
     $data->timemodified = time();
 
-    if (empty($data->availablefromenable)) {
-        $data->timeavailablefrom = 0;
-    }
-
-    if (empty($data->availabletoenable)) {
-        $data->timeavailableto = 0;
-    }
-
-    if (empty($data->viewfromenable)) {
-        $data->timeviewfrom = 0;
-    }
-
-    if (empty($data->viewtoenable)) {
-        $data->timeviewto = 0;
-    }
-
-
     if (! $data->id = insert_record('data', $data)) {
         return false;
     }
@@ -636,22 +619,6 @@ function data_update_instance($data) {
 
     $data->timemodified = time();
 
-    if (empty($data->availablefromenable)) {
-        $data->timeavailablefrom = 0;
-    }
-
-    if (empty($data->availabletoenable)) {
-        $data->timeavailableto = 0;
-    }
-
-    if (empty($data->viewfromenable)) {
-        $data->timeviewfrom = 0;
-    }
-
-    if (empty($data->viewtoenable)) {
-        $data->timeviewto = 0;
-    }
-
     if (! $data->instance = update_record('data', $data)) {
         return false;
     }
index fa12ce71277562ca36afc605eda1545e62bb8ab9..01f3c7e49bd2b8cf40ba40b1a2a76bf17940621f 100644 (file)
@@ -20,29 +20,17 @@ class data_mod_form extends moodleform_mod {
                $mform->setType('intro', PARAM_RAW);
                $mform->addRule('intro', get_string('required'), 'required', null, 'client');
 
-        $availablefromgroup=array();
-           $availablefromgroup[]=&MoodleQuickForm::createElement('date_selector', 'availablefrom', '');
-           $availablefromgroup[]=&MoodleQuickForm::createElement('checkbox', 'availablefromenabled', '', get_string('enable'));
-        $mform->addGroup($availablefromgroup, 'availablefromgroup', get_string('availablefromdate', 'data'), '&nbsp;', false);
-        $mform->disabledIf('availablefromgroup', 'availablefromenabled');
-
-        $availabletogroup=array();
-           $availabletogroup[]=&MoodleQuickForm::createElement('date_selector', 'availableto', '');
-           $availabletogroup[]=&MoodleQuickForm::createElement('checkbox', 'availabletoenabled', '', get_string('enable'));
-        $mform->addGroup($availabletogroup, 'availabletogroup', get_string('availabletodate', 'data'), '&nbsp;', false);
-        $mform->disabledIf('availabletogroup', 'availabletoenabled');
-
-        $viewfromgroup=array();
-           $viewfromgroup[]=&MoodleQuickForm::createElement('date_selector', 'viewfrom', '');
-           $viewfromgroup[]=&MoodleQuickForm::createElement('checkbox', 'viewfromenabled', '', get_string('enable'));
-        $mform->addGroup($viewfromgroup, 'viewfromgroup', get_string('viewfromdate', 'data'), '&nbsp;', false);
-        $mform->disabledIf('viewfromgroup', 'viewfromenabled');
-
-        $viewtogroup=array();
-           $viewtogroup[]=&MoodleQuickForm::createElement('date_selector', 'viewto', '');
-           $viewtogroup[]=&MoodleQuickForm::createElement('checkbox', 'viewtoenabled', '', get_string('enable'));
-        $mform->addGroup($viewtogroup, 'viewtogroup', get_string('viewtodate', 'data'), '&nbsp;', false);
-        $mform->disabledIf('viewtogroup', 'viewtoenabled');
+        $mform->addElement('date_selector', 'timeavailablefrom', get_string('availablefromdate', 'data'), array('optional'=>true));
+        $mform->disabledIf('timeavailablefrom', 'timeavailablefrom[on]');
+
+        $mform->addElement('date_selector', 'timeavailableto', get_string('availabletodate', 'data'), array('optional'=>true));
+        $mform->disabledIf('timeavailableto', 'timeavailableto[on]');
+
+        $mform->addElement('date_selector', 'timeviewfrom', get_string('viewfromdate', 'data'), array('optional'=>true));
+        $mform->disabledIf('timeviewfrom', 'timeviewfrom[on]');
+
+        $mform->addElement('date_selector', 'timeviewto', get_string('viewtodate', 'data'), array('optional'=>true));
+        $mform->disabledIf('timeviewto', 'timeviewto[on]');
 
 
         $countoptions=  array(0=>get_string('none'))+