Merge branch 'MDL-37459-master-fix2' of git://github.com/damyon/moodle

This commit is contained in:
Marina Glancy 2013-06-12 16:53:49 +10:00
commit 128e9315d6
5 changed files with 104 additions and 26 deletions

View File

@ -49,6 +49,12 @@ abstract class moodleform_mod extends moodleform {
/** a flag indicating whether outcomes are being used*/
protected $_outcomesused;
/**
* @var bool A flag used to indicate that this module should lock settings
* based on admin settings flags in definition_after_data.
*/
protected $applyadminlockedflags = false;
function moodleform_mod($current, $section, $cm, $course) {
$this->current = $current;
$this->_instance = $current->instance;
@ -278,6 +284,9 @@ abstract class moodleform_mod extends moodleform {
}
}
}
// Freeze admin defaults if required (and not different from default)
$this->apply_admin_locked_flags();
}
// form verification
@ -866,22 +875,24 @@ abstract class moodleform_mod extends moodleform {
}
/**
* Get the list of admin settings for this module and apply any defaults/advanced/locked settings.
* Get the list of admin settings for this module and apply any locked settings.
* This cannot happen in apply_admin_defaults because we do not the current values of the settings
* in that function because set_data has not been called yet.
*
* @param $datetimeoffsets array - If passed, this is an array of fieldnames => times that the
* default date/time value should be relative to. If not passed, all
* date/time fields are set relative to the users current midnight.
* @return void
*/
function apply_admin_defaults($datetimeoffsets = array()) {
protected function apply_admin_locked_flags() {
global $OUTPUT;
if (!$this->applyadminlockedflags) {
return;
}
$settings = get_config($this->_modname);
$mform = $this->_form;
$lockedicon = html_writer::tag('span',
$OUTPUT->pix_icon('t/locked', get_string('locked', 'admin')),
array('class' => 'action-icon'));
$usermidnight = usergetmidnight(time());
foreach ($settings as $name => $value) {
if (strpos('_', $name) !== false) {
@ -889,31 +900,64 @@ abstract class moodleform_mod extends moodleform {
}
if ($mform->elementExists($name)) {
$element = $mform->getElement($name);
if ($element->getType() == 'date_time_selector') {
$enabledsetting = $name . '_enabled';
if (empty($settings->$enabledsetting)) {
$mform->setDefault($name, 0);
} else {
$relativetime = $usermidnight;
if (isset($datetimeoffsets[$name])) {
$relativetime = $datetimeoffsets[$name];
}
$mform->setDefault($name, $relativetime + $settings->$name);
$lockedsetting = $name . '_locked';
if (!empty($settings->$lockedsetting)) {
$value = $mform->getElement($name)->getValue();
$value = reset($value);
if ($value == $settings->$name) {
$mform->setConstant($name, $settings->$name);
$element->setLabel($element->getLabel() . $lockedicon);
// Do not use hardfreeze because we need the hidden input to check dependencies.
$element->freeze();
}
}
}
}
}
/**
* Get the list of admin settings for this module and apply any defaults/advanced/locked settings.
*
* @param $datetimeoffsets array - If passed, this is an array of fieldnames => times that the
* default date/time value should be relative to. If not passed, all
* date/time fields are set relative to the users current midnight.
* @return void
*/
public function apply_admin_defaults($datetimeoffsets = array()) {
// This flag triggers the settings to be locked in apply_admin_locked_flags().
$this->applyadminlockedflags = true;
$settings = get_config($this->_modname);
$mform = $this->_form;
$usermidnight = usergetmidnight(time());
$isupdate = !empty($this->_cm);
foreach ($settings as $name => $value) {
if (strpos('_', $name) !== false) {
continue;
}
if ($mform->elementExists($name)) {
$element = $mform->getElement($name);
if (!$isupdate) {
if ($element->getType() == 'date_time_selector') {
$enabledsetting = $name . '_enabled';
if (empty($settings->$enabledsetting)) {
$mform->setDefault($name, 0);
} else {
$relativetime = $usermidnight;
if (isset($datetimeoffsets[$name])) {
$relativetime = $datetimeoffsets[$name];
}
$mform->setDefault($name, $relativetime + $settings->$name);
}
} else {
$mform->setDefault($name, $settings->$name);
}
} else {
$mform->setDefault($name, $settings->$name);
}
$advancedsetting = $name . '_adv';
if (!empty($settings->$advancedsetting)) {
$mform->setAdvanced($name);
}
$lockedsetting = $name . '_locked';
if (!empty($settings->$lockedsetting)) {
$mform->setConstant($name, $settings->$name);
$element->setLabel($element->getLabel() . $lockedicon);
// Do not use hardfreeze because we need the hidden input to check dependencies.
$element->freeze();
}
}
}
}

View File

@ -1615,6 +1615,9 @@ abstract class admin_setting {
}
}
if (!empty($output)) {
return html_writer::tag('span', $output, array('class' => 'adminsettingsflags'));
}
return $output;
}

View File

@ -251,6 +251,12 @@
.admin_colourpicker .previewcolour {border:1px solid #000;margin-left:301px;}
.admin_colourpicker .currentcolour {border:1px solid #000;margin-left:301px;border-top-width:0;}
/* Styles for flags on admin settings */
.adminsettingsflags { float: right; }
.dir-rtl .adminsettingsflags { float: left; }
.adminsettingsflags label { margin-right: 7px; }
.dir-rtl .adminsettingsflags label { margin-left: 7px; }
/** Overide for RTL layout **/
.dir-rtl #adminsettings .form-item .form-setting,
.dir-rtl #adminsettings .form-item .form-label,

View File

@ -398,6 +398,31 @@ img.iconsmall {
direction: ltr;
}
/* Styles for flags on admin settings */
.adminsettingsflags {
float: right;
}
.dir-rtl .adminsettingsflags {
float: left;
}
.adminsettingsflags label {
margin-right: 7px;
}
.dir-rtl .adminsettingsflags label {
margin-left: 7px;
}
.form-description {
clear: right;
}
.dir-rtl .form-description {
clear: left;
}
.form-item .form-setting .form-htmlarea {
width: 640px;
display: inline;

File diff suppressed because one or more lines are too long