Merge branch 'MDL-65938-master' of git://github.com/junpataleta/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2019-07-24 00:32:49 +02:00 committed by Adrian Greeve
commit 2db07ee59c
12 changed files with 104 additions and 185 deletions

View File

@ -38,6 +38,9 @@ use renderable;
*/
class edit_renderer extends \plugin_renderer_base {
/** @var string The toggle group name of the checkboxes for the toggle-all functionality. */
protected $togglegroup = 'quiz-questions';
/**
* Render the edit page
*
@ -249,7 +252,11 @@ class edit_renderer extends \plugin_renderer_base {
'type' => 'button',
'id' => 'selectmultipledeletecommand',
'value' => get_string('deleteselected', 'mod_quiz'),
'class' => 'btn btn-secondary'
'class' => 'btn btn-secondary',
'data-action' => 'toggle',
'data-togglegroup' => $this->togglegroup,
'data-toggle' => 'action',
'disabled' => true
);
$buttoncanceloptions = array(
'type' => 'button',
@ -259,7 +266,7 @@ class edit_renderer extends \plugin_renderer_base {
);
$groupoptions = array(
'class' => 'btn-group selectmultiplecommand actions',
'class' => 'btn-group selectmultiplecommand actions m-1',
'role' => 'group'
);
@ -270,29 +277,26 @@ class edit_renderer extends \plugin_renderer_base {
$buttoncanceloptions), $groupoptions);
$toolbaroptions = array(
'class' => 'btn-toolbar',
'class' => 'btn-toolbar m-1',
'role' => 'toolbar',
'aria-label' => get_string('selectmultipletoolbar', 'quiz'),
);
// Select all/deselect all questions.
$buttonselectalloptions = array(
'role' => 'button',
'id' => 'questionselectall',
'class' => 'btn btn-link'
);
$buttondeselectalloptions = array(
'role' => 'button',
'id' => 'questiondeselectall',
'class' => 'btn btn-link'
);
$output .= html_writer::tag('div',
html_writer::tag('div',
html_writer::link('#', get_string('selectall', 'quiz'), $buttonselectalloptions) .
html_writer::tag('span', "/", ['class' => 'separator']) .
html_writer::link('#', get_string('selectnone', 'quiz'), $buttondeselectalloptions),
array('class' => 'btn-group selectmultiplecommandbuttons')),
$toolbaroptions);
$selectallid = 'questionselectall';
$selectalltext = get_string('selectall', 'moodle');
$deselectalltext = get_string('deselectall', 'moodle');
$mastercheckbox = new \core\output\checkbox_toggleall($this->togglegroup, true, [
'id' => $selectallid,
'name' => $selectallid,
'value' => 1,
'label' => $selectalltext,
'selectall' => $selectalltext,
'deselectall' => $deselectalltext,
], true);
$selectdeselect = html_writer::div($this->render($mastercheckbox), 'selectmultiplecommandbuttons');
$output .= html_writer::tag('div', $selectdeselect, $toolbaroptions);
return $output;
}
@ -728,10 +732,13 @@ class edit_renderer extends \plugin_renderer_base {
}
$output .= html_writer::start_div('mod-indent-outer');
$output .= html_writer::tag('input', '', array('id' => 'selectquestion-' .
$structure->get_displayed_number_for_slot($slot), 'name' => 'selectquestion[]',
'type' => 'checkbox', 'class' => 'select-multiple-checkbox',
'value' => $structure->get_displayed_number_for_slot($slot)));
$checkbox = new \core\output\checkbox_toggleall($this->togglegroup, false, [
'id' => 'selectquestion-' . $structure->get_displayed_number_for_slot($slot),
'name' => 'selectquestion[]',
'value' => $structure->get_displayed_number_for_slot($slot),
'classes' => 'select-multiple-checkbox',
]);
$output .= $this->render($checkbox);
$output .= $this->question_number($structure->get_displayed_number_for_slot($slot));
// This div is used to indent the content.

View File

@ -75,6 +75,9 @@ abstract class quiz_attempts_report_table extends table_sql {
/** @var bool whether to include the column with checkboxes to select each attempt. */
protected $includecheckboxes;
/** @var string The toggle group name for the checkboxes in the checkbox column. */
protected $togglegroup = 'quiz-attempts';
/**
* Constructor
* @param string $uniqueid
@ -108,9 +111,17 @@ abstract class quiz_attempts_report_table extends table_sql {
* @return string HTML content to go inside the td.
*/
public function col_checkbox($attempt) {
global $OUTPUT;
if ($attempt->attempt) {
return html_writer::checkbox('attemptid[]', $attempt->attempt, false,
get_string('selectattempt', 'quiz'), [], ['class' => 'accesshide']);
$checkbox = new \core\output\checkbox_toggleall($this->togglegroup, false, [
'id' => "attemptid_{$attempt->attempt}",
'name' => 'attemptid[]',
'value' => $attempt->attempt,
'label' => get_string('selectattempt', 'quiz'),
'labelclasses' => 'accesshide',
]);
return $OUTPUT->render($checkbox);
} else {
return '';
}
@ -610,22 +621,6 @@ abstract class quiz_attempts_report_table extends table_sql {
}
echo '<div id="commands">';
echo '<a id="checkattempts" href="#">' .
get_string('selectall', 'quiz') . '</a> / ';
echo '<a id="uncheckattempts" href="#">' .
get_string('selectnone', 'quiz') . '</a> ';
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$('#checkattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', true);
e.preventDefault();
});
$('#uncheckattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', false);
e.preventDefault();
});
});");
echo '&nbsp;&nbsp;';
$this->submit_buttons();
echo '</div>';
@ -640,10 +635,47 @@ abstract class quiz_attempts_report_table extends table_sql {
protected function submit_buttons() {
global $PAGE;
if (has_capability('mod/quiz:deleteattempts', $this->context)) {
echo '<input type="submit" class="btn btn-secondary mr-1" id="deleteattemptsbutton" name="delete" value="' .
get_string('deleteselected', 'quiz_overview') . '"/>';
$deletebuttonparams = [
'type' => 'submit',
'class' => 'btn btn-secondary mr-1',
'id' => 'deleteattemptsbutton',
'name' => 'delete',
'value' => get_string('deleteselected', 'quiz_overview'),
'data-action' => 'toggle',
'data-togglegroup' => $this->togglegroup,
'data-toggle' => 'action',
'disabled' => true
];
echo html_writer::empty_tag('input', $deletebuttonparams);
$PAGE->requires->event_handler('#deleteattemptsbutton', 'click', 'M.util.show_confirm_dialog',
array('message' => get_string('deleteattemptcheck', 'quiz')));
}
}
/**
* Generates the contents for the checkbox column header.
*
* It returns the HTML for a master \core\output\checkbox_toggleall component that selects/deselects all quiz attempts.
*
* @return string
*/
public function checkbox_col_header() {
global $OUTPUT;
// Build the select/deselect all control.
$selectallid = $this->uniqueid . '-selectall-attempts';
$selectalltext = get_string('selectall', 'quiz');
$deselectalltext = get_string('selectnone', 'quiz');
$mastercheckbox = new \core\output\checkbox_toggleall($this->togglegroup, true, [
'id' => $selectallid,
'name' => $selectallid,
'value' => 1,
'label' => $selectalltext,
'labelclasses' => 'accesshide',
'selectall' => $selectalltext,
'deselectall' => $deselectalltext,
]);
return $OUTPUT->render($mastercheckbox);
}
}

