Files
moodle/mod/data/preset_form.php
T
Sara Arjona aecb87f53e MDL-75142 mod_data: Add description to presets
This commit adds support to description field for presets:
- For plugin presets, description will be stored in the module_help
string in lang files.
- For saved presets, a new element, <description>, has been added
to the preset.xml file, to include this information.

A new field has been added to the "Save as preset" modal, to let users
define description (which is empty by default, to support pre-existing
presets that won't have it).

Apart from that, the "Save as preset" workflow has been slightly improved,
following the Product UX/UX suggestions to hide the checkbox to overwrite
the preset by default and show it only if the user tries to save a preset
with an existing name.
2022-08-05 14:51:49 +02:00

73 lines
3.3 KiB
PHP

<?php
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden!');
}
require_once($CFG->libdir . '/formslib.php');
class data_existing_preset_form extends moodleform {
public function definition() {
$this->_form->addElement('header', 'presets', get_string('usestandard', 'data'));
$this->_form->addHelpButton('presets', 'usestandard', 'data');
$this->_form->addElement('hidden', 'd');
$this->_form->setType('d', PARAM_INT);
$this->_form->addElement('hidden', 'action', 'confirmdelete');
$this->_form->setType('action', PARAM_ALPHANUM);
$delete = get_string('delete');
foreach ($this->_customdata['presets'] as $preset) {
$userid = $preset instanceof \mod_data\preset ? $preset->get_userid() : $preset->userid;
$this->_form->addElement('radio', 'fullname', null, ' '.$preset->description, $userid.'/'.$preset->shortname);
}
$this->_form->addElement('submit', 'importexisting', get_string('choose'));
}
}
class data_import_preset_zip_form extends moodleform {
public function definition() {
$this->_form->addElement('header', 'uploadpreset', get_string('fromfile', 'data'));
$this->_form->addHelpButton('uploadpreset', 'fromfile', 'data');
$this->_form->addElement('hidden', 'd');
$this->_form->setType('d', PARAM_INT);
$this->_form->addElement('hidden', 'mode', 'import');
$this->_form->setType('mode', PARAM_ALPHANUM);
$this->_form->addElement('hidden', 'action', 'importzip');
$this->_form->setType('action', PARAM_ALPHANUM);
$this->_form->addElement('filepicker', 'importfile', get_string('chooseorupload', 'data'));
$this->_form->addRule('importfile', null, 'required');
$buttons = [
$this->_form->createElement('submit', 'submitbutton', get_string('save')),
$this->_form->createElement('cancel'),
];
$this->_form->addGroup($buttons, 'buttonar', '', [' '], false);
}
}
class data_export_form extends moodleform {
public function definition() {
$this->_form->addElement('header', 'exportheading', get_string('exportaszip', 'data'));
$this->_form->addElement('hidden', 'd');
$this->_form->setType('d', PARAM_INT);
$this->_form->addElement('hidden', 'action', 'export');
$this->_form->setType('action', PARAM_ALPHANUM);
$this->_form->addElement('submit', 'export', get_string('export', 'data'));
}
}
class data_save_preset_form extends moodleform {
public function definition() {
$this->_form->addElement('header', 'exportheading', get_string('saveaspreset', 'data'));
$this->_form->addElement('hidden', 'd');
$this->_form->setType('d', PARAM_INT);
$this->_form->addElement('hidden', 'action', 'save2');
$this->_form->setType('action', PARAM_ALPHANUM);
$this->_form->addElement('text', 'name', get_string('name'));
$this->_form->setType('name', PARAM_FILE);
$this->_form->addRule('name', null, 'required');
$this->_form->addElement('checkbox', 'overwrite', get_string('overwrite', 'data'), get_string('overrwritedesc', 'data'));
$this->_form->addElement('submit', 'saveaspreset', get_string('continue'));
}
}