Merge branch 'MDL-79048-master-2' of https://github.com/junpataleta/moodle

This commit is contained in:
Jake Dallimore 2023-09-11 12:59:59 +08:00
commit 996760f32d
No known key found for this signature in database
8 changed files with 73 additions and 7 deletions

View File

@ -1,4 +1,4 @@
define("core_courseformat/local/content/bulkedittools",["exports","core/reactive","core/sticky-footer","core_courseformat/courseeditor","core/str","core/pending","core/prefetch","core_courseformat/local/content/actions/bulkselection"],(function(_exports,_reactive,_stickyFooter,_courseeditor,_str,_pending,_prefetch,_bulkselection){var obj;
define("core_courseformat/local/content/bulkedittools",["exports","core/reactive","core/sticky-footer","core_courseformat/courseeditor","core/str","core/pending","core/prefetch","core_courseformat/local/content/actions/bulkselection","core/notification"],(function(_exports,_reactive,_stickyFooter,_courseeditor,_str,_pending,_prefetch,_bulkselection,_notification){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* The bulk editor tools bar.
*
@ -6,6 +6,6 @@ define("core_courseformat/local/content/bulkedittools",["exports","core/reactive
* @class core_courseformat/local/content/bulkedittools
* @copyright 2023 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj},(0,_prefetch.prefetchStrings)("core_courseformat",["bulkselection"]);class Component extends _reactive.BaseComponent{create(){this.name="bulk_editor_tools",this.selectors={ACTIONS:'[data-for="bulkaction"]',ACTIONTOOL:'[data-for="bulkactions"] li',CANCEL:'[data-for="bulkcancel"]',COUNT:"[data-for='bulkcount']",SELECTABLE:"[data-bulkcheckbox][data-is-selectable]",SELECTALL:'[data-for="selectall"]',BULKBTN:'[data-for="enableBulk"]'},this.classes={HIDE:"d-none",DISABLED:"disabled"}}static init(target,selectors){return new this({element:document.querySelector(target),reactive:(0,_courseeditor.getCurrentCourseEditor)(),selectors:selectors})}stateReady(){const cancelBtn=this.getElement(this.selectors.CANCEL);cancelBtn&&this.addEventListener(cancelBtn,"click",this._cancelBulk);const selectAll=this.getElement(this.selectors.SELECTALL);selectAll&&this.addEventListener(selectAll,"click",this._selectAllClick)}getWatchers(){return[{watch:"bulk.enabled:updated",handler:this._refreshEnabled},{watch:"bulk:updated",handler:this._refreshTools}]}_refreshEnabled(_ref){let{element:element}=_ref;element.enabled?(0,_stickyFooter.enableStickyFooter)():(0,_stickyFooter.disableStickyFooter)()}_refreshTools(param){this._refreshSelectCount(param),this._refreshSelectAll(param),this._refreshActions(param)}async _refreshSelectCount(_ref2){let{element:bulk}=_ref2;const stringName=bulk.selection.length>1?"bulkselection_plural":"bulkselection",selectedCount=await(0,_str.getString)(stringName,"core_courseformat",bulk.selection.length),selectedElement=this.getElement(this.selectors.COUNT);selectedElement&&(selectedElement.innerHTML=selectedCount)}_refreshSelectAll(_ref3){let{element:bulk}=_ref3;const selectall=this.getElement(this.selectors.SELECTALL);if(!selectall)return;selectall.disabled=""===bulk.selectedType;const pending=new _pending.default("courseformat/bulktools:refreshSelectAll");setTimeout((()=>{selectall.checked=(0,_bulkselection.checkAllBulkSelected)(this.reactive),pending.resolve()}),100)}_refreshActions(_ref4){let{element:bulk}=_ref4;const displayType="section"==bulk.selectedType?"section":"cm",enabled=""!==bulk.selectedType;this.getElements(this.selectors.ACTIONS).forEach((action=>{action.classList.toggle(this.classes.DISABLED,!enabled),action.tabIndex=enabled?0:-1;const actionTool=action.closest(this.selectors.ACTIONTOOL),isHidden=action.dataset.bulk!=displayType;null==actionTool||actionTool.classList.toggle(this.classes.HIDE,isHidden)}))}_cancelBulk(){const pending=new _pending.default("courseformat/content:bulktoggle_off");this.reactive.dispatch("bulkEnable",!1),setTimeout((()=>{var _document$querySelect;null===(_document$querySelect=document.querySelector(this.selectors.BULKBTN))||void 0===_document$querySelect||_document$querySelect.focus(),pending.resolve()}),150)}_selectAllClick(event){event.preventDefault(),event.altKey?(0,_bulkselection.switchBulkSelection)(this.reactive):(0,_bulkselection.checkAllBulkSelected)(this.reactive)?this._handleUnselectAll():(0,_bulkselection.selectAllBulk)(this.reactive,!0)}_handleUnselectAll(){const pending=new _pending.default("courseformat/content:bulktUnselectAll");(0,_bulkselection.selectAllBulk)(this.reactive,!1),setTimeout((()=>{var _document$querySelect2;null===(_document$querySelect2=document.querySelector(this.selectors.SELECTABLE))||void 0===_document$querySelect2||_document$querySelect2.focus(),pending.resolve()}),150)}}return _exports.default=Component,_exports.default}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_pending=_interopRequireDefault(_pending),_notification=_interopRequireDefault(_notification),(0,_prefetch.prefetchStrings)("core_courseformat",["bulkselection"]);class Component extends _reactive.BaseComponent{create(){this.name="bulk_editor_tools",this.selectors={ACTIONS:'[data-for="bulkaction"]',ACTIONTOOL:'[data-for="bulkactions"] li',CANCEL:'[data-for="bulkcancel"]',COUNT:"[data-for='bulkcount']",SELECTABLE:"[data-bulkcheckbox][data-is-selectable]",SELECTALL:'[data-for="selectall"]',BULKBTN:'[data-for="enableBulk"]'},this.classes={HIDE:"d-none",DISABLED:"disabled"}}static init(target,selectors){return new this({element:document.querySelector(target),reactive:(0,_courseeditor.getCurrentCourseEditor)(),selectors:selectors})}stateReady(){const cancelBtn=this.getElement(this.selectors.CANCEL);cancelBtn&&this.addEventListener(cancelBtn,"click",this._cancelBulk);const selectAll=this.getElement(this.selectors.SELECTALL);selectAll&&this.addEventListener(selectAll,"click",this._selectAllClick)}getWatchers(){return[{watch:"bulk.enabled:updated",handler:this._refreshEnabled},{watch:"bulk:updated",handler:this._refreshTools}]}_refreshEnabled(_ref){let{element:element}=_ref;this._updatePageTitle(element.enabled).catch(_notification.default.exception),element.enabled?(0,_stickyFooter.enableStickyFooter)():(0,_stickyFooter.disableStickyFooter)()}_refreshTools(param){this._refreshSelectCount(param),this._refreshSelectAll(param),this._refreshActions(param)}async _refreshSelectCount(_ref2){let{element:bulk}=_ref2;const stringName=bulk.selection.length>1?"bulkselection_plural":"bulkselection",selectedCount=await(0,_str.getString)(stringName,"core_courseformat",bulk.selection.length),selectedElement=this.getElement(this.selectors.COUNT);selectedElement&&(selectedElement.innerHTML=selectedCount)}_refreshSelectAll(_ref3){let{element:bulk}=_ref3;const selectall=this.getElement(this.selectors.SELECTALL);if(!selectall)return;selectall.disabled=""===bulk.selectedType;const pending=new _pending.default("courseformat/bulktools:refreshSelectAll");setTimeout((()=>{selectall.checked=(0,_bulkselection.checkAllBulkSelected)(this.reactive),pending.resolve()}),100)}_refreshActions(_ref4){let{element:bulk}=_ref4;const displayType="section"==bulk.selectedType?"section":"cm",enabled=""!==bulk.selectedType;this.getElements(this.selectors.ACTIONS).forEach((action=>{action.classList.toggle(this.classes.DISABLED,!enabled),action.tabIndex=enabled?0:-1;const actionTool=action.closest(this.selectors.ACTIONTOOL),isHidden=action.dataset.bulk!=displayType;null==actionTool||actionTool.classList.toggle(this.classes.HIDE,isHidden)}))}_cancelBulk(){const pending=new _pending.default("courseformat/content:bulktoggle_off");this.reactive.dispatch("bulkEnable",!1),setTimeout((()=>{var _document$querySelect;null===(_document$querySelect=document.querySelector(this.selectors.BULKBTN))||void 0===_document$querySelect||_document$querySelect.focus(),pending.resolve()}),150)}_selectAllClick(event){event.preventDefault(),event.altKey?(0,_bulkselection.switchBulkSelection)(this.reactive):(0,_bulkselection.checkAllBulkSelected)(this.reactive)?this._handleUnselectAll():(0,_bulkselection.selectAllBulk)(this.reactive,!0)}_handleUnselectAll(){const pending=new _pending.default("courseformat/content:bulktUnselectAll");(0,_bulkselection.selectAllBulk)(this.reactive,!1),setTimeout((()=>{var _document$querySelect2;null===(_document$querySelect2=document.querySelector(this.selectors.SELECTABLE))||void 0===_document$querySelect2||_document$querySelect2.focus(),pending.resolve()}),150)}async _updatePageTitle(enabled){const enableBulk=document.querySelector(this.selectors.BULKBTN);let params,bulkEditTitle,editingTitle;enableBulk.dataset.sectiontitle?(params={course:enableBulk.dataset.coursename,sectionname:enableBulk.dataset.sectionname,sectiontitle:enableBulk.dataset.sectiontitle},bulkEditTitle=await(0,_str.getString)("coursesectiontitlebulkediting","moodle",params),editingTitle=await(0,_str.getString)("coursesectiontitleediting","moodle",params)):(params={course:enableBulk.dataset.coursename},bulkEditTitle=await(0,_str.getString)("coursetitlebulkediting","moodle",params),editingTitle=await(0,_str.getString)("coursetitleediting","moodle",params));const pageTitle=document.title;document.title=enabled?pageTitle.replace(editingTitle,bulkEditTitle):pageTitle.replace(bulkEditTitle,editingTitle)}}return _exports.default=Component,_exports.default}));
//# sourceMappingURL=bulkedittools.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -33,6 +33,7 @@ import {
switchBulkSelection,
checkAllBulkSelected
} from 'core_courseformat/local/content/actions/bulkselection';
import Notification from 'core/notification';
// Load global strings.
prefetchStrings(
@ -113,6 +114,8 @@ export default class Component extends BaseComponent {
* @param {Object} param.element details the update details (state.bulk in this case).
*/
_refreshEnabled({element}) {
this._updatePageTitle(element.enabled).catch(Notification.exception);
if (element.enabled) {
enableStickyFooter();
} else {
@ -234,4 +237,47 @@ export default class Component extends BaseComponent {
pending.resolve();
}, 150);
}
/**
* Updates the <title> attribute of the page whenever bulk editing is toggled.
*
* This helps users, especially screen reader users, to understand the current state of the course homepage.
*
* @param {Boolean} enabled True when bulk editing is turned on. False, otherwise.
* @returns {Promise<void>}
* @private
*/
async _updatePageTitle(enabled) {
const enableBulk = document.querySelector(this.selectors.BULKBTN);
let params, bulkEditTitle, editingTitle;
if (enableBulk.dataset.sectiontitle) {
// Section editing mode.
params = {
course: enableBulk.dataset.coursename,
sectionname: enableBulk.dataset.sectionname,
sectiontitle: enableBulk.dataset.sectiontitle,
};
bulkEditTitle = await getString('coursesectiontitlebulkediting', 'moodle', params);
editingTitle = await getString('coursesectiontitleediting', 'moodle', params);
} else {
// Whole course editing mode.
params = {
course: enableBulk.dataset.coursename
};
bulkEditTitle = await getString('coursetitlebulkediting', 'moodle', params);
editingTitle = await getString('coursetitleediting', 'moodle', params);
}
const pageTitle = document.title;
if (enabled) {
// Use bulk editing string for the page title.
// At this point, the current page title should be the normal editing title.
// So replace the normal editing title with the bulk editing title.
document.title = pageTitle.replace(editingTitle, bulkEditTitle);
} else {
// Use the normal editing string for the page title.
// At this point, the current page title should be the bulk editing title.
// So replace the bulk editing title with the normal editing title.
document.title = pageTitle.replace(bulkEditTitle, editingTitle);
}
}
}

View File

@ -50,13 +50,20 @@ class bulkedittoggler implements named_templatable, renderable {
* @return stdClass data context for a mustache template
*/
public function export_for_template(\renderer_base $output) {
$section = optional_param('section', 0, PARAM_INT);
$format = $this->format;
$course = $format->get_course();
$data = (object)[
'id' => $course->id,
'coursename' => format_string($course->fullname),
];
if ($section) {
$data->sectionname = get_string('sectionname', "format_$course->format");
$data->sectiontitle = get_section_name($course, $section);
}
return $data;
}
}

View File

@ -26,7 +26,9 @@
<button
id="bulk-enable-{{uniqid}}"
class="bulkEnable btn text-primary text-nowrap"
data-for="enableBulk"
data-for="enableBulk" data-coursename="{{coursename}}"
{{#sectiontitle}} data-sectiontitle="{{.}}" {{/sectiontitle}}
{{#sectionname}} data-sectionname="{{.}}" {{/sectionname}}
>
{{#str}} bulkedit, core_courseformat {{/str}} {{#pix}} i/edit, core {{/pix}}
</button>

View File

@ -259,19 +259,25 @@ if ($PAGE->user_allowed_editing()) {
$PAGE->set_button($buttons);
}
$editingtitle = '';
if ($PAGE->user_is_editing()) {
// Append this to the page title's lang string to get its equivalent when editing mode is turned on.
$editingtitle = 'editing';
}
// If viewing a section, make the title more specific.
if ($section && $section > 0 && course_format_uses_sections($course->format)) {
$sectionname = get_string('sectionname', "format_$course->format");
$sectiontitle = get_section_name($course, $section);
$PAGE->set_title(
get_string(
'coursesectiontitle',
'coursesectiontitle' . $editingtitle,
'moodle',
['course' => $course->fullname, 'sectiontitle' => $sectiontitle, 'sectionname' => $sectionname]
)
);
} else {
$PAGE->set_title(get_string('coursetitle', 'moodle', ['course' => $course->fullname]));
$PAGE->set_title(get_string('coursetitle' . $editingtitle, 'moodle', ['course' => $course->fullname]));
}
// Add bulk editing control.

View File

@ -29,6 +29,7 @@ $string['availability_hide_help'] = 'Not available to students.';
$string['availability_stealth'] = 'Make available but don\'t show on course page';
$string['availability_stealth_help'] = 'Available to students if you provide a link. Activities will still appear in the gradebook and other reports.';
$string['bulkedit'] = 'Bulk edit';
$string['bulkeditingcourse'] = 'Bulk edit course: {$a}';
$string['bulkcancel'] = 'Close bulk edit';
$string['bulkselection'] = '{$a} selected';
$string['bulkselection_plural'] = '{$a} selected';

View File

@ -418,7 +418,9 @@ $string['courserestore'] = 'Course restore';
$string['coursereuse'] = 'Course reuse';
$string['courses'] = 'Courses';
$string['coursesectionsummaries'] = 'Course section summaries';
$string['coursesectiontitle'] = 'Course: {$a->course}, {$a->sectionname}: {$a->sectiontitle}';
$string['coursesectiontitle'] = '{$a->sectionname}: {$a->sectiontitle} | {$a->course}';
$string['coursesectiontitlebulkediting'] = 'Bulk edit {$a->sectionname}: {$a->sectiontitle} | {$a->course}';
$string['coursesectiontitleediting'] = 'Edit {$a->sectionname}: {$a->sectiontitle} | {$a->course}';
$string['coursesettings'] = 'Course default settings';
$string['coursesmovedout'] = 'Courses moved out from {$a}';
$string['coursespending'] = 'Courses pending approval';
@ -432,6 +434,8 @@ $string['coursestart'] = 'Course start';
$string['coursesummary'] = 'Course summary';
$string['coursesummary_help'] = 'A short description of your course. The content you add here is searchable.';
$string['coursetitle'] = 'Course: {$a->course}';
$string['coursetitlebulkediting'] = 'Bulk edit course: {$a->course}';
$string['coursetitleediting'] = 'Edit course: {$a->course}';
$string['courseupdates'] = 'Course updates';
$string['coursevisibility'] = 'Course visibility';
$string['coursevisibility_help'] = '* Show: The course appears in the list of courses and students can access it.