From 5f040a5ac885778aaf0ffeb9e392e15040e17a9d Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 24 Nov 2020 01:02:50 +0800 Subject: [PATCH 1/3] MDL-69422 core: Convert required and help button container to div * A span element cannot have a div as a child. --- lib/form/templates/element-advcheckbox.mustache | 4 ++-- lib/form/templates/element-checkbox.mustache | 4 ++-- lib/form/templates/element-radio.mustache | 4 ++-- lib/form/templates/element-template.mustache | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/form/templates/element-advcheckbox.mustache b/lib/form/templates/element-advcheckbox.mustache index d64ad69daf5..7524c003eb2 100644 --- a/lib/form/templates/element-advcheckbox.mustache +++ b/lib/form/templates/element-advcheckbox.mustache @@ -38,14 +38,14 @@ {{{label}}} {{/text}} - +
{{#required}}
{{#pix}}req, core, {{#str}}required{{/str}}{{/pix}}
{{/required}} {{{helpbutton}}} - +
{{$ element }} From b92ff2923c0ede041c927af4cf7c62d87b32a71c Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 23 Nov 2020 21:34:49 +0800 Subject: [PATCH 2/3] MDL-69422 mod_data: Export form accessibility fixes * Set appropriate heading element IDs * Replace usages of deprecated HTML tag acronym with abbr instead. * Add a label for the export fields fieldset. * Move the CSV delimiter list outside the radio group. * Fix div under a label element and duplicate labels for the checkboxes of the fields to be exported by showing the field name and type together. * Group the fields to be exported as a fieldset. * Move unsupported fields into a separate list. * Move export options into its own section and group the options as a fieldset. --- mod/data/export_form.php | 82 +++++++++++++++++++++++++-------------- mod/data/lang/en/data.php | 15 +++++-- 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/mod/data/export_form.php b/mod/data/export_form.php index edf9986165d..75f27f4b5d2 100644 --- a/mod/data/export_form.php +++ b/mod/data/export_form.php @@ -31,25 +31,31 @@ class mod_data_export_form extends moodleform { } function definition() { - global $CFG; $mform =& $this->_form; - $mform->addElement('header', 'notice', get_string('chooseexportformat', 'data')); - $choices = csv_import_reader::get_delimiter_list(); - $key = array_search(';', $choices); - if (! $key === FALSE) { - // array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon): - unset($choices[$key]); - } + $mform->addElement('header', 'exportformat', get_string('chooseexportformat', 'data')); + + $optionattrs = ['class' => 'mt-1 mb-1']; + + // Export format type radio group. $typesarray = array(); - $str = get_string('csvwithselecteddelimiter', 'data'); - $typesarray[] = $mform->createElement('radio', 'exporttype', null, $str . ' ', 'csv'); - $typesarray[] = $mform->createElement('select', 'delimiter_name', null, $choices); - //temporarily commenting out Excel export option. See MDL-19864 + $typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data'), 'csv', + $optionattrs); + // Temporarily commenting out Excel export option. See MDL-19864. //$typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls'); - $typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods'); - $mform->addGroup($typesarray, 'exportar', '', array(''), false); + $typesarray[] = $mform->createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods', $optionattrs); + $mform->addGroup($typesarray, 'exportar', get_string('exportformat', 'data'), null, false); $mform->addRule('exportar', null, 'required'); $mform->setDefault('exporttype', 'csv'); + + // CSV delimiter list. + $choices = csv_import_reader::get_delimiter_list(); + $key = array_search(';', $choices); + if ($key !== false) { + // Array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon): + unset($choices[$key]); + } + $mform->addElement('select', 'delimiter_name', get_string('fielddelimiter', 'data'), $choices); + $mform->hideIf('delimiter_name', 'exporttype', 'neq', 'csv'); if (array_key_exists('cfg', $choices)) { $mform->setDefault('delimiter_name', 'cfg'); } else if (get_string('listsep', 'langconfig') == ';') { @@ -57,38 +63,56 @@ class mod_data_export_form extends moodleform { } else { $mform->setDefault('delimiter_name', 'comma'); } - $mform->addElement('header', 'notice', get_string('chooseexportfields', 'data')); + + // Fields to be exported. + $mform->addElement('header', 'exportfieldsheader', get_string('chooseexportfields', 'data')); + $mform->setExpanded('exportfieldsheader'); $numfieldsthatcanbeselected = 0; - foreach($this->_datafields as $field) { - if($field->text_export_supported()) { + $exportfields = []; + $unsupportedfields = []; + foreach ($this->_datafields as $field) { + $label = get_string('fieldnametype', 'data', (object)['name' => $field->field->name, 'type' => $field->name()]); + if ($field->text_export_supported()) { $numfieldsthatcanbeselected++; - $html = '
' . $field->field->name . '
'; - $name = ' (' . $field->name() . ')'; - $mform->addElement('advcheckbox', 'field_' . $field->field->id, $html, $name, array('group' => 1)); + $exportfields[] = $mform->createElement('advcheckbox', 'field_' . $field->field->id, '', $label, + array_merge(['group' => 1], $optionattrs)); $mform->setDefault('field_' . $field->field->id, 1); } else { - $a = new stdClass(); - $a->fieldtype = $field->name(); - $str = get_string('unsupportedexport', 'data', $a); - $mform->addElement('static', 'unsupported' . $field->field->id, $field->field->name, $str); + $unsupportedfields[] = $label; } } + $mform->addGroup($exportfields, 'exportfields', get_string('selectfields', 'data'), ['
'], false); + if ($numfieldsthatcanbeselected > 1) { $this->add_checkbox_controller(1, null, null, 1); } + + // List fields that cannot be exported. + if (!empty($unsupportedfields)) { + $unsupportedfieldslist = html_writer::tag('p', get_string('unsupportedfieldslist', 'data'), ['class' => 'mt-1']); + $unsupportedfieldslist .= html_writer::alist($unsupportedfields); + $mform->addElement('static', 'unsupportedfields', get_string('unsupportedfields', 'data'), $unsupportedfieldslist); + } + + // Export options. + $mform->addElement('header', 'exportoptionsheader', get_string('exportoptions', 'data')); + $mform->setExpanded('exportoptionsheader'); + $exportoptions = []; if (core_tag_tag::is_enabled('mod_data', 'data_records')) { - $mform->addElement('checkbox', 'exporttags', get_string('includetags', 'data')); + $exportoptions[] = $mform->createElement('checkbox', 'exporttags', get_string('includetags', 'data'), '', $optionattrs); $mform->setDefault('exporttags', 1); } $context = context_module::instance($this->_cm->id); if (has_capability('mod/data:exportuserinfo', $context)) { - $mform->addElement('checkbox', 'exportuser', get_string('includeuserdetails', 'data')); + $exportoptions[] = $mform->createElement('checkbox', 'exportuser', get_string('includeuserdetails', 'data'), '', + $optionattrs); } - $mform->addElement('checkbox', 'exporttime', get_string('includetime', 'data')); + $exportoptions[] = $mform->createElement('checkbox', 'exporttime', get_string('includetime', 'data'), '', $optionattrs); if ($this->_data->approval) { - $mform->addElement('checkbox', 'exportapproval', get_string('includeapproval', 'data')); + $exportoptions[] = $mform->createElement('checkbox', 'exportapproval', get_string('includeapproval', 'data'), '', + $optionattrs); } + $mform->addGroup($exportoptions, 'exportoptions', get_string('selectexportoptions', 'data'), ['
'], false); $this->add_action_buttons(true, get_string('exportentries', 'data')); } diff --git a/mod/data/lang/en/data.php b/mod/data/lang/en/data.php index d96f7f5fa2c..a49ca728e0d 100644 --- a/mod/data/lang/en/data.php +++ b/mod/data/lang/en/data.php @@ -83,7 +83,7 @@ $string['csvfailed'] = 'Unable to read the raw data from the CSV file'; $string['csvfile'] = 'CSV file'; $string['csvimport'] = 'CSV file import'; $string['csvimport_help'] = 'Entries may be imported via a plain text file with a list of field names as the first line, then the data, with one record per line.'; -$string['csvwithselecteddelimiter'] = 'CSV text with selected delimiter:'; +$string['csvwithselecteddelimiter'] = 'CSV'; $string['data:addinstance'] = 'Add a new database'; $string['data:approve'] = 'Approve and undo approved entries'; $string['data:comment'] = 'Write comments'; @@ -153,6 +153,8 @@ $string['exportaszip'] = 'Export as zip'; $string['exportaszip_help'] = 'The export as zip feature allows you to save the templates and fields as a preset zip for download. The zip may then be imported to another course.'; $string['exportedtozip'] = 'Exported to temporary zip...'; $string['exportentries'] = 'Export entries'; +$string['exportformat'] = 'Export format'; +$string['exportoptions'] = 'Export options'; $string['exportownentries'] = 'Export your own entries only? ({$a->mine}/{$a->all})'; $string['failedpresetdelete'] = 'Error deleting a preset!'; $string['fieldadded'] = 'Field added'; @@ -169,6 +171,7 @@ $string['fieldmappings'] = 'Field mappings'; $string['fieldmappings_help'] = 'This menu allows you to keep the data from the existing database. To preserve the data in a field, you must map it to a new field, where the data will appear. Any field can also be left blank, with no information copied into it. Any old field not mapped to a new one will be lost and all its data removed. You can only map fields of the same type, so each drop-down menu will have different fields in it. Also, you must be careful not to try and map one old field to more than one new field.'; $string['fieldname'] = 'Field name'; +$string['fieldnametype'] = '{$a->name} ({$a->type})'; $string['fieldnotmatched'] = 'The following fields in your file are not known in this database: {$a}'; $string['fieldoptions'] = 'Options (one per line)'; $string['fields'] = 'Fields'; @@ -195,8 +198,8 @@ $string['headerlisttemplate'] = 'Defines browsing interface for multiple entries $string['headerrsstemplate'] = 'Defines appearance of entries in RSS feeds'; $string['headersingletemplate'] = 'Defines browsing interface for a single entry'; $string['checkbox'] = 'Checkbox'; -$string['chooseexportfields'] = 'Choose the fields you wish to export:'; -$string['chooseexportformat'] = 'Choose the format you wish to export to:'; +$string['chooseexportfields'] = 'Choose the fields you wish to export'; +$string['chooseexportformat'] = 'Choose the format you wish to export to'; $string['chooseorupload'] = 'Choose file'; $string['expired'] = 'Sorry, this activity closed on {$a} and is no longer available'; $string['importentries'] = 'Import entries'; @@ -290,7 +293,7 @@ $string['number'] = 'Number'; $string['numberrssarticles'] = 'Entries in the RSS feed'; $string['numnotapproved'] = 'Pending'; $string['numrecords'] = '{$a} entries'; -$string['ods'] = 'ODS (OpenOffice)'; +$string['ods'] = 'ODS (OpenOffice)'; $string['openafterclose'] = 'You have specified an open date after the close date'; $string['optionaldescription'] = 'Short description (optional)'; $string['optionalfilename'] = 'Filename (optional)'; @@ -366,6 +369,8 @@ $string['search'] = 'Search'; $string['search:activity'] = 'Database - activity information'; $string['search:entry'] = 'Database - entries'; $string['selectedrequired'] = 'All selected required'; +$string['selectfields'] = 'Select fields'; +$string['selectexportoptions'] = 'Select export options'; $string['showall'] = 'Show all entries'; $string['single'] = 'View single'; $string['singletemplate'] = 'Single template'; @@ -387,6 +392,8 @@ $string['todatabase'] = 'to this database.'; $string['type'] = 'Field type'; $string['undefinedprocessactionmethod'] = 'No action method defined in Data_Preset to handle action "{$a}".'; $string['unsupportedexport'] = '({$a->fieldtype}) cannot be exported.'; +$string['unsupportedfields'] = 'Unsupported fields'; +$string['unsupportedfieldslist'] = 'The following fields cannot be exported:'; $string['updatefield'] = 'Update an existing field'; $string['uploadfile'] = 'Upload file'; $string['uploadrecords'] = 'Upload entries from a file'; From 0f05c1dc0b8fb8cba65dd0d309df0d7146752bd8 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Fri, 27 Nov 2020 23:27:33 +0800 Subject: [PATCH 3/3] MDL-69422 mod_data: Deprecate unused 'unsupportedexport' string --- mod/data/lang/en/data.php | 4 +++- mod/data/lang/en/deprecated.txt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mod/data/lang/en/data.php b/mod/data/lang/en/data.php index a49ca728e0d..1c5be548e94 100644 --- a/mod/data/lang/en/data.php +++ b/mod/data/lang/en/data.php @@ -391,7 +391,6 @@ $string['timemodified'] = 'Time modified'; $string['todatabase'] = 'to this database.'; $string['type'] = 'Field type'; $string['undefinedprocessactionmethod'] = 'No action method defined in Data_Preset to handle action "{$a}".'; -$string['unsupportedexport'] = '({$a->fieldtype}) cannot be exported.'; $string['unsupportedfields'] = 'Unsupported fields'; $string['unsupportedfieldslist'] = 'The following fields cannot be exported:'; $string['updatefield'] = 'Update an existing field'; @@ -413,3 +412,6 @@ $string['viewfromdate'] = 'Read only from'; $string['viewtodate'] = 'Read only to'; $string['viewtodatevalidation'] = 'The read only to date cannot be before the read only from date.'; $string['wrongdataid'] = 'Wrong data id provided'; + +// Deprecated since Moodle 3.11. +$string['unsupportedexport'] = '({$a->fieldtype}) cannot be exported.'; diff --git a/mod/data/lang/en/deprecated.txt b/mod/data/lang/en/deprecated.txt index e69de29bb2d..0c6891c2960 100644 --- a/mod/data/lang/en/deprecated.txt +++ b/mod/data/lang/en/deprecated.txt @@ -0,0 +1 @@ +unsupportedexport,mod_data