From b3af55b363817df5cf449ac0090cc53e68cd60a6 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Mon, 11 Mar 2013 13:09:23 +0800 Subject: [PATCH] MDL-30438 Lesson Module: improve password field to disabled when password protect is set to no. --- lib/form/passwordunmask.php | 5 ++++- lib/form/yui/passwordunmask/passwordunmask.js | 7 ++++--- mod/lesson/mod_form.php | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/form/passwordunmask.php b/lib/form/passwordunmask.php index bd256fcf123..15bd4bc35d2 100644 --- a/lib/form/passwordunmask.php +++ b/lib/form/passwordunmask.php @@ -80,8 +80,11 @@ class MoodleQuickForm_passwordunmask extends MoodleQuickForm_password { } else { $unmask = get_string('unmaskpassword', 'form'); //Pass id of the element, so that unmask checkbox can be attached. + $attributes = array('formid' => $this->getAttribute('id'), + 'checkboxlabel' => $unmask, + 'checkboxname' => $this->getAttribute('name')); $PAGE->requires->yui_module('moodle-form-passwordunmask', 'M.form.passwordunmask', - array(array('formid' => $this->getAttribute('id'), 'checkboxname' => $unmask))); + array($attributes)); return $this->_getTabs() . '_getAttrString($this->_attributes) . ' />'; } } diff --git a/lib/form/yui/passwordunmask/passwordunmask.js b/lib/form/yui/passwordunmask/passwordunmask.js index dfe4de4b472..1bbefccdc8c 100644 --- a/lib/form/yui/passwordunmask/passwordunmask.js +++ b/lib/form/yui/passwordunmask/passwordunmask.js @@ -7,18 +7,19 @@ YUI.add('moodle-form-passwordunmask', function(Y) { //Initialize checkbox if id is passed initializer : function(params) { if (params && params.formid) { - this.add_checkbox(params.formid, params.checkboxname); + this.add_checkbox(params.formid, params.checkboxlabel, params.checkboxname); } }, //Create checkbox for unmasking password - add_checkbox : function(elementid, checkboxlabel) { + add_checkbox : function(elementid, checkboxlabel, checkboxname) { var node = Y.one('#'+elementid); //retaining unmask div from previous implementation. var unmaskdiv = Y.Node.create('
'); //Add checkbox for unmasking to unmaskdiv - var unmaskchb = Y.Node.create(''); + var unmaskchb = Y.Node.create(''); unmaskdiv.appendChild(unmaskchb); //Attach event using static javascript function for unmasking password. unmaskchb.on('click', function() {unmaskPassword(elementid);}); diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index 9e88c584d69..7f82372b8fd 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -133,6 +133,7 @@ class mod_lesson_mod_form extends moodleform_mod { $mform->setType('password', PARAM_RAW); $mform->setAdvanced('password'); $mform->disabledIf('password', 'usepassword', 'eq', 0); + $mform->disabledIf('passwordunmask', 'usepassword', 'eq', 0); $this->standard_grading_coursemodule_elements();