Skip to content

Commit

Permalink
Merge branch 'MDL-68353-master' of git://github.com/rezaies/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed May 29, 2020
2 parents 2e324c1 + dce43c7 commit 96dc92f
Show file tree
Hide file tree
Showing 27 changed files with 151 additions and 59 deletions.
44 changes: 35 additions & 9 deletions admin/templates/setting.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,28 @@
}}
<div class="form-item row" id="{{id}}">
<div class="form-label col-sm-3 text-sm-right">
<label {{#labelfor}}for="{{labelfor}}"{{/labelfor}}>
{{{title}}}
{{#override}}
<div class="alert alert-info">{{override}}</div>
{{/override}}
{{#warning}}
<div class="alert alert-warning">{{warning}}</div>
{{/warning}}
</label>
{{#customcontrol}}
<p {{#labelfor}}id="{{labelfor}}_label"{{/labelfor}}>
{{{title}}}
{{#override}}
<div class="alert alert-info">{{override}}</div>
{{/override}}
{{#warning}}
<div class="alert alert-warning">{{warning}}</div>
{{/warning}}
</p>
{{/customcontrol}}
{{^customcontrol}}
<label {{#labelfor}}for="{{labelfor}}"{{/labelfor}}>
{{{title}}}
{{#override}}
<div class="alert alert-info">{{override}}</div>
{{/override}}
{{#warning}}
<div class="alert alert-warning">{{warning}}</div>
{{/warning}}
</label>
{{/customcontrol}}
<span class="form-shortname d-block small text-muted">{{{name}}}</span>
</div>
<div class="form-setting col-sm-9">
Expand All @@ -72,3 +85,16 @@
{{#dependenton}}<div class="form-dependenton mb-4 text-muted">{{{.}}}</div>{{/dependenton}}
</div>
</div>
{{#customcontrol}}
{{#js}}
require(['jquery'], function($) {
$('#{{id}}_label').css('cursor', 'default');
$('#{{id}}_label').click(function() {
$('#{{id}}')
.find('button, a, input:not([type="hidden"]), select, textarea, [tabindex]')
.filter(':not([disabled]):not([tabindex="0"]):not([tabindex="-1"])')
.first().focus();
});
});
{{/js}}
{{/customcontrol}}
14 changes: 14 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,8 @@ abstract class admin_setting {
private $forceltr = null;
/** @var array list of other settings that may cause this setting to be hidden */
private $dependenton = [];
/** @var bool Whether this setting uses a custom form control */
protected $customcontrol = false;

/**
* Constructor
Expand Down Expand Up @@ -2081,6 +2083,16 @@ public function add_dependent_on($dependenton) {
public function get_dependent_on() {
return $this->dependenton;
}

/**
* Whether this setting uses a custom form control.
* This function is especially useful to decide if we should render a label element for this setting or not.
*
* @return bool
*/
public function has_custom_form_control(): bool {
return $this->customcontrol;
}
}

/**
Expand Down Expand Up @@ -8925,6 +8937,7 @@ function format_admin_setting($setting, $title='', $form='', $description='', $l
$context->description = highlight($query, markdown_to_html($description));
$context->element = $form;
$context->forceltr = $setting->get_force_ltr();
$context->customcontrol = $setting->has_custom_form_control();

return $OUTPUT->render_from_template('core_admin/setting', $context);
}
Expand Down Expand Up @@ -10384,6 +10397,7 @@ public function __construct($name, $visiblename, $description, $filearea, $itemi
$this->filearea = $filearea;
$this->itemid = $itemid;
$this->options = (array)$options;
$this->customcontrol = true;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/behat/classes/partial_named_selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ public function __construct() {
.//*[contains(., %locator%) and not(.//*[contains(., %locator%)])]
XPATH
, 'form_row' => <<<XPATH
.//*[self::label or self::div[contains(concat(' ', @class, ' '), ' fstaticlabel ')]][contains(., %locator%)]/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]
.//*[contains(concat(' ', @class, ' '), ' col-form-label ')]
[normalize-space(.)= %locator%]
/ancestor::*[contains(concat(' ', @class, ' '), ' fitem ')]
XPATH
, 'autocomplete_selection' => <<<XPATH
.//div[contains(concat(' ', normalize-space(@class), ' '), concat(' ', 'form-autocomplete-selection', ' '))]/span[@role='listitem'][contains(normalize-space(.), %locator%)]
Expand Down Expand Up @@ -253,7 +255,7 @@ public function __construct() {
,
'filemanager' => <<<XPATH
.//*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']
/descendant::input[@id = //label[contains(normalize-space(string(.)), %locator%)]/@for]
/descendant::input[@id = substring-before(//p[contains(normalize-space(string(.)), %locator%)]/@id, '_label')]
XPATH
,
'passwordunmask' => <<<XPATH
Expand Down
2 changes: 1 addition & 1 deletion lib/behat/core_behat_file_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function get_filepicker_node($filepickerelement) {
$filepickerelement = behat_context_helper::escape($filepickerelement);
$filepickercontainer = $this->find(
'xpath',
"//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" .
"//input[./@id = substring-before(//p[normalize-space(.)=$filepickerelement]/@id, '_label')]" .
"//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']",
$exception
);
Expand Down
2 changes: 1 addition & 1 deletion lib/behat/form_field/behat_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected function get_field_locator($locatortype = false) {
// Defaults to label.
if ($locatortype == 'label' || $locatortype == false) {

$labelnode = $this->session->getPage()->find('xpath', '//label[@for="' . $fieldid . '"]');
$labelnode = $this->session->getPage()->find('xpath', "//label[@for='$fieldid']|//p[@id='{$fieldid}_label']");

// Exception only if $locatortype was specified.
if (!$labelnode && $locatortype == 'label') {
Expand Down
2 changes: 1 addition & 1 deletion lib/behat/form_field/behat_form_filemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function get_value() {
$fieldlabel = $this->get_field_locator();

// Get the name of the current directory elements.
$xpath = "//label[contains(., '" . $fieldlabel . "')]" .
$xpath = "//p[normalize-space(.)='$fieldlabel']" .
"/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' fitem ')]" .
"/descendant::div[@data-fieldtype = 'filemanager']" .
"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-filename ')]";
Expand Down
1 change: 0 additions & 1 deletion lib/form/templates/element-advcheckbox-inline.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
value="{{element.selectedvalue}}"
{{/element.selectedvalue}}
{{#element.checked}}checked{{/element.checked}}
size="{{element.size}}"
{{#error}}
autofocus aria-describedby="{{element.iderror}}"
{{/error}}
Expand Down
1 change: 0 additions & 1 deletion lib/form/templates/element-checkbox-inline.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
value="1"
{{/element.value}}
{{#element.checked}}checked{{/element.checked}}
size="{{element.size}}"
{{#error}}
autofocus aria-describedby="{{element.iderror}}"
{{/error}}
Expand Down
23 changes: 22 additions & 1 deletion lib/form/templates/element-filemanager.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
{{< core_form/element-template }}
{{$label}}
{{^element.hiddenlabel}}
<p id="{{element.id}}_label" class="col-form-label d-inline" aria-hidden="true">
{{{label}}}
</p>
{{/element.hiddenlabel}}
{{/label}}
{{$element}}
{{{element.html}}}
<fieldset class="w-100 m-0 p-0 border-0" id="{{element.id}}_fieldset">
<legend class="sr-only">{{label}}</legend>
{{{element.html}}}
</fieldset>
{{/element}}
{{/ core_form/element-template }}
{{#js}}
(function() {
var label = document.getElementById('{{element.id}}_label');
if (label) {
label.style.cursor = 'default';
label.addEventListener('click', function() {
document.querySelectorAll('#{{element.id}}_fieldset div.fp-toolbar a')[0].focus();
});
}
})();
{{/js}}
23 changes: 22 additions & 1 deletion lib/form/templates/element-filepicker.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
{{< core_form/element-template }}
{{$label}}
{{^element.hiddenlabel}}
<p id="{{element.id}}_label" class="col-form-label d-inline" aria-hidden="true">
{{{label}}}
</p>
{{/element.hiddenlabel}}
{{/label}}
{{$element}}
{{{element.html}}}
<fieldset class="w-100 m-0 p-0 border-0" id="{{element.id}}_fieldset">
<legend class="sr-only">{{label}}</legend>
{{{element.html}}}
</fieldset>
{{/element}}
{{/ core_form/element-template }}
{{#js}}
(function() {
var label = document.getElementById('{{element.id}}_label');
if (label) {
label.style.cursor = 'default';
label.addEventListener('click', function() {
document.querySelectorAll('#{{element.id}}_fieldset .fp-btn-choose')[0].focus();
});
}
})();
{{/js}}
5 changes: 4 additions & 1 deletion lib/form/templates/element-group.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
require(['jquery'], function($) {
$('#{{element.id}}_label').css('cursor', 'default');
$('#{{element.id}}_label').click(function() {
$('#{{element.id}}').find('button, a, input, select, textarea, [tabindex]:not([tabindex="-1"])').filter(':enabled').first().focus();
$('#{{element.id}}')
.find('button, a, input:not([type="hidden"]), select, textarea, [tabindex]')
.filter(':not([disabled]):not([tabindex="0"]):not([tabindex="-1"])')
.first().focus();
});
});
{{/js}}
2 changes: 1 addition & 1 deletion lib/form/templates/element-password-inline.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
name="{{element.name}}"
id="{{element.id}}"
value="{{element.value}}"
size="{{element.size}}"
{{#element.size}}size="{{element.size}}"{{/element.size}}
{{#error}}
autofocus aria-describedby="{{element.iderror}}"
{{/error}} {{{element.attributes}}}>
Expand Down
2 changes: 1 addition & 1 deletion lib/form/templates/element-password.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
name="{{element.name}}"
id="{{element.id}}"
value="{{element.value}}"
size="{{element.size}}"
{{#element.size}}size="{{element.size}}"{{/element.size}}
{{#error}}
autofocus aria-describedby="{{element.iderror}}"
{{/error}} {{{element.attributes}}}>
Expand Down
4 changes: 2 additions & 2 deletions lib/form/templates/element-template.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{{#advanced}}<abbr class="initialism text-info" title="{{#str}}advanced{{/str}}">!</abbr>{{/advanced}}
{{{helpbutton}}}
</span>
{{$ label }}
{{# label}}{{$ label }}
{{^element.staticlabel}}
<label class="col-form-label d-inline {{#element.hiddenlabel}}sr-only{{/element.hiddenlabel}}" for="{{element.id}}">
{{{label}}}
Expand All @@ -60,7 +60,7 @@
{{{label}}}
</span>
{{/element.staticlabel}}
{{/ label }}
{{/ label }}{{/ label}}
</div>
<div class="col-md-9 form-inline felement" data-fieldtype="{{element.type}}">
{{$ element }}
Expand Down
2 changes: 1 addition & 1 deletion lib/form/templates/element-text-inline.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
readonly {{#element.hardfrozen}}disabled{{/element.hardfrozen}}
{{/element.frozen}}
value="{{element.value}}"
size="{{element.size}}"
{{#element.size}}size="{{element.size}}"{{/element.size}}
{{#error}}
autofocus aria-describedby="{{element.iderror}}"
{{/error}}
Expand Down
2 changes: 1 addition & 1 deletion lib/form/templates/element-text.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{/element.frozen}}
id="{{element.id}}"
value="{{element.value}}"
size="{{element.size}}"
{{#element.size}}size="{{element.size}}"{{/element.size}}
{{#error}}
autofocus aria-describedby="{{element.iderror}}"
{{/error}}
Expand Down
2 changes: 1 addition & 1 deletion lib/form/templates/element-url.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name="{{element.name}}"
id="{{element.id}}"
value="{{element.value}}"
size="{{element.size}}"
{{#element.size}}size="{{element.size}}"{{/element.size}}
{{#error}}
autofocus aria-describedby="{{element.iderror}}"
{{/error}}
Expand Down
4 changes: 2 additions & 2 deletions lib/templates/filemanager_fileselect.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
</div>
</div>
<div class="fp-original form-group row mx-0">
<label class="form-control-label col-4 px-0">{{#str}}original, repository{{/str}}</label>
<div class="form-control-label col-4 px-0">{{#str}}original, repository{{/str}}</div>
<div class="col-8 form-inline">
<span class="fp-originloading">{{#pix}}i/loading_small{{/pix}} {{#str}}loading, repository{{/str}}</span><span class="fp-value"></span>
</div>
</div>
<div class="fp-reflist form-group row mx-0">
<label class="form-control-label col-4 px-0">{{#str}}referenceslist, repository{{/str}}</label>
<div class="form-control-label col-4 px-0">{{#str}}referenceslist, repository{{/str}}</div>
<div class="col-8 form-inline">
<p class="fp-refcount"></p>
<span class="fp-reflistloading">{{#pix}}i/loading_small{{/pix}} {{#str}}loading, repository{{/str}}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ Y.extend(DIALOGUE, Y.Panel, {
var bb;

if (this.get('closeButton') !== false) {
// The buttons constructor does not allow custom attributes
this.get('buttons').header[0].setAttribute('title', this.get('closeButtonTitle'));
var title = this.get('closeButtonTitle');
// The buttons constructor does not allow custom attributes.
this.get('buttons').header[0].setAttribute('title', title);
this.get('buttons').header[0].setAttribute('aria-label', title);
}

// Initialise the element cache.
Expand Down
Loading

0 comments on commit 96dc92f

Please sign in to comment.