Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 35... Línea 35...
35
    create() {
35
    create() {
36
        // Optional component name for debugging.
36
        // Optional component name for debugging.
37
        this.name = 'content_section';
37
        this.name = 'content_section';
38
        // Default query selectors.
38
        // Default query selectors.
39
        this.selectors = {
39
        this.selectors = {
-
 
40
            ACTIONMENU: '.section-actions',
40
            SECTION_ITEM: `[data-for='section_title']`,
41
            SECTION_ITEM: `[data-for='section_title']`,
41
            CM: `[data-for="cmitem"]`,
42
            CM: `[data-for="cmitem"]`,
42
            SECTIONINFO: `[data-for="sectioninfo"]`,
43
            SECTIONINFO: `[data-for="sectioninfo"]`,
43
            SECTIONBADGES: `[data-region="sectionbadges"]`,
44
            SECTIONBADGES: `[data-region="sectionbadges"]`,
44
            SHOWSECTION: `[data-action="sectionShow"]`,
45
            SHOWSECTION: `[data-action="sectionShow"]`,
Línea 91... Línea 92...
91
        if (!pageCmInfo || pageCmInfo.sectionid !== this.id) {
92
        if (!pageCmInfo || pageCmInfo.sectionid !== this.id) {
92
            return;
93
            return;
93
        }
94
        }
94
        await this.reactive.dispatch('sectionContentCollapsed', [this.id], false);
95
        await this.reactive.dispatch('sectionContentCollapsed', [this.id], false);
95
        const pendingOpen = new Pending(`courseformat/section:openSectionIfNecessary`);
96
        const pendingOpen = new Pending(`courseformat/section:openSectionIfNecessary`);
96
        this.element.scrollIntoView({block: "center"});
-
 
97
        setTimeout(() => {
97
        setTimeout(() => {
-
 
98
            document.querySelector("#" + pageCmInfo.anchor).scrollIntoView();
98
            this.reactive.dispatch('setPageItem', 'cm', pageCmInfo.id);
99
            this.reactive.dispatch('setPageItem', 'cm', pageCmInfo.id);
99
            pendingOpen.resolve();
100
            pendingOpen.resolve();
100
        }, 250);
101
        }, 250);
101
    }
102
    }
Línea 117... Línea 118...
117
     * @param {Object} dropdata the exported drop data.
118
     * @param {Object} dropdata the exported drop data.
118
     * @returns {boolean}
119
     * @returns {boolean}
119
     */
120
     */
120
    validateDropData(dropdata) {
121
    validateDropData(dropdata) {
121
        // If the format uses one section per page sections dropping in the content is ignored.
122
        // If the format uses one section per page sections dropping in the content is ignored.
122
       if (dropdata?.type === 'section' && this.reactive.sectionReturn !== null) {
123
        if (dropdata?.type === 'section' && (this.reactive?.sectionReturn ?? this.reactive?.pageSectionId) !== null) {
123
            return false;
124
            return false;
124
        }
125
        }
125
        return super.validateDropData(dropdata);
126
        return super.validateDropData(dropdata);
126
    }
127
    }
Línea 134... Línea 135...
134
        const cms = this.getElements(this.selectors.CM);
135
        const cms = this.getElements(this.selectors.CM);
135
        // DndUpload may add extra elements so :last-child selector cannot be used.
136
        // DndUpload may add extra elements so :last-child selector cannot be used.
136
        if (!cms || cms.length === 0) {
137
        if (!cms || cms.length === 0) {
137
            return null;
138
            return null;
138
        }
139
        }
139
        return cms[cms.length - 1];
140
        const lastCm = cms[cms.length - 1];
-
 
141
        // If it is a delegated section return the last item overall.
-
 
142
        if (this.section.component !== null) {
-
 
143
            return lastCm;
-
 
144
        }
-
 
145
        // If it is a regular section and the last item overall has a parent cm, return the parent instead.
-
 
146
        const parentSection = lastCm.parentNode.closest(this.selectors.CM);
-
 
147
        return parentSection ?? lastCm;
-
 
148
    }
-
 
149
 
-
 
150
    /**
-
 
151
     * Get a fallback element when there is no CM in the section.
-
 
152
     *
-
 
153
     * @returns {element|null} the las course module element of the section.
-
 
154
     */
-
 
155
    getLastCmFallback() {
-
 
156
        // The sectioninfo is always present, even when the section is empty.
-
 
157
        return this.getElement(this.selectors.SECTIONINFO);
140
    }
158
    }
Línea 141... Línea 159...
141
 
159
 
142
    /**
160
    /**
143
     * Update a content section using the state information.
161
     * Update a content section using the state information.
Línea 189... Línea 207...
189
        } else {
207
        } else {
190
            selector = this.selectors.HIDESECTION;
208
            selector = this.selectors.HIDESECTION;
191
            newAction = 'sectionShow';
209
            newAction = 'sectionShow';
192
        }
210
        }
193
        // Find the affected action.
211
        // Find the affected action.
194
        const affectedAction = this.getElement(selector);
212
        const affectedAction = this._getActionMenu(selector);
195
        if (!affectedAction) {
213
        if (!affectedAction) {
196
            return;
214
            return;
197
        }
215
        }
198
        // Change action.
216
        // Change action.
199
        affectedAction.dataset.action = newAction;
217
        affectedAction.dataset.action = newAction;
Línea 214... Línea 232...
214
                const pixHtml = await Templates.renderPix(newIcon, 'core');
232
                const pixHtml = await Templates.renderPix(newIcon, 'core');
215
                Templates.replaceNode(icon, pixHtml, '');
233
                Templates.replaceNode(icon, pixHtml, '');
216
            }
234
            }
217
        }
235
        }
218
    }
236
    }
-
 
237
 
-
 
238
    /**
-
 
239
     * Get the action menu element from the selector.
-
 
240
     *
-
 
241
     * @param {string} selector The selector to find the action menu.
-
 
242
     * @returns The action menu element.
-
 
243
     */
-
 
244
    _getActionMenu(selector) {
-
 
245
        return document.querySelector(`${this.selectors.ACTIONMENU}[data-sectionid='${this.id}'] ${selector}`);
-
 
246
    }
219
}
247
}