Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 69116fcd authored by Francois Gannaz's avatar Francois Gannaz
Browse files

Fix the mission_id filtering by mod_form

parent 7096be11
<?php
/**
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @package mod_labnbook
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_labnbook\form;
require_once $CFG->libdir . '/formslib.php';
require_once $CFG->libdir . '/form/select.php';
/**
* select_dynamic differs from Moodle's select by not filtering the value.
* So this select options do not have to be declared in the PHP model,
* one can add them dynamically.
*/
class select_dynamic extends \MoodleQuickForm_select
{
/**
* Overrides the filtering method.
*
* @param array $submitValues submitted values
* @param bool $assoc if true the returned value is an assoc array
* @return string|array
*/
function exportValue(&$submitValues, $assoc = false)
{
if (empty($this->_options)) {
return $this->_prepareValue(null, $assoc);
}
$value = $this->_findValue($submitValues);
if (is_null($value)) {
$value = $this->getValue();
}
if ($this->getMultiple()) {
return $this->_prepareValue((array) $value, $assoc);
} else {
return $this->_prepareValue(is_array($value) ? $value[0] : $value, $assoc);
}
}
}
......@@ -9,6 +9,7 @@
*/
use \mod_labnbook\fetch;
use \mod_labnbook\form\select_dynamic;
defined('MOODLE_INTERNAL') || die();
......@@ -27,7 +28,7 @@ define('TEAMCONFIG_METHOD_RANDOM', 3);
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_labnbook_mod_form extends moodleform_mod {
class mod_labnbook_mod_form extends \moodleform_mod {
/**
* Defines forms elements
......@@ -38,11 +39,10 @@ class mod_labnbook_mod_form extends moodleform_mod {
$mform = $this->_form;
$mform->addElement('header', 'external', "LabNbook");
$mform->addElement(
'select',
$dynamicSelect = new select_dynamic(
'labnbook_missionid',
get_string('mission', 'mod_labnbook'),
['' => "-"],
['0' => "-"],
[
'onchange' => 'javascript: '
. 'document.querySelector("#id_name").value = getMission(this.value).name;'
......@@ -50,8 +50,10 @@ class mod_labnbook_mod_form extends moodleform_mod {
. 'document.querySelector("#id_introeditoreditable").innerHTML = getMission(this.value).description;'
. 'document.querySelector("#id_introeditor").innerHTML = getMission(this.value).description;'
// TODO update the TinyMCE text. Is there a way to detect the editor plugin? A common API for pluggable editors?
]
]
);
$mform->addElement($dynamicSelect);
$mform->setType('labnbook_missionid', PARAM_INT);
$mform->addRule('labnbook_missionid', null, 'required', null, 'client');
$fetchMissions = (new fetch\user)->getJsMissions();
......@@ -68,7 +70,7 @@ function refreshMissions() {
return;
}
refreshLock = 1;
var container = document.querySelector('#id_labnbook_missionid');
var container = document.querySelector('select[name="labnbook_missionid"]');
var loading = document.createElement('span');
loading.setAttribute('class', 'fa fa-spinner fa-pulse fa-fw');
......@@ -79,7 +81,7 @@ function refreshMissions() {
refreshLock = 0;
document.querySelector('#labnbook-missions-loading').remove();
container.innerHTML = '<option value="">-</option>';
container.innerHTML = '<option value="0">-</option>';
for (m of missions) {
labnbookMissions.set(m.id_mission, m);
var e = document.createElement('option');
......@@ -139,6 +141,7 @@ EOJS
];
$mform->addElement('select', 'method', get_string('method', 'mod_labnbook'), $options);
$mform->addHelpButton('method', 'method', 'mod_labnbook');
$mform->setType('method', PARAM_INT);
$mform->addRule("method", null, 'required', null, 'client');
$this->addInputInt('teams_max', true);
......@@ -171,7 +174,16 @@ EOJS
function definition_after_data() {
parent::definition_after_data();
if ($this->_form->getElementValue('update')) {
$this->_form->freeze('labnbook_missionid');
//$this->_form->freeze('labnbook_missionid');
}
}
public function data_postprocessing($data) {
if (empty($data->size_min)) {
$data->size_min = 1;
}
if (empty($data->size_max)) {
$data->size_max = $data->size_opt + 1;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment