Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'wip-mdl-50484' of https://github.com/rajeshtaneja/moodle
  • Loading branch information
andrewnicols committed Feb 22, 2016
2 parents 83a9510 + 660b0f0 commit ea65e55
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 31 deletions.
15 changes: 7 additions & 8 deletions admin/roles/classes/capability_table_with_risks.php
Expand Up @@ -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;
Expand Down Expand Up @@ -183,12 +182,12 @@ protected function add_row_cells($capability) {
*/
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;
}
}
3 changes: 2 additions & 1 deletion blocks/navigation/renderer.php
Expand Up @@ -70,7 +70,8 @@ protected function navigation_node($items, $attrs=array(), $expansionlimit=null,

// 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()) {
Expand Down
4 changes: 4 additions & 0 deletions grade/grading/form/rubric/renderer.php
Expand Up @@ -450,6 +450,8 @@ protected function rubric_edit_options($mode, $options) {
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
Expand All @@ -461,6 +463,8 @@ protected function rubric_edit_options($mode, $options) {
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']));
Expand Down
5 changes: 3 additions & 2 deletions grade/report/grader/lib.php
Expand Up @@ -1603,8 +1603,9 @@ protected function get_course_header($element) {
}

$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;
Expand Down
1 change: 0 additions & 1 deletion lib/form/advcheckbox.php
Expand Up @@ -130,5 +130,4 @@ function getFrozenHtml()
}
return $output;
}

}
1 change: 0 additions & 1 deletion lib/form/text.php
Expand Up @@ -124,5 +124,4 @@ function toHtml(){
function getHelpButton(){
return $this->_helpbutton;
}

}
2 changes: 1 addition & 1 deletion lib/form/url.php
Expand Up @@ -119,7 +119,7 @@ function toHtml(){
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;
Expand Down
3 changes: 2 additions & 1 deletion lib/formslib.php
Expand Up @@ -2651,7 +2651,7 @@ public function __construct() {

'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>',

Expand Down Expand Up @@ -2766,6 +2766,7 @@ function startGroup(&$group, $required, $error){
$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';
Expand Down
11 changes: 9 additions & 2 deletions lib/pear/HTML/QuickForm/element.php
Expand Up @@ -254,11 +254,18 @@ function _getPersistantData()
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) . ' />';
}
}

Expand Down Expand Up @@ -486,4 +493,4 @@ function _prepareValue($value, $assoc)

// }}}
} // end class HTML_QuickForm_element
?>
?>
1 change: 1 addition & 0 deletions lib/pear/README_MOODLE.txt
Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions lib/tests/formslib_test.php
Expand Up @@ -577,6 +577,35 @@ public function test_multiple_modgrade_fields() {
$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);

}
}


Expand Down Expand Up @@ -861,3 +890,42 @@ public function definition() {
$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);
}
}
10 changes: 7 additions & 3 deletions mod/lesson/pagetypes/truefalse.php
Expand Up @@ -409,24 +409,28 @@ public function definition() {
$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 {
Expand Down
22 changes: 13 additions & 9 deletions mod/lesson/styles.css
Expand Up @@ -26,43 +26,47 @@

.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;
left: 0;
}

.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;
Expand Down
4 changes: 2 additions & 2 deletions user/addnote.php
Expand Up @@ -103,9 +103,9 @@
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>',
Expand Down

0 comments on commit ea65e55

Please sign in to comment.