mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
some changes to date_selector and date_time_selector. Now automatically disabledIf disable checkbox is checked. 'optional' option includes a disable checkbox.
This commit is contained in:
parent
ce446e0907
commit
11f260f4ee
@ -81,46 +81,72 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
||||
$this->_elements[] =& MoodleQuickForm::createElement('select', 'year', get_string('year', 'form'), $years, $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->_elements[] =& MoodleQuickForm::createElement('checkbox', 'off', null, get_string('disable'), $this->getAttributes(), true);
|
||||
}
|
||||
$this->setValue();
|
||||
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' == $event) {
|
||||
return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
// if no boxes were checked, then there is no value in the array
|
||||
// yet we don't want to display default value in this case
|
||||
if ($caller->isSubmitted()) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
$requestvalue=$value;
|
||||
if ($value == 0) {
|
||||
$value = time();
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
$currentdate = usergetdate($value);
|
||||
$value = array(
|
||||
'day' => $currentdate['mday'],
|
||||
'month' => $currentdate['mon'],
|
||||
'year' => $currentdate['year']);
|
||||
// If optional, default to off, unless a date was provided
|
||||
if($this->_options['optional']) {
|
||||
$value['off'] = ($requestvalue == 0) ? true : false;
|
||||
}
|
||||
} else {
|
||||
$value['off'] = (isset($value['off'])) ? true : false;
|
||||
}
|
||||
if (null !== $value){
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
case 'createElement':
|
||||
if($arg[2]['optional']) {
|
||||
$caller->disabledIf($arg[0], $arg[0].'[off]', 'checked');
|
||||
}
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
break;
|
||||
default:
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
}
|
||||
// {{{ setValue()
|
||||
} // end func onQuickFormEvent
|
||||
|
||||
function setValue($value=0)
|
||||
{
|
||||
$requestvalue=$value;
|
||||
if (!($value)) {
|
||||
$value = time();
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
$currentdate = usergetdate($value);
|
||||
$value = array(
|
||||
'day' => $currentdate['mday'],
|
||||
'month' => $currentdate['mon'],
|
||||
'year' => $currentdate['year']);
|
||||
// If optional, default to off, unless a date was provided
|
||||
if($this->_options['optional']) {
|
||||
$value['on'] = $requestvalue ? true : false;
|
||||
}
|
||||
}
|
||||
parent::setValue($value);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
function toHtml()
|
||||
@ -161,12 +187,13 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group
|
||||
}
|
||||
if (count($valuearray)){
|
||||
if($this->_options['optional']) {
|
||||
// If checkbox is not on, the value is zero, so go no further
|
||||
if(empty($valuearray['on'])) {
|
||||
// If checkbox is on, the value is zero, so go no further
|
||||
if(!empty($valuearray['off'])) {
|
||||
$value[$this->getName()]=0;
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
$value[$this->getName()]=make_timestamp($valuearray['year'],
|
||||
$valuearray['month'],
|
||||
$valuearray['day'],
|
||||
|
@ -31,8 +31,6 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
||||
*/
|
||||
var $_wrap = array('', '');
|
||||
|
||||
//var $_seperator=array('', '', 'Time ', '');
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
@ -90,47 +88,74 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
||||
$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->_elements[] =& MoodleQuickForm::createElement('checkbox', 'off', null, get_string('disable'), $this->getAttributes(), true);
|
||||
}
|
||||
|
||||
$this->setValue();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ onQuickFormEvent()
|
||||
|
||||
/**
|
||||
* Called by HTML_QuickForm whenever form event is made on this element
|
||||
*
|
||||
* @param string $event Name of event
|
||||
* @param mixed $arg event arguments
|
||||
* @param object $caller calling object
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function onQuickFormEvent($event, $arg, &$caller)
|
||||
{
|
||||
if ('updateValue' == $event) {
|
||||
return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
|
||||
} else {
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
switch ($event) {
|
||||
case 'updateValue':
|
||||
// constant values override both default and submitted ones
|
||||
// default values are overriden by submitted
|
||||
$value = $this->_findValue($caller->_constantValues);
|
||||
if (null === $value) {
|
||||
// if no boxes were checked, then there is no value in the array
|
||||
// yet we don't want to display default value in this case
|
||||
if ($caller->isSubmitted()) {
|
||||
$value = $this->_findValue($caller->_submitValues);
|
||||
} else {
|
||||
$value = $this->_findValue($caller->_defaultValues);
|
||||
}
|
||||
}
|
||||
$requestvalue=$value;
|
||||
if ($value == 0) {
|
||||
$value = time();
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
$currentdate = usergetdate($value);
|
||||
$value = array(
|
||||
'minute' => $currentdate['minutes'],
|
||||
'hour' => $currentdate['hours'],
|
||||
'day' => $currentdate['mday'],
|
||||
'month' => $currentdate['mon'],
|
||||
'year' => $currentdate['year']);
|
||||
// If optional, default to off, unless a date was provided
|
||||
if($this->_options['optional']) {
|
||||
$value['off'] = ($requestvalue == 0) ? true : false;
|
||||
}
|
||||
} else {
|
||||
$value['off'] = (isset($value['off'])) ? true : false;
|
||||
}
|
||||
if (null !== $value){
|
||||
$this->setValue($value);
|
||||
}
|
||||
break;
|
||||
case 'createElement':
|
||||
if($this->_options['optional']) {
|
||||
$caller->disabledIf($arg[0], $arg[0].'[off]', 'checked');
|
||||
}
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
break;
|
||||
default:
|
||||
return parent::onQuickFormEvent($event, $arg, $caller);
|
||||
}
|
||||
}
|
||||
|
||||
// {{{ setValue()
|
||||
|
||||
function setValue($value=0)
|
||||
{
|
||||
$requestvalue=$value;
|
||||
if (!($value)) {
|
||||
$value = time();
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
$currentdate = usergetdate($value);
|
||||
$value = array(
|
||||
'minute' => $currentdate['minutes'],
|
||||
'hour' => $currentdate['hours'],
|
||||
'day' => $currentdate['mday'],
|
||||
'month' => $currentdate['mon'],
|
||||
'year' => $currentdate['year']);
|
||||
if($this->_options['optional']) {
|
||||
$value['on'] = $requestvalue ? true : false;
|
||||
}
|
||||
}
|
||||
parent::setValue($value);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// {{{ toHtml()
|
||||
|
||||
@ -166,14 +191,14 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{
|
||||
$valuearray = array();
|
||||
foreach ($this->_elements as $element){
|
||||
$thisexport = $element->exportValue($submitValues[$this->getName()], true);
|
||||
if ($thisexport!==null){
|
||||
if ($thisexport!=null){
|
||||
$valuearray += $thisexport;
|
||||
}
|
||||
}
|
||||
if (count($valuearray)){
|
||||
if($this->_options['optional']) {
|
||||
// If checkbox is not on, the value is zero, so go no further
|
||||
if(empty($valuearray['on'])) {
|
||||
// If checkbox is on, the value is zero, so go no further
|
||||
if(!empty($valuearray['off'])) {
|
||||
$value[$this->getName()]=0;
|
||||
return $value;
|
||||
}
|
||||
|
@ -845,7 +845,12 @@ function validate_' . $this->_attributes['id'] . '(frm) {
|
||||
foreach ($this->_dependencies as $dependentOn => $elements){
|
||||
$js .= "'$dependentOn'".' : {dependents :[';
|
||||
foreach ($elements as $element){
|
||||
$js.="'".$element['dependent']."', ";
|
||||
$elementNames = $this->_getElNamesRecursive($element['dependent']);
|
||||
foreach ($elementNames as $dependent){
|
||||
if ($dependent != $dependentOn) {
|
||||
$js.="'".$dependent."', ";
|
||||
}
|
||||
}
|
||||
}
|
||||
$js=rtrim($js, ', ');
|
||||
$js .= "],\n";
|
||||
@ -901,13 +906,8 @@ function validate_' . $this->_attributes['id'] . '(frm) {
|
||||
* @param mixed $value used in conjunction with condition.
|
||||
*/
|
||||
function disabledIf($elementName, $dependentOn, $condition = 'notchecked', $value=null){
|
||||
$dependents = $this->_getElNamesRecursive($elementName);
|
||||
foreach ($dependents as $dependent){
|
||||
if ($dependent != $dependentOn) {
|
||||
$this->_dependencies[$dependentOn][] = array('dependent'=>$dependent,
|
||||
$this->_dependencies[$dependentOn][] = array('dependent'=>$elementName,
|
||||
'condition'=>$condition, 'value'=>$value);
|
||||
}
|
||||
}
|
||||
}
|
||||
function _registerNoSubmitButton($addfieldsname){
|
||||
$this->_noSubmitButtons[]=$addfieldsname;
|
||||
|
@ -21,16 +21,12 @@ class data_mod_form extends moodleform_mod {
|
||||
$mform->addRule('intro', get_string('required'), 'required', null, 'client');
|
||||
|
||||
$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'))+
|
||||
@ -71,6 +67,5 @@ class data_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
@ -478,17 +478,8 @@
|
||||
if ($forum->type == 'news' && !$fromform->parent) {
|
||||
$updatediscussion = new object;
|
||||
$updatediscussion->id = $fromform->discussion;
|
||||
if (empty($fromform->timestartdisabled)) {
|
||||
$updatediscussion->timestart = $fromform->timestart;
|
||||
} else {
|
||||
$updatediscussion->timestart = 0;
|
||||
}
|
||||
if (empty($fromform->timeenddisabled)) {
|
||||
$updatediscussion->timeend = $fromform->timeend;
|
||||
} else {
|
||||
$updatediscussion->timeend = 0;
|
||||
}
|
||||
|
||||
$updatediscussion->timestart = $fromform->timestart;
|
||||
$updatediscussion->timeend = $fromform->timeend;
|
||||
if (!update_record('forum_discussions', $updatediscussion)) {
|
||||
error(get_string("couldnotupdate", "forum"), $errordestination);
|
||||
}
|
||||
@ -574,16 +565,8 @@
|
||||
if ($forum->type == 'news' && !$fromform->parent) {
|
||||
$newstopic = true;
|
||||
}
|
||||
if ($newstopic && empty($fromform->timestartdisabled)) {
|
||||
$discussion->timestart = $fromform->timestart;
|
||||
} else {
|
||||
$discussion->timestart = 0;
|
||||
}
|
||||
if ($newstopic && empty($fromform->timeenddisabled)) {
|
||||
$discussion->timeend = $fromform->timeend;
|
||||
} else {
|
||||
$discussion->timeend = 0;
|
||||
}
|
||||
$discussion->timestart = $fromform->timestart;
|
||||
$discussion->timeend = $fromform->timeend;
|
||||
|
||||
$message = '';
|
||||
if ($discussion->id = forum_add_discussion($discussion, $message)) {
|
||||
@ -751,6 +734,8 @@
|
||||
'userid'=>$post->userid,
|
||||
'parent'=>$post->parent,
|
||||
'discussion'=>$post->discussion,
|
||||
'timestart'=>$discussion->timestart,
|
||||
'timeend'=>$discussion->timeend,
|
||||
'course'=>$course->id)+
|
||||
|
||||
$page_params+
|
||||
@ -763,22 +748,6 @@
|
||||
'groupid'=>$post->groupid):
|
||||
array())+
|
||||
|
||||
(isset($discussion->timestart)?
|
||||
array('timestart'=>$discussion->timestart):
|
||||
array('timestart'=>0))+
|
||||
|
||||
(isset($discussion->timeend)?
|
||||
array('timeend'=>$discussion->timeend):
|
||||
array('timeend'=>0))+
|
||||
|
||||
(isset($discussion->timestartdisabled)?
|
||||
array('timestartdisabled'=>$discussion->timestartdisabled):
|
||||
array('timestartdisabled'=>1))+
|
||||
|
||||
(isset($discussion->timeenddisabled)?
|
||||
array('timeenddisabled'=>$discussion->timeenddisabled):
|
||||
array('timeenddisabled'=>1))+
|
||||
|
||||
(isset($discussion->id)?
|
||||
array('discussion'=>$discussion->id):
|
||||
array()));
|
||||
|
@ -64,33 +64,21 @@ class forum_post_form extends moodleform {
|
||||
$mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
|
||||
}
|
||||
|
||||
if (!isset($discussion->timestart)) {
|
||||
$discussion->timestart = 0;
|
||||
}
|
||||
if (!isset($discussion->timeend)) {
|
||||
$discussion->timeend = 0;
|
||||
}
|
||||
if (!empty($CFG->forum_enabletimedposts) && !$post->parent) {
|
||||
$mform->addElement('header', '', get_string('displayperiod', 'forum'));
|
||||
|
||||
$timestartgroup = array();
|
||||
$timestartgroup[] = &MoodleQuickForm::createElement('date_selector', 'timestart', get_string('timestartday', 'forum'));
|
||||
$timestartgroup[] = &MoodleQuickForm::createElement('checkbox', 'timestartdisabled', '', get_string('disable'));
|
||||
$mform->addGroup($timestartgroup, 'timestartgroup', get_string('displaystart', 'forum'), ' ', false);
|
||||
$mform->setHelpButton('timestartgroup', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
|
||||
$mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional'=>true));
|
||||
$mform->setHelpButton('timestart', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
|
||||
|
||||
$timeendgroup = array();
|
||||
$timeendgroup[] = &MoodleQuickForm::createElement('date_selector', 'timeend', get_string('timeendday', 'forum'));
|
||||
$timeendgroup[] = &MoodleQuickForm::createElement('checkbox', 'timeenddisabled', '', get_string('disable'));
|
||||
$mform->addGroup($timeendgroup, 'timeendgroup', get_string('displayend', 'forum'), ' ', false);
|
||||
$mform->setHelpButton('timeendgroup', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
|
||||
$mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional'=>true));
|
||||
$mform->setHelpButton('timeend', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
|
||||
|
||||
} else {
|
||||
$mform->addElement('hidden', 'timestartdisabled', '1');
|
||||
$mform->setType('timestartdisabled', PARAM_INT);
|
||||
$mform->addElement('hidden', 'timeenddisabled', '1');
|
||||
$mform->setType('timeenddisabled', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'timestart');
|
||||
$mform->setType('timestart', PARAM_INT);
|
||||
$mform->addElement('hidden', 'timeend');
|
||||
$mform->setType('timeend', PARAM_INT);
|
||||
$mfrom->setConstants(array('timestart'=> 0, 'timeend'=>0));
|
||||
}
|
||||
if (isset($post->edit)) {
|
||||
$submit_string = get_string('savechanges');
|
||||
@ -128,9 +116,9 @@ class forum_post_form extends moodleform {
|
||||
|
||||
function validation($data) {
|
||||
$error = array();
|
||||
if (empty($data['timeenddisabled']) && empty($data['timestartdisabled'])
|
||||
if (($data['timeend']!=0) && ($data['timestart']!=0)
|
||||
&& $data['timeend'] <= $data['timestart']) {
|
||||
$error['timeendgroup'] = get_string('timestartenderror', 'forum');
|
||||
$error['timeend'] = get_string('timestartenderror', 'forum');
|
||||
}
|
||||
return (count($error)==0) ? true : $error;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user