MDL-82720 core_courseformat: Allow easier overriding of format JS
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -6,6 +6,6 @@ define("core_courseformat/local/content/activity_header",["exports","core/reacti
|
||||
* @class core_courseformat/local/content/activity_header
|
||||
* @copyright 2021 Ferran Recio <ferran@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/(CourseEvents);const SELECTORS_ACTIVITY_HEADER="[data-for='page-activity-header']";class Component extends _reactive.BaseComponent{create(){this.name="activity_header"}static init(target,selectors){const elementselector=target||SELECTORS_ACTIVITY_HEADER;return new Component({element:document.querySelector(elementselector),reactive:(0,_courseeditor.getCurrentCourseEditor)(),selectors:selectors})}stateReady(){this.addEventListener(this.element,CourseEvents.manualCompletionToggled,this._completionHandler)}_completionHandler(_ref){let{detail:detail}=_ref;void 0!==detail&&this.reactive.dispatch("cmCompletion",[detail.cmid],detail.completed)}}return _exports.default=Component,_exports.default}));
|
||||
*/(CourseEvents);const SELECTORS_ACTIVITY_HEADER="[data-for='page-activity-header']";class Component extends _reactive.BaseComponent{create(){this.name="activity_header"}static init(target,selectors){const elementselector=target||SELECTORS_ACTIVITY_HEADER;return new this({element:document.querySelector(elementselector),reactive:(0,_courseeditor.getCurrentCourseEditor)(),selectors:selectors})}stateReady(){this.addEventListener(this.element,CourseEvents.manualCompletionToggled,this._completionHandler)}_completionHandler(_ref){let{detail:detail}=_ref;void 0!==detail&&this.reactive.dispatch("cmCompletion",[detail.cmid],detail.completed)}}return _exports.default=Component,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=activity_header.min.js.map
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"activity_header.min.js","sources":["../../../src/local/content/activity_header.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * The activity header component.\n *\n * @module core_courseformat/local/content/activity_header\n * @class core_courseformat/local/content/activity_header\n * @copyright 2021 Ferran Recio <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {BaseComponent} from 'core/reactive';\nimport {getCurrentCourseEditor} from 'core_courseformat/courseeditor';\nimport * as CourseEvents from 'core_course/events';\n\n// Global page selectors.\nconst SELECTORS = {\n ACTIVITY_HEADER: `[data-for='page-activity-header']`,\n};\n\nexport default class Component extends BaseComponent {\n\n /**\n * Constructor hook.\n */\n create() {\n // Optional component name for debugging.\n this.name = 'activity_header';\n }\n\n /**\n * Static method to create a component instance form the mustache template.\n *\n * @param {string} target optional altentative DOM main element CSS selector\n * @param {object} selectors optional css selector overrides\n * @return {Component}\n */\n static init(target, selectors) {\n const elementselector = (target) ? target : SELECTORS.ACTIVITY_HEADER;\n return new Component({\n element: document.querySelector(elementselector),\n reactive: getCurrentCourseEditor(),\n selectors\n });\n }\n\n /**\n * Initial state ready method.\n */\n stateReady() {\n // Capture completion events.\n this.addEventListener(\n this.element,\n CourseEvents.manualCompletionToggled,\n this._completionHandler\n );\n }\n\n /**\n * Activity manual completion listener.\n *\n * @param {Event} event the custom event\n * @param {object} event.detail the event details\n */\n _completionHandler({detail}) {\n if (detail === undefined) {\n return;\n }\n this.reactive.dispatch('cmCompletion', [detail.cmid], detail.completed);\n }\n}\n"],"names":["SELECTORS","Component","BaseComponent","create","name","target","selectors","elementselector","element","document","querySelector","reactive","stateReady","addEventListener","this","CourseEvents","manualCompletionToggled","_completionHandler","detail","undefined","dispatch","cmid","completed"],"mappings":";;;;;;;;0BA6BMA,oEAIeC,kBAAkBC,wBAKnCC,cAESC,KAAO,8BAUJC,OAAQC,iBACVC,gBAAmBF,QAAmBL,iCACrC,IAAIC,UAAU,CACjBO,QAASC,SAASC,cAAcH,iBAChCI,UAAU,0CACVL,UAAAA,YAORM,kBAESC,iBACDC,KAAKN,QACLO,aAAaC,wBACbF,KAAKG,oBAUbA,6BAAmBC,OAACA,kBACDC,IAAXD,aAGCP,SAASS,SAAS,eAAgB,CAACF,OAAOG,MAAOH,OAAOI"}
|
||||
{"version":3,"file":"activity_header.min.js","sources":["../../../src/local/content/activity_header.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * The activity header component.\n *\n * @module core_courseformat/local/content/activity_header\n * @class core_courseformat/local/content/activity_header\n * @copyright 2021 Ferran Recio <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {BaseComponent} from 'core/reactive';\nimport {getCurrentCourseEditor} from 'core_courseformat/courseeditor';\nimport * as CourseEvents from 'core_course/events';\n\n// Global page selectors.\nconst SELECTORS = {\n ACTIVITY_HEADER: `[data-for='page-activity-header']`,\n};\n\nexport default class Component extends BaseComponent {\n\n /**\n * Constructor hook.\n */\n create() {\n // Optional component name for debugging.\n this.name = 'activity_header';\n }\n\n /**\n * Static method to create a component instance form the mustache template.\n *\n * @param {string} target optional altentative DOM main element CSS selector\n * @param {object} selectors optional css selector overrides\n * @return {Component}\n */\n static init(target, selectors) {\n const elementselector = (target) ? target : SELECTORS.ACTIVITY_HEADER;\n return new this({\n element: document.querySelector(elementselector),\n reactive: getCurrentCourseEditor(),\n selectors\n });\n }\n\n /**\n * Initial state ready method.\n */\n stateReady() {\n // Capture completion events.\n this.addEventListener(\n this.element,\n CourseEvents.manualCompletionToggled,\n this._completionHandler\n );\n }\n\n /**\n * Activity manual completion listener.\n *\n * @param {Event} event the custom event\n * @param {object} event.detail the event details\n */\n _completionHandler({detail}) {\n if (detail === undefined) {\n return;\n }\n this.reactive.dispatch('cmCompletion', [detail.cmid], detail.completed);\n }\n}\n"],"names":["SELECTORS","Component","BaseComponent","create","name","target","selectors","elementselector","this","element","document","querySelector","reactive","stateReady","addEventListener","CourseEvents","manualCompletionToggled","_completionHandler","detail","undefined","dispatch","cmid","completed"],"mappings":";;;;;;;;0BA6BMA,oEAIeC,kBAAkBC,wBAKnCC,cAESC,KAAO,8BAUJC,OAAQC,iBACVC,gBAAmBF,QAAmBL,iCACrC,IAAIQ,KAAK,CACZC,QAASC,SAASC,cAAcJ,iBAChCK,UAAU,0CACVN,UAAAA,YAORO,kBAESC,iBACDN,KAAKC,QACLM,aAAaC,wBACbR,KAAKS,oBAUbA,6BAAmBC,OAACA,kBACDC,IAAXD,aAGCN,SAASQ,SAAS,eAAgB,CAACF,OAAOG,MAAOH,OAAOI"}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -6,6 +6,6 @@ define("core_courseformat/local/courseindex/placeholder",["exports","core/reacti
|
||||
* @class core_courseformat/local/courseindex/placeholder
|
||||
* @copyright 2021 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,_templates=_interopRequireDefault(_templates),_pending=_interopRequireDefault(_pending),_log=_interopRequireDefault(_log);class Component extends _reactive.BaseComponent{static init(target,selectors){let element=document.querySelector(target);return element||(_log.default.debug("Init component with id is deprecated, use a query selector instead."),element=document.getElementById(target)),new this({element:element,reactive:(0,_courseeditor.getCurrentCourseEditor)(),selectors:selectors})}create(){this.pendingContent=new _pending.default("core_courseformat/placeholder:loadcourseindex")}async stateReady(state){this.loadStaticContent()||await this.loadTemplateContent(state)}loadStaticContent(){const index=this.reactive.getStorageValue("courseIndex");return!(!index.html||!index.js)&&(_templates.default.replaceNode(this.element,index.html,index.js),this.pendingContent.resolve(),!0)}async loadTemplateContent(state){const data=this.reactive.getExporter().course(state);try{const{html:html,js:js}=await _templates.default.renderForPromise("core_courseformat/local/courseindex/courseindex",data);_templates.default.replaceNode(this.element,html,js),this.pendingContent.resolve(),this.reactive.setStorageValue("courseIndex",{html:html,js:js})}catch(error){throw this.pendingContent.resolve(error),error}}}return _exports.default=Component,_exports.default}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_templates=_interopRequireDefault(_templates),_pending=_interopRequireDefault(_pending),_log=_interopRequireDefault(_log);class Component extends _reactive.BaseComponent{static init(target,selectors){let element=document.querySelector(target);return element||(_log.default.debug("Init component with id is deprecated, use a query selector instead."),element=document.getElementById(target)),new this({element:element,reactive:(0,_courseeditor.getCurrentCourseEditor)(),selectors:selectors})}create(){this.pendingContent=new _pending.default("core_courseformat/placeholder:loadcourseindex")}async stateReady(state){this.loadStaticContent()||await this.loadTemplateContent(state)}loadStaticContent(){const index=this.reactive.getStorageValue("courseIndex");return!(!index.html||!index.js)&&(_templates.default.replaceNode(this.element,index.html,index.js),this.pendingContent.resolve(),!0)}async loadTemplateContent(state){const data=this.reactive.getExporter().course(state);try{const{html:html,js:js}=await this._renderCourseIndex(data);_templates.default.replaceNode(this.element,html,js),this.pendingContent.resolve(),this.reactive.setStorageValue("courseIndex",{html:html,js:js})}catch(error){throw this.pendingContent.resolve(error),error}}_renderCourseIndex(data){return _templates.default.renderForPromise("core_courseformat/local/courseindex/courseindex",data)}}return _exports.default=Component,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=placeholder.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -8,6 +8,6 @@ define("core_courseformat/local/courseindex/section",["exports","core_courseform
|
||||
* @class core_courseformat/local/courseindex/section
|
||||
* @copyright 2021 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,_sectiontitle=_interopRequireDefault(_sectiontitle),_dndsection=_interopRequireDefault(_dndsection),_log=_interopRequireDefault(_log);class Component extends _dndsection.default{create(){this.name="courseindex_section",this.selectors={SECTION:"[data-for='section']",SECTION_ITEM:"[data-for='section_item']",SECTION_TITLE:"[data-for='section_title']",CM_LAST:'[data-for="cm"]:last-child',DND_ALLOWED:"[data-courseindexdndallowed='true']"},this.classes={SECTIONHIDDEN:"dimmed",SECTIONCURRENT:"current",LOCKED:"editinprogress",RESTRICTIONS:"restrictions",PAGEITEM:"pageitem",OVERLAYBORDERS:"overlay-preview-borders"},this.id=this.element.dataset.id,this.isPageItem=!1}static init(target,selectors){let element=document.querySelector(target);return element||(_log.default.debug("Init component with id is deprecated, use a query selector instead."),element=document.getElementById(target)),new this({element:element,selectors:selectors})}stateReady(state){var _section$sectionurl;this.configState(state);const sectionItem=this.getElement(this.selectors.SECTION_ITEM);if(this.reactive.isEditing&&this.reactive.supportComponents&&document.querySelector(this.selectors.DND_ALLOWED)){const titleitem=new _sectiontitle.default({...this,element:sectionItem,fullregion:this.element});this.configDragDrop(titleitem)}const section=state.section.get(this.id);window.location.href==(null===(_section$sectionurl=section.sectionurl)||void 0===_section$sectionurl?void 0:_section$sectionurl.replace(/&/g,"&"))&&(this.reactive.dispatch("setPageItem","section",this.id),sectionItem.scrollIntoView())}getWatchers(){return[{watch:"section[".concat(this.id,"]:deleted"),handler:this.remove},{watch:"section[".concat(this.id,"]:updated"),handler:this._refreshSection},{watch:"course.pageItem:updated",handler:this._refreshPageItem}]}getLastCm(){return this.getElement(this.selectors.CM_LAST)}_refreshSection(_ref){var _element$hasrestricti,_element$dragging,_element$locked;let{element:element}=_ref;const sectionItem=this.getElement(this.selectors.SECTION_ITEM);sectionItem.classList.toggle(this.classes.SECTIONHIDDEN,!element.visible),sectionItem.classList.toggle(this.classes.RESTRICTIONS,null!==(_element$hasrestricti=element.hasrestrictions)&&void 0!==_element$hasrestricti&&_element$hasrestricti),this.element.classList.toggle(this.classes.SECTIONCURRENT,element.current),this.element.classList.toggle(this.classes.DRAGGING,null!==(_element$dragging=element.dragging)&&void 0!==_element$dragging&&_element$dragging),this.element.classList.toggle(this.classes.LOCKED,null!==(_element$locked=element.locked)&&void 0!==_element$locked&&_element$locked),this.locked=element.locked,this.getElement(this.selectors.SECTION_TITLE).innerHTML=element.title}_refreshPageItem(_ref2){var _element$pageItem,_this$pageItem;let{element:element,state:state}=_ref2;if(!element.pageItem)return;const containsPageItem=this._isPageItemInThisSection(element.pageItem);if(!containsPageItem||this._isParentSectionIndexCollapsed(state))return this.pageItem=!1,void this.getElement(this.selectors.SECTION_ITEM).classList.remove(this.classes.PAGEITEM);!state.section.get(this.id).indexcollapsed||null!==(_element$pageItem=element.pageItem)&&void 0!==_element$pageItem&&_element$pageItem.isStatic?this.pageItem="section"==element.pageItem.type&&element.pageItem.id==this.id:this.pageItem=containsPageItem;this.getElement(this.selectors.SECTION_ITEM).classList.toggle(this.classes.PAGEITEM,null!==(_this$pageItem=this.pageItem)&&void 0!==_this$pageItem&&_this$pageItem),this.pageItem&&!this.reactive.isEditing&&this.element.scrollIntoView({block:"nearest"})}_isPageItemInThisSection(pageItem){if(pageItem.sectionId==this.id)return!0;return!!this.element.querySelector("".concat(this.selectors.SECTION,'[data-id="').concat(pageItem.sectionId,'"]'))}_isParentSectionIndexCollapsed(state){const parentElement=this.element.parentElement.closest(this.selectors.SECTION);if(!parentElement||!parentElement.dataset.id)return null;return!!state.section.get(parentElement.dataset.id).indexcollapsed}async addOverlay(){this.element.classList.add(this.classes.OVERLAYBORDERS)}removeOverlay(){this.element.classList.remove(this.classes.OVERLAYBORDERS)}}return _exports.default=Component,_exports.default}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_sectiontitle=_interopRequireDefault(_sectiontitle),_dndsection=_interopRequireDefault(_dndsection),_log=_interopRequireDefault(_log);class Component extends _dndsection.default{create(){this.name="courseindex_section",this.selectors={SECTION:"[data-for='section']",SECTION_ITEM:"[data-for='section_item']",SECTION_TITLE:"[data-for='section_title']",CM_LAST:'[data-for="cm"]:last-child',DND_ALLOWED:"[data-courseindexdndallowed='true']"},this.classes={SECTIONHIDDEN:"dimmed",SECTIONCURRENT:"current",LOCKED:"editinprogress",RESTRICTIONS:"restrictions",PAGEITEM:"pageitem",OVERLAYBORDERS:"overlay-preview-borders"},this.id=this.element.dataset.id,this.isPageItem=!1}static init(target,selectors){let element=document.querySelector(target);return element||(_log.default.debug("Init component with id is deprecated, use a query selector instead."),element=document.getElementById(target)),new this({element:element,selectors:selectors})}stateReady(state){var _section$sectionurl;this.configState(state);const sectionItem=this.getElement(this.selectors.SECTION_ITEM);if(this.reactive.isEditing&&this.reactive.supportComponents&&document.querySelector(this.selectors.DND_ALLOWED)){const titleitem=this._newSectionTitle(sectionItem);this.configDragDrop(titleitem)}const section=state.section.get(this.id);window.location.href==(null===(_section$sectionurl=section.sectionurl)||void 0===_section$sectionurl?void 0:_section$sectionurl.replace(/&/g,"&"))&&(this.reactive.dispatch("setPageItem","section",this.id),sectionItem.scrollIntoView())}_newSectionTitle(sectionItem){return new _sectiontitle.default({...this,element:sectionItem,fullregion:this.element})}getWatchers(){return[{watch:"section[".concat(this.id,"]:deleted"),handler:this.remove},{watch:"section[".concat(this.id,"]:updated"),handler:this._refreshSection},{watch:"course.pageItem:updated",handler:this._refreshPageItem}]}getLastCm(){return this.getElement(this.selectors.CM_LAST)}_refreshSection(_ref){var _element$hasrestricti,_element$dragging,_element$locked;let{element:element}=_ref;const sectionItem=this.getElement(this.selectors.SECTION_ITEM);sectionItem.classList.toggle(this.classes.SECTIONHIDDEN,!element.visible),sectionItem.classList.toggle(this.classes.RESTRICTIONS,null!==(_element$hasrestricti=element.hasrestrictions)&&void 0!==_element$hasrestricti&&_element$hasrestricti),this.element.classList.toggle(this.classes.SECTIONCURRENT,element.current),this.element.classList.toggle(this.classes.DRAGGING,null!==(_element$dragging=element.dragging)&&void 0!==_element$dragging&&_element$dragging),this.element.classList.toggle(this.classes.LOCKED,null!==(_element$locked=element.locked)&&void 0!==_element$locked&&_element$locked),this.locked=element.locked,this.getElement(this.selectors.SECTION_TITLE).innerHTML=element.title}_refreshPageItem(_ref2){var _element$pageItem,_this$pageItem;let{element:element,state:state}=_ref2;if(!element.pageItem)return;const containsPageItem=this._isPageItemInThisSection(element.pageItem);if(!containsPageItem||this._isParentSectionIndexCollapsed(state))return this.pageItem=!1,void this.getElement(this.selectors.SECTION_ITEM).classList.remove(this.classes.PAGEITEM);!state.section.get(this.id).indexcollapsed||null!==(_element$pageItem=element.pageItem)&&void 0!==_element$pageItem&&_element$pageItem.isStatic?this.pageItem="section"==element.pageItem.type&&element.pageItem.id==this.id:this.pageItem=containsPageItem;this.getElement(this.selectors.SECTION_ITEM).classList.toggle(this.classes.PAGEITEM,null!==(_this$pageItem=this.pageItem)&&void 0!==_this$pageItem&&_this$pageItem),this.pageItem&&!this.reactive.isEditing&&this.element.scrollIntoView({block:"nearest"})}_isPageItemInThisSection(pageItem){if(pageItem.sectionId==this.id)return!0;return!!this.element.querySelector("".concat(this.selectors.SECTION,'[data-id="').concat(pageItem.sectionId,'"]'))}_isParentSectionIndexCollapsed(state){const parentElement=this.element.parentElement.closest(this.selectors.SECTION);if(!parentElement||!parentElement.dataset.id)return null;return!!state.section.get(parentElement.dataset.id).indexcollapsed}async addOverlay(){this.element.classList.add(this.classes.OVERLAYBORDERS)}removeOverlay(){this.element.classList.remove(this.classes.OVERLAYBORDERS)}}return _exports.default=Component,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=section.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -101,7 +101,7 @@ export default class Component extends BaseComponent {
|
||||
log.debug('Init component with id is deprecated, use a query selector instead.');
|
||||
element = document.getElementById(target);
|
||||
}
|
||||
return new Component({
|
||||
return new this({
|
||||
element,
|
||||
reactive: getCurrentCourseEditor(),
|
||||
selectors,
|
||||
@@ -527,21 +527,37 @@ export default class Component extends BaseComponent {
|
||||
this._scanIndex(
|
||||
this.selectors.SECTION,
|
||||
this.sections,
|
||||
(item) => {
|
||||
return new Section(item);
|
||||
}
|
||||
this._newSection
|
||||
);
|
||||
|
||||
// Find unindexed cms.
|
||||
this._scanIndex(
|
||||
this.selectors.CM,
|
||||
this.cms,
|
||||
(item) => {
|
||||
return new CmItem(item);
|
||||
}
|
||||
this._newCmItem
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Section object.
|
||||
*
|
||||
* @param {Object} item the constructor data
|
||||
* @return {Section} the new object
|
||||
*/
|
||||
_newSection(item) {
|
||||
return new Section(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new CM object.
|
||||
*
|
||||
* @param {Object} item the constructor data
|
||||
* @return {CmItem} the new object
|
||||
*/
|
||||
_newCmItem(item) {
|
||||
return new CmItem(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reindex a content (section or cm) of the course content.
|
||||
*
|
||||
|
||||
@@ -50,7 +50,7 @@ export default class Component extends BaseComponent {
|
||||
*/
|
||||
static init(target, selectors) {
|
||||
const elementselector = (target) ? target : SELECTORS.ACTIVITY_HEADER;
|
||||
return new Component({
|
||||
return new this({
|
||||
element: document.querySelector(elementselector),
|
||||
reactive: getCurrentCourseEditor(),
|
||||
selectors
|
||||
|
||||
@@ -73,17 +73,27 @@ export default class extends DndSection {
|
||||
const sectionItem = this.getElement(this.selectors.SECTION_ITEM);
|
||||
if (sectionItem) {
|
||||
// Init the inner dragable element.
|
||||
const headerComponent = new Header({
|
||||
...this,
|
||||
element: sectionItem,
|
||||
fullregion: this.element,
|
||||
});
|
||||
const headerComponent = this._newHeader(sectionItem);
|
||||
this.configDragDrop(headerComponent);
|
||||
}
|
||||
}
|
||||
this._openSectionIfNecessary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Header object.
|
||||
*
|
||||
* @param {Element} sectionItem the Header's element
|
||||
* @return {Header} the new object
|
||||
*/
|
||||
_newHeader(sectionItem) {
|
||||
return new Header({
|
||||
...this,
|
||||
element: sectionItem,
|
||||
fullregion: this.element,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the section if the anchored activity is inside.
|
||||
*/
|
||||
|
||||
@@ -266,13 +266,24 @@ export default class Component extends BaseComponent {
|
||||
const exporter = this.reactive.getExporter();
|
||||
const data = exporter.cm(state, element);
|
||||
// Create the new content.
|
||||
const newcomponent = await this.renderComponent(fakeelement, 'core_courseformat/local/courseindex/cm', data);
|
||||
const newcomponent = await this._renderCm(fakeelement, data);
|
||||
// Replace the fake node with the real content.
|
||||
const newelement = newcomponent.getElement();
|
||||
this.cms[element.id] = newelement;
|
||||
fakeelement.parentNode.replaceChild(newelement, fakeelement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a course index CM template.
|
||||
*
|
||||
* @param {Element} fakeelement fake node while the component is loading
|
||||
* @param {Object} data the render data
|
||||
* @return {Promise<BaseComponent>} the new object
|
||||
*/
|
||||
_renderCm(fakeelement, data) {
|
||||
return this.renderComponent(fakeelement, 'core_courseformat/local/courseindex/cm', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new section instance.
|
||||
*
|
||||
@@ -295,13 +306,24 @@ export default class Component extends BaseComponent {
|
||||
const exporter = this.reactive.getExporter();
|
||||
const data = exporter.section(state, element);
|
||||
// Create the new content.
|
||||
const newcomponent = await this.renderComponent(fakeelement, 'core_courseformat/local/courseindex/section', data);
|
||||
const newcomponent = await this._renderSection(fakeelement, data);
|
||||
// Replace the fake node with the real content.
|
||||
const newelement = newcomponent.getElement();
|
||||
this.sections[element.id] = newelement;
|
||||
fakeelement.parentNode.replaceChild(newelement, fakeelement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a course index section template.
|
||||
*
|
||||
* @param {Element} fakeelement fake node while the component is loading
|
||||
* @param {Object} data the render data
|
||||
* @return {Promise<BaseComponent>} the new object
|
||||
*/
|
||||
_renderSection(fakeelement, data) {
|
||||
return this.renderComponent(fakeelement, 'core_courseformat/local/courseindex/section', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh a section cm list.
|
||||
*
|
||||
|
||||
@@ -101,10 +101,7 @@ export default class Component extends BaseComponent {
|
||||
const data = exporter.course(state);
|
||||
try {
|
||||
// To render an HTML into our component we just use the regular Templates module.
|
||||
const {html, js} = await Templates.renderForPromise(
|
||||
'core_courseformat/local/courseindex/courseindex',
|
||||
data,
|
||||
);
|
||||
const {html, js} = await this._renderCourseIndex(data);
|
||||
Templates.replaceNode(this.element, html, js);
|
||||
this.pendingContent.resolve();
|
||||
|
||||
@@ -115,4 +112,17 @@ export default class Component extends BaseComponent {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the course index template.
|
||||
*
|
||||
* @param {Object} data the render data
|
||||
* @return {Promise<{html: string, js: string}>} the new HTML and JS
|
||||
*/
|
||||
_renderCourseIndex(data) {
|
||||
return Templates.renderForPromise(
|
||||
'core_courseformat/local/courseindex/courseindex',
|
||||
data,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,11 +90,7 @@ export default class Component extends DndSection {
|
||||
// Drag and drop is only available for components compatible course formats.
|
||||
if (this.reactive.isEditing && this.reactive.supportComponents && document.querySelector(this.selectors.DND_ALLOWED)) {
|
||||
// Init the inner dragable element passing the full section as affected region.
|
||||
const titleitem = new SectionTitle({
|
||||
...this,
|
||||
element: sectionItem,
|
||||
fullregion: this.element,
|
||||
});
|
||||
const titleitem = this._newSectionTitle(sectionItem);
|
||||
this.configDragDrop(titleitem);
|
||||
}
|
||||
// Check if the current url is the section url.
|
||||
@@ -106,6 +102,20 @@ export default class Component extends DndSection {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SectionTitle object.
|
||||
*
|
||||
* @param {Element} sectionItem the SectionTitle's element
|
||||
* @return {SectionTitle} the new object
|
||||
*/
|
||||
_newSectionTitle(sectionItem) {
|
||||
return new SectionTitle({
|
||||
...this,
|
||||
element: sectionItem,
|
||||
fullregion: this.element,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Component watchers.
|
||||
*
|
||||
|
||||
@@ -218,6 +218,7 @@
|
||||
{{/ core_courseformat/local/content/bulkedittools}}
|
||||
{{/bulkedittools}}
|
||||
</div>
|
||||
{{$ core_courseformat/local/content-js}}
|
||||
{{#js}}
|
||||
require(['core_courseformat/local/content'], function(component) {
|
||||
component.init(
|
||||
@@ -225,3 +226,4 @@ require(['core_courseformat/local/content'], function(component) {
|
||||
);
|
||||
});
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/content-js}}
|
||||
|
||||
@@ -32,8 +32,10 @@
|
||||
>
|
||||
{{#str}} bulkedit, core_courseformat {{/str}} {{#pix}} i/bulk_edit, core {{/pix}}
|
||||
</button>
|
||||
{{$ core_courseformat/local/content/bulkedittoggler-js}}
|
||||
{{#js}}
|
||||
require(['core_courseformat/local/content/bulkedittoggler'], function(component) {
|
||||
component.init('#bulk-enable-{{uniqid}}');
|
||||
});
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/content/bulkedittoggler-js}}
|
||||
|
||||
@@ -85,8 +85,10 @@
|
||||
</div>
|
||||
{{/ stickycontent }}
|
||||
{{/ core/sticky_footer }}
|
||||
{{$ core_courseformat/local/content/bulkedittools-js}}
|
||||
{{#js}}
|
||||
require(['core_courseformat/local/content/bulkedittools'], function(component) {
|
||||
component.init('[data-for="bulkedittools"]');
|
||||
});
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/content/bulkedittools-js}}
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{{$ core_courseformat/local/content/frontpagesection-js}}
|
||||
{{#js}}
|
||||
{{! The home page should be as fast as possible, we only load the editor when needed.}}
|
||||
{{#editing}}
|
||||
@@ -53,3 +54,4 @@ require(['core_courseformat/local/content'], function(component) {
|
||||
});
|
||||
{{/editing}}
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/content/frontpagesection-js}}
|
||||
|
||||
@@ -71,8 +71,10 @@
|
||||
{{/sectioninfo}}
|
||||
{{/hasdelegatedsection}}
|
||||
</li>
|
||||
{{$ core_courseformat/local/courseindex/cm-js}}
|
||||
{{#js}}
|
||||
require(['core_courseformat/local/courseindex/cm'], function(component) {
|
||||
component.init('#course-index-cm-{{id}}');
|
||||
});
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/courseindex/cm-js}}
|
||||
|
||||
@@ -104,8 +104,10 @@
|
||||
{{> core_courseformat/local/courseindex/section }}
|
||||
{{/sections}}
|
||||
</div>
|
||||
{{$ core_courseformat/local/courseindex/courseindex-js}}
|
||||
{{#js}}
|
||||
require(['core_courseformat/local/courseindex/courseindex'], function(component) {
|
||||
component.init('#course-index');
|
||||
});
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/courseindex/courseindex-js}}
|
||||
|
||||
@@ -30,8 +30,10 @@
|
||||
{{> core_courseformat/local/courseindex/placeholders }}
|
||||
</div>
|
||||
</nav>
|
||||
{{$ core_courseformat/local/courseindex/drawer-js}}
|
||||
{{#js}}
|
||||
require(['core_courseformat/local/courseindex/drawer'], function(component) {
|
||||
component.init('#courseindex');
|
||||
});
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/courseindex/drawer-js}}
|
||||
|
||||
@@ -50,8 +50,10 @@
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{{$ core_courseformat/local/courseindex/placeholders-js}}
|
||||
{{#js}}
|
||||
require(['core_courseformat/local/courseindex/placeholder'], function(component) {
|
||||
component.init('#course-index-placeholder');
|
||||
});
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/courseindex/placeholders-js}}
|
||||
|
||||
@@ -130,8 +130,10 @@
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{{$ core_courseformat/local/courseindex/section-js}}
|
||||
{{#js}}
|
||||
require(['core_courseformat/local/courseindex/section'], function(component) {
|
||||
component.init('#course-index-section-{{id}}');
|
||||
});
|
||||
{{/js}}
|
||||
{{/ core_courseformat/local/courseindex/section-js}}
|
||||
|
||||
Reference in New Issue
Block a user