View File

@ -213,8 +213,17 @@ class quiz_overview_table extends quiz_attempts_report_table {
protected function submit_buttons() {
if (has_capability('mod/quiz:regrade', $this->context)) {
echo '<input type="submit" class="btn btn-secondary mr-1" name="regrade" value="' .
get_string('regradeselected', 'quiz_overview') . '"/>';
$regradebuttonparams = [
'type' => 'submit',
'class' => 'btn btn-secondary mr-1',
'name' => 'regrade',
'value' => get_string('regradeselected', 'quiz_overview'),
'data-action' => 'toggle',
'data-togglegroup' => $this->togglegroup,
'data-toggle' => 'action',
'disabled' => true
];
echo html_writer::empty_tag('input', $regradebuttonparams);
}
parent::submit_buttons();
}

View File

@ -173,7 +173,7 @@ class quiz_overview_report extends quiz_attempts_report {
if (!$table->is_downloading() && $options->checkboxcolumn) {
$columns[] = 'checkbox';
$headers[] = null;
$headers[] = $table->checkbox_col_header();
}
$this->add_user_columns($table, $columns, $headers);

View File

@ -142,7 +142,7 @@ class quiz_responses_report extends quiz_attempts_report {
if (!$table->is_downloading() && $options->checkboxcolumn) {
$columns[] = 'checkbox';
$headers[] = null;
$headers[] = $table->checkbox_col_header();
}
$this->add_user_columns($table, $columns, $headers);

View File

@ -1137,12 +1137,8 @@ table#categoryquestions {
/* Bulk edit actions */
#page-mod-quiz-edit .selectmultiplecommandbuttons {
margin: 0.6em 0.4em;
}
#page-mod-quiz-edit .btn-group.selectmultiplecommand,
#page-mod-quiz-edit .btn-group.selectmultiplecommandbuttons,
#page-mod-quiz-edit .selectmultiplecommandbuttons,
#page-mod-quiz-edit .select-multiple-checkbox {
display: none;
}
@ -1150,21 +1146,7 @@ table#categoryquestions {
#page-mod-quiz-edit.select-multiple .selectmultiplecommand,
#page-mod-quiz-edit.select-multiple .selectmultiplecommandbuttons,
#page-mod-quiz-edit.select-multiple .select-multiple-checkbox {
display: inherit;
}
#page-mod-quiz-edit.select-multiple .selectmultiplecommandbuttons .separator {
position: relative;
float: left;
padding: .5rem 0;
}
#page-mod-quiz-edit #questionselectall {
padding-right: .1rem;
}
#page-mod-quiz-edit #questiondeselectall {
padding-left: .1rem;
display: inline-block;
}
#page-mod-quiz-edit.select-multiple input.select-multiple-checkbox[type="checkbox"] {

