@@ -40,6 +40,7 @@ class Section extends BaseComponent {
4040 this . selectors = {
4141 SECTION : `[data-for='section']` ,
4242 SECTION_NAVIGATION : `[data-for='section-nav']` ,
43+ SECTION_DIVIDER : `[data-for='section-divider']` ,
4344 SETMARKER : `[data-action="sectionHighlight"]` ,
4445 REMOVEMARKER : `[data-action="sectionUnhighlight"]` ,
4546 ACTIONTEXT : `.menu-action-text` ,
@@ -64,7 +65,8 @@ class Section extends BaseComponent {
6465 getWatchers ( ) {
6566 return [
6667 { watch : `section.current:updated` , handler : this . _refreshHighlight } ,
67- { watch : `section.number:updated` , handler : this . _reloadSectionNavigation } ,
68+ { watch : `section.number:updated` , handler : this . _reloadSectionDividerAndNavigation } ,
69+ { watch : `section.number:updated` , handler : this . _refreshSectionNumber } ,
6870 ] ;
6971 }
7072
@@ -110,10 +112,7 @@ class Section extends BaseComponent {
110112 }
111113
112114 /**
113- * Reload a course section contents.
114- *
115- * Section HTML is still strongly backend dependant.
116- * Some changes require to get a new version of the section.
115+ * Reload a course section navigation.
117116 *
118117 * @param {details } param0 the watcher details
119118 * @param {object } param0.element the state object
@@ -142,6 +141,69 @@ class Section extends BaseComponent {
142141 } ) ;
143142 }
144143 }
144+
145+ /**
146+ * Reload a course section divider.
147+ *
148+ * @param {details } param0 the watcher details
149+ * @param {object } param0.element the state object
150+ */
151+ _reloadSectionDivider ( { element} ) {
152+ const pendingReload = new Pending ( `format_ucl/section:reloadDivider_${ element . id } ` ) ;
153+ const sectiondivider = this . getElement ( this . selectors . SECTION_DIVIDER , element . id ) ;
154+
155+ if ( sectiondivider ) {
156+ const promise = Fragment . loadFragment (
157+ 'format_ucl' ,
158+ 'section_divider' ,
159+ Config . courseContextId ,
160+ {
161+ id : element . id ,
162+ courseid : Config . courseId ,
163+ }
164+ ) ;
165+ promise . then ( ( html , js ) => {
166+ Templates . replaceNode ( sectiondivider , html , js ) ;
167+ pendingReload . resolve ( ) ;
168+ } ) . catch ( ( ) => {
169+ pendingReload . resolve ( ) ;
170+ } ) ;
171+ }
172+ }
173+
174+ /**
175+ * Reload a course section divider and navigation.
176+ *
177+ * Called when a section has been moved
178+ *
179+ * @param {details } param0 the watcher details
180+ * @param {object } param0.element the state object
181+ */
182+ _reloadSectionDividerAndNavigation ( { element} ) {
183+ this . _reloadSectionDivider ( { element} ) ;
184+ this . _reloadSectionNavigation ( { element} ) ;
185+ }
186+
187+ /**
188+ * Update a course section when the section number changes.
189+ *
190+ * The courseActions module used for most course section tools still depends on css classes and
191+ * section numbers (not id). To prevent inconsistencies when a section is moved, we need to refresh
192+ * the sectionreturnnum
193+ *
194+ * @param {Object } param
195+ * @param {Object } param.element details the update details.
196+ */
197+ _refreshSectionNumber ( { element} ) {
198+ // Find the element.
199+ const target = this . getElement ( this . selectors . SECTION , element . id ) ;
200+ if ( ! target ) {
201+ // Job done. Nothing to refresh.
202+ return ;
203+ }
204+ // The data-sectionnumber is the attribute used by components to store the section number.
205+ target . dataset . sectionreturnnum = element . number ;
206+ }
145207}
146208
147209export const init = ( ) => {
0 commit comments