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

This commit is contained in:
Andrew Nicols 2020-01-08 08:50:03 +08:00
commit 5e34719d7e
6 changed files with 78 additions and 80 deletions

View File

@ -1,2 +1,2 @@
define ("core_grades/edittree_index",["jquery"],function(a){var b=function(){a("body").on("change",".itemselect.ignoredirty",b.checkMoveMenuState);a("body").on("click","[data-action=\"grade_edittree-index-bulkselect\"]",b.toggleAllSelectItems);a("body").on("change",".weightoverride",b.toggleWeightInput);a("#menumoveafter").on("change",function(){var b=a(this).closest("form"),c=b.find("#bulkmoveinput");c.val(1);b.submit()});b.checkMoveMenuState()};b.toggleWeightInput=function(b){b.preventDefault();var c=a(this),d=c.closest("tr");a("input[name=\"weight_"+d.data("itemid")+"\"]").prop("disabled",!c.prop("checked"))};b.toggleAllSelectItems=function(c){c.preventDefault();var d=a(this),e=d.closest("tr");a("."+e.data("category")+" .itemselect").prop("checked",d.data("checked"));b.checkMoveMenuState()};b.getMoveMenu=function(){return a("#menumoveafter")};b.checkMoveMenuState=function(){var c=b.getMoveMenu();if(!c.length){return!1}var d;a(".itemselect").each(function(){d=a(this).prop("checked");return!d});c.prop("disabled",!d);return d};return{enhance:b}});
define ("core_grades/edittree_index",["jquery"],function(a){var b=function(){a("body").on("change",".weightoverride",b.toggleWeightInput);a("#menumoveafter").on("change",function(){var b=a(this).closest("form"),c=b.find("#bulkmoveinput");c.val(1);b.submit()})};b.toggleWeightInput=function(b){b.preventDefault();var c=a(this),d=c.closest("tr");a("input[name=\"weight_"+d.data("itemid")+"\"]").prop("disabled",!c.prop("checked"))};return{enhance:b}});
//# sourceMappingURL=edittree_index.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -30,12 +30,6 @@ define([
* @method edittree
*/
var edittree = function() {
// Watch items and toggle the move menu accordingly.
$('body').on('change', '.itemselect.ignoredirty', edittree.checkMoveMenuState);
// Watch for the 'All' and 'None' links.
$('body').on('click', '[data-action="grade_edittree-index-bulkselect"]', edittree.toggleAllSelectItems);
// Watch for the weight override checkboxes.
$('body').on('change', '.weightoverride', edittree.toggleWeightInput);
@ -47,9 +41,6 @@ define([
bulkmove.val(1);
form.submit();
});
// CHeck the initial state of the move menu.
edittree.checkMoveMenuState();
};
/**
@ -67,60 +58,6 @@ define([
$('input[name="weight_' + row.data('itemid') + '"]').prop('disabled', !node.prop('checked'));
};
/**
* Toggle all select boxes on or off.
*
* @method toggleAllSelectItems
* @param {EventFacade} e
* @private
*/
edittree.toggleAllSelectItems = function(e) {
e.preventDefault();
var node = $(this),
row = node.closest('tr');
$('.' + row.data('category') + ' .itemselect').prop('checked', node.data('checked'));
edittree.checkMoveMenuState();
};
/**
* Get the move menu.
*
* @method getMoveMenu
* @private
* @return {jQuery}
*/
edittree.getMoveMenu = function() {
return $('#menumoveafter');
};
/**
* Check whether any checkboxes are ticked.
*
* @method checkMoveMenuState
* @private
* @return {Boolean}
*/
edittree.checkMoveMenuState = function() {
var menu = edittree.getMoveMenu();
if (!menu.length) {
return false;
}
var selected;
$('.itemselect').each(function() {
selected = $(this).prop('checked');
// Return early if any are checked.
return !selected;
});
menu.prop('disabled', !selected);
return selected;
};
return /** @alias module:core_grades/edittree_index */ {
enhance: edittree
};

View File

@ -840,20 +840,39 @@ class grade_edit_tree_column_select extends grade_edit_tree_column {
}
public function get_category_cell($category, $levelclass, $params) {
global $OUTPUT;
if (empty($params['eid'])) {
throw new Exception('Array key (eid) missing from 3rd param of grade_edit_tree_column_select::get_category_cell($category, $levelclass, $params)');
}
$selectall = html_writer::link('#', get_string('all'), [
'data-action' => 'grade_edittree-index-bulkselect',
'data-checked' => true,
]);
$selectnone = html_writer::link('#', get_string('none'), [
'data-action' => 'grade_edittree-index-bulkselect',
'data-checked' => false,
// Get toggle group for this master checkbox.
$togglegroup = $this->get_checkbox_togglegroup($category);
// Set label for this master checkbox.
$masterlabel = get_string('all');
// Use category name if available.
if ($category->fullname !== '?') {
$masterlabel = format_string($category->fullname);
// Limit the displayed category name to prevent the Select column from getting too wide.
if (core_text::strlen($masterlabel) > 20) {
$masterlabel = get_string('textellipsis', 'core', core_text::substr($masterlabel, 0, 12));
}
}
// Build the master checkbox.
$mastercheckbox = new \core\output\checkbox_toggleall($togglegroup, true, [
'id' => $togglegroup,
'name' => $togglegroup,
'value' => 1,
'classes' => 'itemselect ignoredirty',
'label' => $masterlabel,
// Consistent label to prevent the select column from resizing.
'selectall' => $masterlabel,
'deselectall' => $masterlabel,
'labelclasses' => 'm-0',
]);
$categorycell = parent::get_category_cell($category, $levelclass, $params);
$categorycell->text = $selectall . ' / ' . $selectnone;
$categorycell->text = $OUTPUT->render($mastercheckbox);
return $categorycell;
}
@ -864,12 +883,43 @@ class grade_edit_tree_column_select extends grade_edit_tree_column {
$itemcell = parent::get_item_cell($item, $params);
if ($params['itemtype'] != 'course' && $params['itemtype'] != 'category') {
$itemcell->text = '<label class="accesshide" for="select_'.$params['eid'].'">'.
get_string('select', 'grades', $item->itemname).'</label>
<input class="itemselect ignoredirty" type="checkbox" name="select_'.$params['eid'].'" id="select_'.$params['eid'].
'"/>';
global $OUTPUT;
// Fetch the grade item's category.
$category = grade_category::fetch(['id' => $item->categoryid]);
$togglegroup = $this->get_checkbox_togglegroup($category);
$checkboxid = 'select_' . $params['eid'];
$checkbox = new \core\output\checkbox_toggleall($togglegroup, false, [
'id' => $checkboxid,
'name' => $checkboxid,
'label' => get_string('select', 'grades', $item->itemname),
'labelclasses' => 'accesshide',
'classes' => 'itemselect ignoredirty',
]);
$itemcell->text = $OUTPUT->render($checkbox);
}
return $itemcell;
}
/**
* Generates a toggle group name for a bulk-action checkbox based on the given grade category.
*
* @param grade_category $category The grade category.
* @return string
*/
protected function get_checkbox_togglegroup(grade_category $category): string {
$levels = [];
$categories = explode('/', $category->path);
foreach ($categories as $categoryid) {
$level = 'category' . $categoryid;
if (!in_array($level, $levels)) {
$levels[] = 'category' . $categoryid;
}
}
$togglegroup = implode(' ', $levels);
return $togglegroup;
}
}

View File

@ -17,11 +17,20 @@
{{!
@template core_grades/edit_tree
Edit tree.
Edit tree template.
Context variables required for this template:
* actionurl - string - Form action URL.
* sesskey - string - The session key.
* notification - object - Context data for the notification.
* showsave - boolean - Whether to show the save changes button.
* showbulkmove - boolean - Whether to show the bulk move select menu.
* table - string - HTML content of the grade items table.
* bulkmoveoptions - array - Key-value pair array for the options of the the bulk move select menu element.
Example context (json):
{
"actionurl": "https://domain.example/grade/edit/tree/index.php?id=4",
"actionurl": "#",
"sesskey": "fakesesskey",
"notification": "",
"table": "<table class='generaltable simple setup-grades' id='grade_edit_tree_table'><thead> <tr><th>Name</th><th>Weights</th><th>Max grade</th><th>Actions</th> </tr></thead><tbody></tbody></table>",
@ -48,7 +57,8 @@
<div class="form-inline mt-3">
<input type="hidden" name="bulkmove" value="0" id="bulkmoveinput">
<label for="menumoveafter">{{#str}}moveselectedto, grades{{/str}}</label>
<select name="moveafter" id="menumoveafter" class="ignoredirty singleselect custom-select form-control">
<select name="moveafter" id="menumoveafter" class="ignoredirty singleselect custom-select form-control"
data-action="toggle" data-toggle="action" data-togglegroup="category" disabled>
{{#bulkmoveoptions}}
<option value="{{value}}">{{name}}</option>
{{/bulkmoveoptions}}

View File

@ -2002,6 +2002,7 @@ If \'plain text area\' is selected, a format for text input areas such as HTML o
The list of available text editors is determined by the site administrator.';
$string['texteditor'] = 'Use standard web forms';
$string['textformat'] = 'Plain text format';
$string['textellipsis'] = '{$a}...';
$string['timesplitting:deciles'] = 'Last tenth';
$string['timesplitting:deciles_help'] = 'This analysis interval divides the course into tenths (10 equal parts), with each prediction being based on the data of only the most recent previous tenth.';
$string['timesplitting:decilesaccum'] = 'All previous tenths';