View File

@ -131,7 +131,7 @@ Feature: Edit quiz page - remove multiple questions
# Delete all questions in page. Page contains multiple questions
When I click on "Select multiple items" "button"
Then I click on "Select all" "link"
Then I press "Select all"
And I click on "Delete selected" "button"
And I click on "Yes" "button" in the "Confirm" "dialogue"
@ -162,10 +162,10 @@ Feature: Edit quiz page - remove multiple questions
# Delete last question in last page. Page contains multiple questions
When I click on "Select multiple items" "button"
And I click on "Select all" "link"
And I press "Select all"
Then the field "selectquestion-3" matches value "1"
When I click on "Deselect all" "link"
When I press "Deselect all"
Then the field "selectquestion-3" matches value "0"
@javascript

View File

@ -47,7 +47,6 @@ var CSS = {
CONTENTAFTERLINK: 'div.contentafterlink',
CONTENTWITHOUTLINK: 'div.contentwithoutlink',
DELETESECTIONICON: 'a.editing_delete .icon',
DESELECTALL: '#questiondeselectall',
EDITMAXMARK: 'a.editing_maxmark',
EDITSECTION: 'a.editing_section',
EDITSECTIONICON: 'a.editing_section .icon',
@ -322,28 +321,8 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, {
Y.one('body').removeClass(CSS.SELECTMULTIPLE);
});
// Click select all link to check all the checkboxes.
Y.one(SELECTOR.SELECTALL).on('click', function(e) {
e.preventDefault();
Y.all(SELECTOR.SELECTMULTIPLECHECKBOX).set('checked', 'checked');
});
// Click deselect all link to show the select all checkboxes.
Y.one(SELECTOR.DESELECTALL).on('click', function(e) {
e.preventDefault();
Y.all(SELECTOR.SELECTMULTIPLECHECKBOX).set('checked', '');
});
// Disable delete multiple button by default.
Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON).setAttribute('disabled', 'disabled');
// Assign the delete method to the delete multiple button.
Y.delegate('click', this.delete_multiple_action, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this);
// Enable the delete all button only when at least one slot is selected.
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTMULTIPLECHECKBOX, this);
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTALL, this);
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.DESELECTALL, this);
},
/**
@ -416,22 +395,6 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, {
return null;
},
/**
* If a select multiple checkbox is checked enable the buttons in the select multiple
* toolbar otherwise disable it.
*
* @method toggle_select_all_buttons_enabled
*/
toggle_select_all_buttons_enabled: function() {
var checked = Y.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':checked');
var deletebutton = Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON);
if (checked && !checked.isEmpty()) {
deletebutton.removeAttribute('disabled');
} else {
deletebutton.setAttribute('disabled', 'disabled');
}
},
/**
* Deletes the given activity or resource after confirmation.
*

File diff suppressed because one or more lines are too long

View File

@ -47,7 +47,6 @@ var CSS = {
CONTENTAFTERLINK: 'div.contentafterlink',
CONTENTWITHOUTLINK: 'div.contentwithoutlink',
DELETESECTIONICON: 'a.editing_delete .icon',
DESELECTALL: '#questiondeselectall',
EDITMAXMARK: 'a.editing_maxmark',
EDITSECTION: 'a.editing_section',
EDITSECTIONICON: 'a.editing_section .icon',
@ -322,28 +321,8 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, {
Y.one('body').removeClass(CSS.SELECTMULTIPLE);
});
// Click select all link to check all the checkboxes.
Y.one(SELECTOR.SELECTALL).on('click', function(e) {
e.preventDefault();
Y.all(SELECTOR.SELECTMULTIPLECHECKBOX).set('checked', 'checked');
});
// Click deselect all link to show the select all checkboxes.
Y.one(SELECTOR.DESELECTALL).on('click', function(e) {
e.preventDefault();
Y.all(SELECTOR.SELECTMULTIPLECHECKBOX).set('checked', '');
});
// Disable delete multiple button by default.
Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON).setAttribute('disabled', 'disabled');
// Assign the delete method to the delete multiple button.
Y.delegate('click', this.delete_multiple_action, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this);
// Enable the delete all button only when at least one slot is selected.
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTMULTIPLECHECKBOX, this);
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTALL, this);
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.DESELECTALL, this);
},
/**
@ -416,22 +395,6 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, {
return null;
},
/**
* If a select multiple checkbox is checked enable the buttons in the select multiple
* toolbar otherwise disable it.
*
* @method toggle_select_all_buttons_enabled
*/
toggle_select_all_buttons_enabled: function() {
var checked = Y.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':checked');
var deletebutton = Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON);
if (checked && !checked.isEmpty()) {
deletebutton.removeAttribute('disabled');
} else {
deletebutton.setAttribute('disabled', 'disabled');
}
},
/**
* Deletes the given activity or resource after confirmation.
*

View File

@ -88,28 +88,8 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, {
Y.one('body').removeClass(CSS.SELECTMULTIPLE);
});
// Click select all link to check all the checkboxes.
Y.one(SELECTOR.SELECTALL).on('click', function(e) {
e.preventDefault();
Y.all(SELECTOR.SELECTMULTIPLECHECKBOX).set('checked', 'checked');
});
// Click deselect all link to show the select all checkboxes.
Y.one(SELECTOR.DESELECTALL).on('click', function(e) {
e.preventDefault();
Y.all(SELECTOR.SELECTMULTIPLECHECKBOX).set('checked', '');
});
// Disable delete multiple button by default.
Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON).setAttribute('disabled', 'disabled');
// Assign the delete method to the delete multiple button.
Y.delegate('click', this.delete_multiple_action, BODY, SELECTOR.SELECTMULTIPLEDELETEBUTTON, this);
// Enable the delete all button only when at least one slot is selected.
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTMULTIPLECHECKBOX, this);
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.SELECTALL, this);
Y.delegate('click', this.toggle_select_all_buttons_enabled, BODY, SELECTOR.DESELECTALL, this);
},
/**
@ -182,22 +162,6 @@ Y.extend(RESOURCETOOLBOX, TOOLBOX, {
return null;
},
/**
* If a select multiple checkbox is checked enable the buttons in the select multiple
* toolbar otherwise disable it.
*
* @method toggle_select_all_buttons_enabled
*/
toggle_select_all_buttons_enabled: function() {
var checked = Y.all(SELECTOR.SELECTMULTIPLECHECKBOX + ':checked');
var deletebutton = Y.one(SELECTOR.SELECTMULTIPLEDELETEBUTTON);
if (checked && !checked.isEmpty()) {
deletebutton.removeAttribute('disabled');
} else {
deletebutton.setAttribute('disabled', 'disabled');
}
},
/**
* Deletes the given activity or resource after confirmation.
*

View File

@ -45,7 +45,6 @@ var CSS = {
CONTENTAFTERLINK: 'div.contentafterlink',
CONTENTWITHOUTLINK: 'div.contentwithoutlink',
DELETESECTIONICON: 'a.editing_delete .icon',
DESELECTALL: '#questiondeselectall',
EDITMAXMARK: 'a.editing_maxmark',
EDITSECTION: 'a.editing_section',
EDITSECTIONICON: 'a.editing_section .icon',