This commit is contained in:
Andrew Nicols
2016-02-22 12:22:07 +08:00
14 changed files with 119 additions and 31 deletions
@@ -35,7 +35,6 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit
protected $allpermissions; // We don't need perms ourselves, but all our subclasses do.
protected $strperms; // Language string cache.
protected $risksurl; // URL in moodledocs about risks.
protected $riskicons = array(); // Cache to avoid regenerating the HTML for each risk icon.
/** @var array The capabilities to highlight as default/inherited. */
protected $parentpermissions;
protected $displaypermissions;
@@ -183,12 +182,12 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit
*/
public function get_risk_icon($type) {
global $OUTPUT;
if (!isset($this->riskicons[$type])) {
$iconurl = $OUTPUT->pix_url('i/' . str_replace('risk', 'risk_', $type));
$text = '<img src="' . $iconurl . '" alt="' . get_string($type . 'short', 'admin') . '" />';
$action = new popup_action('click', $this->risksurl, 'docspopup');
$this->riskicons[$type] = $OUTPUT->action_link($this->risksurl, $text, $action, array('title'=>get_string($type, 'admin')));
}
return $this->riskicons[$type];
$iconurl = $OUTPUT->pix_url('i/' . str_replace('risk', 'risk_', $type));
$text = '<img src="' . $iconurl . '" alt="' . get_string($type . 'short', 'admin') . '" />';
$action = new popup_action('click', $this->risksurl, 'docspopup');
$riskicon = $OUTPUT->action_link($this->risksurl, $text, $action, array('title'=>get_string($type, 'admin')));
return $riskicon;
}
}
+2 -1
View File
@@ -70,7 +70,8 @@ class block_navigation_renderer extends plugin_renderer_base {
// Turn our navigation items into list items.
$lis = array();
$number = 0;
// Set the number to be static for unique id's.
static $number = 0;
foreach ($items as $item) {
$number++;
if (!$item->display && !$item->contains_active_node()) {
+4
View File
@@ -450,6 +450,8 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
break;
default:
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN && $value) {
// Id should be different then the actual input added later.
$attrs['id'] .= '_hidden';
$html .= html_writer::empty_tag('input', $attrs + array('type' => 'hidden', 'value' => $value));
}
// Display option as checkbox
@@ -461,6 +463,8 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN || $mode == gradingform_rubric_controller::DISPLAY_PREVIEW) {
$attrs['disabled'] = 'disabled';
unset($attrs['name']);
// Id should be different then the actual input added later.
$attrs['id'] .= '_disabled';
}
$html .= html_writer::empty_tag('input', $attrs);
$html .= html_writer::tag('label', get_string($option, 'gradingform_rubric'), array('for' => $attrs['id']));
+3 -2
View File
@@ -1603,8 +1603,9 @@ class grade_report_grader extends grade_report {
}
$name = shorten_text($element['object']->get_name());
$courseheader = html_writer::tag('span', $name, array('id' => 'courseheader'));
$courseheader .= html_writer::label($showing, 'courseheader', false, array('class' => 'accesshide'));
$courseheaderid = 'courseheader_' . clean_param($name, PARAM_ALPHANUMEXT);
$courseheader = html_writer::tag('span', $name, array('id' => $courseheaderid));
$courseheader .= html_writer::label($showing, $courseheaderid, false, array('class' => 'accesshide'));
$courseheader .= $icon;
return $courseheader;
-1
View File
@@ -130,5 +130,4 @@ class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox{
}
return $output;
}
}
-1
View File
@@ -124,5 +124,4 @@ class MoodleQuickForm_text extends HTML_QuickForm_text{
function getHelpButton(){
return $this->_helpbutton;
}
}
+1 -1
View File
@@ -119,7 +119,7 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
if (count($options->repositories) > 0) {
$straddlink = get_string('choosealink', 'repository');
$str .= <<<EOD
<button id="filepicker-button-{$client_id}" class="visibleifjs">
<button id="filepicker-button-js-{$client_id}" class="visibleifjs">
$straddlink
</button>
EOD;
+2 -1
View File
@@ -2651,7 +2651,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
'actionbuttons'=>"\n\t\t".'<div id="{id}" class="fitem fitem_actionbuttons fitem_{type}"><div class="felement {type}">{element}</div></div>',
'fieldset'=>"\n\t\t".'<div id="{id}" class="fitem {advanced}<!-- BEGIN required --> required<!-- END required --> fitem_{type} {emptylabel}"><div class="fitemtitle"><div class="fgrouplabel"><label>{label}<!-- BEGIN required -->{req}<!-- END required -->{advancedimg} </label>{help}</div></div><fieldset class="felement {type}<!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error" tabindex="0">{error}</span><br /><!-- END error -->{element}</fieldset></div>',
'fieldset'=>"\n\t\t".'<div id="{id}" class="fitem {advanced} {class}<!-- BEGIN required --> required<!-- END required --> fitem_{type} {emptylabel}"><div class="fitemtitle"><div class="fgrouplabel"><label>{label}<!-- BEGIN required -->{req}<!-- END required -->{advancedimg} </label>{help}</div></div><fieldset class="felement {type}<!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error" tabindex="0">{error}</span><br /><!-- END error -->{element}</fieldset></div>',
'static'=>"\n\t\t".'<div class="fitem {advanced} {emptylabel}"><div class="fitemtitle"><div class="fstaticlabel">{label}<!-- BEGIN required -->{req}<!-- END required -->{advancedimg} {help}</div></div><div class="felement fstatic <!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error" tabindex="0">{error}</span><br /><!-- END error -->{element}</div></div>',
@@ -2766,6 +2766,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
$html =str_replace('{id}', 'fgroup_' . $group->getAttribute('id'), $html);
$html =str_replace('{name}', $group->getName(), $html);
$html =str_replace('{type}', 'fgroup', $html);
$html =str_replace('{class}', $group->getAttribute('class'), $html);
$emptylabel = '';
if ($group->getLabel() == '') {
$emptylabel = 'femptylabel';
+9 -2
View File
@@ -254,11 +254,18 @@ class HTML_QuickForm_element extends HTML_Common
return '';
} else {
$id = $this->getAttribute('id');
if (isset($id)) {
// Id of persistant input is different then the actual input.
$id = array('id' => $id . '_persistant');
} else {
$id = array();
}
return '<input' . $this->_getAttrString(array(
'type' => 'hidden',
'name' => $this->getName(),
'value' => $this->getValue()
) + (isset($id)? array('id' => $id): array())) . ' />';
) + $id) . ' />';
}
}
@@ -486,4 +493,4 @@ class HTML_QuickForm_element extends HTML_Common
// }}}
} // end class HTML_QuickForm_element
?>
?>
+1
View File
@@ -30,6 +30,7 @@ MDL-46467 - $mform->hardfreeze causes labels to loose their for HTML attribute
MDL-52081 - made all constructors PHP7 compatible
MDL-52826 - Remove onsubmit events pointing to the global validation functions and script
tag moved after the HTML
MDL-50484 - _getPersistantData() returns id with _persistant prefixed to element id.
Pear
+68
View File
@@ -577,6 +577,35 @@ class core_formslib_testcase extends advanced_testcase {
$this->assertTag(array('id' => 'id_grade_3_modgrade_point'), $html);
$this->assertTag(array('id' => 'id_grade_3_modgrade_scale'), $html);
}
/**
* Test persistant freeze elements have different id's.
*/
public function test_persistantrreeze_element() {
$this->resetAfterTest(true);
$form = new formslib_persistantrreeze_element();
ob_start();
$form->display();
$html = ob_get_clean();
// Test advcheckbox id's.
$this->assertTag(array('id' => 'id_advcheckboxpersistant'), $html);
$this->assertTag(array('id' => 'id_advcheckboxpersistant_persistant'), $html);
$this->assertTag(array('id' => 'id_advcheckboxnotpersistant'), $html);
$this->assertNotTag(array('id' => 'id_advcheckboxnotpersistant_persistant'), $html);
$this->assertTag(array('id' => 'id_advcheckboxfrozen'), $html);
$this->assertTag(array('id' => 'id_advcheckboxfrozen_persistant'), $html);
// Check text element id's.
$this->assertTag(array('id' => 'id_textpersistant'), $html);
$this->assertTag(array('id' => 'id_textpersistant_persistant'), $html);
$this->assertTag(array('id' => 'id_textnotpersistant'), $html);
$this->assertNotTag(array('id' => 'id_textnotpersistant_persistant'), $html);
$this->assertTag(array('id' => 'id_textfrozen'), $html);
$this->assertNotTag(array('id' => 'id_textfrozen_persistant'), $html);
}
}
@@ -861,3 +890,42 @@ class formslib_multiple_modgrade_form extends moodleform {
$mform->addElement('modgrade', 'grade[3]', 'Grade 3');
}
}
/**
* Used to test frozen elements get unique id attributes.
*/
class formslib_persistantrreeze_element extends moodleform {
public function definition() {
$mform = $this->_form;
// Create advanced checkbox.
// Persistant.
$advcheckboxpersistant = $mform->addElement('advcheckbox', 'advcheckboxpersistant', 'advcheckbox');
$mform->setType('advcheckboxpersistant', PARAM_BOOL);
$advcheckboxpersistant->setChecked(true);
$advcheckboxpersistant->freeze();
$advcheckboxpersistant->setPersistantFreeze(true);
// Frozen.
$advcheckboxfrozen = $mform->addElement('advcheckbox', 'advcheckboxfrozen', 'advcheckbox');
$mform->setType('advcheckboxfrozen', PARAM_BOOL);
$advcheckboxfrozen->setChecked(true);
$advcheckboxfrozen->freeze();
// Neither persistant nor Frozen.
$mform->addElement('advcheckbox', 'advcheckboxnotpersistant', 'advcheckbox');
$mform->setType('advcheckboxnotpersistant', PARAM_BOOL);
// Create text fields.
// Persistant.
$elpersistant = $mform->addElement('text', 'textpersistant', 'test', 'test');
$mform->setType('textpersistant', PARAM_TEXT);
$elpersistant->freeze();
$elpersistant->setPersistantFreeze(true);
// Frozen.
$elfrozen = $mform->addElement('text', 'textfrozen', 'test', 'test');
$mform->setType('textfrozen', PARAM_TEXT);
$elfrozen->freeze();
// Neither persistant nor Frozen.
$mform->addElement('text', 'textnotpersistant', 'test', 'test');
$mform->setType('textnotpersistant', PARAM_TEXT);
}
}
+7 -3
View File
@@ -409,24 +409,28 @@ class lesson_display_answer_form_truefalse extends moodleform {
$mform->setType('pageid', PARAM_INT);
$i = 0;
$radiobuttons = array();
foreach ($answers as $answer) {
$mform->addElement('html', '<div class="answeroption">');
$ansid = 'answerid';
if ($hasattempt) {
$ansid = 'answer_id';
}
$mform->addElement('radio', $ansid, null, format_text($answer->answer, $answer->answerformat, $options), $answer->id, $disabled);
$radiobuttons[] = $mform->createElement('radio', $ansid, null,
format_text($answer->answer, $answer->answerformat, $options), $answer->id, $disabled);
$mform->setType($ansid, PARAM_INT);
if ($hasattempt && $answer->id == $USER->modattempts[$lessonid]->answerid) {
$mform->setDefault($ansid, $attempt->answerid);
$mform->addElement('hidden', 'answerid', $answer->id);
$mform->setType('answerid', PARAM_INT);
}
$mform->addElement('html', '</div>');
$i++;
}
$radiogroup = $mform->addGroup($radiobuttons, $ansid, '', array(''), false);
$radiogroup->setAttributes(array('class' => 'answeroptiongroup'));
if ($hasattempt) {
$this->add_action_buttons(null, get_string("nextpage", "lesson"));
} else {
+13 -9
View File
@@ -26,14 +26,18 @@
.path-mod-lesson .resourcecontent {text-align: center;}
.path-mod-lesson .answeroption .fcheckbox > span,
.path-mod-lesson .answeroption .fradio > span {
.path-mod-lesson .answeroption .fcheckbox > span {
position: relative;
float: left;
}
.path-mod-lesson .answeroptiongroup .fgroup > span {
position: relative;
width: 100%;
}
.path-mod-lesson .answeroption .fcheckbox input,
.path-mod-lesson .answeroption .fradio input {
.path-mod-lesson .answeroptiongroup input {
position: absolute;
top: 2px;
margin-top: 0px;
@@ -41,28 +45,28 @@
}
.path-mod-lesson .answeroption .fcheckbox label,
.path-mod-lesson .answeroption .fradio label {
.path-mod-lesson .mform .fitem.answeroptiongroup fieldset.fgroup label {
padding-left: 20px;
float: left;
}
.path-mod-lesson .answeroption .felement label p:last-child {
.path-mod-lesson .answeroption .felement label p:last-child,
.path-mod-lesson .answeroptiongroup .felement label p:last-child {
margin-bottom: 0px;
}
.path-mod-lesson.dir-rtl .answeroption .fcheckbox > span,
.path-mod-lesson.dir-rtl .answeroption .fradio > span {
.path-mod-lesson.dir-rtl .answeroption .fcheckbox > span {
float: right;
}
.path-mod-lesson.dir-rtl .answeroption .fcheckbox input,
.path-mod-lesson.dir-rtl .answeroption .fradio input {
.path-mod-lesson.dir-rtl .answeroptiongroup .fgroup input {
left: inherit;
right: 0;
}
.path-mod-lesson.dir-rtl .answeroption .fcheckbox label,
.path-mod-lesson.dir-rtl .answeroption .fradio label {
.path-mod-lesson.dir-rtl .mform .fitem.answeroptiongroup fieldset.fgroup label {
padding-left: 0;
padding-right: 20px;
float: right;
+2 -2
View File
@@ -103,9 +103,9 @@ foreach ($users as $k => $v) {
if (!$user = $DB->get_record('user', array('id' => $v))) {
continue;
}
$checkbox = html_writer::label(get_string('selectnotestate', 'notes'), 'menustates', false, array('class' => 'accesshide'));
$checkbox = html_writer::label(get_string('selectnotestate', 'notes'), 'menustates_'.$v, false, array('class' => 'accesshide'));
$checkbox .= html_writer::select($statenames, 'states[' . $k . ']',
empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], false, array('id' => 'menustates'));
empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], false, array('id' => 'menustates_'.$v));
$table->data[] = array(
'<input type="hidden" name="userid['.$k.']" value="'.$v.'" />'. fullname($user, true),
'<textarea name="contents['. $k . ']" rows="2" cols="40" spellcheck="true">' . strip_tags(@$contents[$k]) . '</textarea>',