MDL-55584 gradereport_singleview: Convert some elements to template

Part of MDL-55071
This commit is contained in:
Frederic Massart 2016-08-16 17:40:07 +08:00 committed by Dan Poltawski
parent 376e14fa34
commit ec3857fee2
8 changed files with 151 additions and 96 deletions

View File

@ -230,10 +230,12 @@ abstract class tablelike extends screen {
* @return array
*/
public function buttons() {
$save = html_writer::empty_tag('input', array(
global $OUTPUT;
$save = $OUTPUT->render_from_template('gradereport_singleview/button', [
'type' => 'submit',
'value' => get_string('save', 'gradereport_singleview'),
));
]);
return array($save);
}

View File

@ -85,62 +85,25 @@ class bulk_insert extends element {
* @return string HTML
*/
public function html() {
$insertvalue = get_string('bulkinsertvalue', 'gradereport_singleview');
$insertappliesto = get_string('bulkappliesto', 'gradereport_singleview');
global $OUTPUT;
$insertoptions = array(
'all' => get_string('all_grades', 'gradereport_singleview'),
'blanks' => get_string('blanks', 'gradereport_singleview')
);
$selectlabel = html_writer::label(
$insertappliesto,
'menu' . $this->selectname
);
$select = html_writer::select(
$insertoptions,
$this->selectname,
'blanks',
false,
array(
'id' => 'menu' . $this->selectname
)
);
$textlabel = html_writer::label(
$insertvalue,
$this->insertname
);
$text = new text_attribute($this->insertname, "0", 'bulk');
$context = (object) [
'label' => get_string('bulklegend', 'gradereport_singleview'),
'applylabel' => get_string('bulkperform', 'gradereport_singleview'),
'applyname' => $this->applyname,
'menuname' => $this->selectname,
'menulabel' => get_string('bulkappliesto', 'gradereport_singleview'),
'menuoptions' => [
['value' => 'all', 'name' => get_string('all_grades', 'gradereport_singleview')],
['value' => 'blanks', 'name' => get_string('blanks', 'gradereport_singleview'), 'selected' => true],
],
'valuename' => $this->insertname,
'valuelabel' => get_string('bulkinsertvalue', 'gradereport_singleview'),
'valuefield' => $text->html()
];
$inner = implode(' ', array(
$selectlabel,
$select,
$textlabel,
$text->html()
));
$fieldset = html_writer::tag(
'fieldset',
html_writer::tag(
'legend',
get_string('bulklegend', 'gradereport_singleview'),
array(
'class' => 'accesshide'
)
) .
$inner
);
$apply = html_writer::checkbox(
$this->applyname,
1,
false,
get_string('bulkperform', 'gradereport_singleview')
);
$applydiv = html_writer::div($apply, 'enable');
return $applydiv . $fieldset;
return $OUTPUT->render_from_template('gradereport_singleview/bulk_insert', $context);
}
/**

View File

@ -77,22 +77,25 @@ class dropdown_attribute extends element {
* @return string
*/
public function html() {
$old = array(
'type' => 'hidden',
'name' => 'old' . $this->name,
'value' => $this->selected
global $OUTPUT;
$options = $this->options;
$selected = $this->selected;
$context = array(
'name' => $this->name,
'value' => $this->selected,
'tabindex' => 1,
'disabled' => !empty($this->isdisabled),
'options' => array_map(function($option) use ($options, $selected) {
return [
'name' => $options[$option],
'value' => $option,
'selected' => $selected == $option
];
}, array_keys($options))
);
$attributes = array('tabindex' => '1');
if (!empty($this->isdisabled)) {
$attributes['disabled'] = 'DISABLED';
}
$select = html_writer::select(
$this->options, $this->name, $this->selected, false, $attributes
);
return ($select . html_writer::empty_tag('input', $old));
return $OUTPUT->render_from_template('gradereport_singleview/dropdown_attribute', $context);
}
}

View File

@ -65,38 +65,24 @@ class text_attribute extends element {
* @return string The HTML.
*/
public function html() {
$attributes = array(
'type' => 'text',
global $OUTPUT;
$context = (object) [
'id' => $this->name,
'name' => $this->name,
'value' => $this->value,
'id' => $this->name
);
'disabled' => $this->isdisabled,
];
if ($this->isdisabled) {
$attributes['disabled'] = 'DISABLED';
}
$hidden = array(
'type' => 'hidden',
'name' => 'old' . $this->name,
'value' => $this->value
);
$label = '';
$context->label = '';
if (preg_match("/^feedback/", $this->name)) {
$labeltitle = get_string('feedbackfor', 'gradereport_singleview', $this->label);
$attributes['tabindex'] = '2';
$label = html_writer::tag('label', $labeltitle, array('for' => $this->name, 'class' => 'accesshide'));
$context->label = get_string('feedbackfor', 'gradereport_singleview', $this->label);
$context->tabindex = '2';
} else if (preg_match("/^finalgrade/", $this->name)) {
$labeltitle = get_string('gradefor', 'gradereport_singleview', $this->label);
$attributes['tabindex'] = '1';
$label = html_writer::tag('label', $labeltitle, array('for' => $this->name, 'class' => 'accesshide'));
$context->label = get_string('gradefor', 'gradereport_singleview', $this->label);
$context->tabindex = '1';
}
return (
$label .
html_writer::empty_tag('input', $attributes) .
html_writer::empty_tag('input', $hidden)
);
return $OUTPUT->render_from_template('gradereport_singleview/text_attribute', $context);
}
}

View File

@ -0,0 +1,34 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
Bulk insert attribute.
}}
<div class="enable">
<input type="checkbox" name="{{applyname}}" value="1" id="{{applyname}}">
<label for="{{applyname}}">{{applylabel}}</label>
</div>
<fieldset>
<legend class="accesshide">{{label}}</legend>
<label for="{{menuname}}">{{menulabel}}</label>
<select name="{{menuname}}" id="{{menuname}}">
{{#menuoptions}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/menuoptions}}
</select>
<label for="{{valuename}}">{{valuelabel}}</label>
{{{valuefield}}}
</fieldset>

View File

@ -0,0 +1,20 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
Button.
}}
<input type="{{type}}" value={{#quote}}{{value}}{{/quote}}>

View File

@ -0,0 +1,25 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
Dropdown attribute.
}}
<select id="{{name}}" name="{{name}}" tabindex="1" {{#disabled}}disabled{{/disabled}}>
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</select>
<input type="hidden" name="old{{name}}" value="{{value}}">

View File

@ -0,0 +1,22 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
Text attribute.
}}
<label for="{{name}}" class="accesshide">{{label}}</label>
<input id="{{name}}" name="{{name}}" type="text" value="{{value}}" {{#tabindex}}tabindex="{{.}}"{{/tabindex}} {{#disabled}}disabled{{/disabled}}>
<input type="hidden" name="old{{name}}" value="{{value}}">