Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 44... Línea 44...
44
 
44
 
45
    /** @property {boolean} isBulkActionsModeEnabled Whether the bulk actions mode is enabled. */
45
    /** @property {boolean} isBulkActionsModeEnabled Whether the bulk actions mode is enabled. */
Línea 46... Línea 46...
46
    isBulkActionsModeEnabled = false;
46
    isBulkActionsModeEnabled = false;
-
 
47
 
-
 
48
    /**
-
 
49
     * @property {int} maxButtons Sets the maximum number of action buttons to display. If exceeded, additional actions
-
 
50
     *                            are shown in a dropdown menu.
-
 
51
     */
-
 
52
    maxButtons = 5;
47
 
53
 
48
    /**
54
    /**
-
 
55
     * The class constructor.
-
 
56
     *
49
     * The class constructor.
57
     * @param {int|null} maxButtons Sets the maximum number of action buttons to display. If exceeded, additional actions
50
     *
58
     *                              are shown in a dropdown menu.
51
     * @returns {void}
59
     * @returns {void}
52
     */
60
     */
53
    constructor() {
61
    constructor(maxButtons = null) {
54
        if (!this.getStickyFooterContainer()) {
62
        if (!this.getStickyFooterContainer()) {
55
            throw new Error('Sticky footer not found.');
63
            throw new Error('Sticky footer not found.');
56
        }
64
        }
57
        // Store any pre-existing content in the sticky footer. When bulk actions mode is enabled, this content will be
65
        // Store any pre-existing content in the sticky footer. When bulk actions mode is enabled, this content will be
-
 
66
        // replaced with the bulk actions content and restored when bulk actions mode is disabled.
-
 
67
        this.initialStickyFooterContent = this.getStickyFooterContainer().innerHTML;
-
 
68
        if (maxButtons) {
58
        // replaced with the bulk actions content and restored when bulk actions mode is disabled.
69
            this.maxButtons = maxButtons;
59
        this.initialStickyFooterContent = this.getStickyFooterContainer().innerHTML;
70
        }
60
        // Register and handle the item select change event.
71
        // Register and handle the item select change event.
61
        this.registerItemSelectChangeEvent(async() => {
72
        this.registerItemSelectChangeEvent(async() => {
62
            this.selectedItems = this.getSelectedItems();
73
            this.selectedItems = this.getSelectedItems();
Línea 104... Línea 115...
104
    registerItemSelectChangeEvent(eventHandler) {
115
    registerItemSelectChangeEvent(eventHandler) {
105
        throw new Error(`registerItemSelectChangeEvent(${eventHandler}) must be implemented in ${this.constructor.name}`);
116
        throw new Error(`registerItemSelectChangeEvent(${eventHandler}) must be implemented in ${this.constructor.name}`);
106
    }
117
    }
Línea 107... Línea 118...
107
 
118
 
-
 
119
    /**
-
 
120
     * Defines the action for deselecting a selected item.
-
 
121
     *
-
 
122
     * The base bulk actions class supports deselecting all selected items but does not have knowledge of the type of the
-
 
123
     * selected element. Therefore, each subclass must explicitly define the action of resetting the attributes that
-
 
124
     * indicate a selected state.
-
 
125
     *
-
 
126
     * @method deselectItem
-
 
127
     * @param {HTMLElement} selectedItem The selected element.
-
 
128
     * @returns {void}
-
 
129
     */
-
 
130
    deselectItem(selectedItem) {
-
 
131
        throw new Error(`deselectItem(${selectedItem}) must be implemented in ${this.constructor.name}`);
-
 
132
    }
-
 
133
 
108
    /**
134
    /**
109
     * Returns the sticky footer container.
135
     * Returns the sticky footer container.
110
     *
136
     *
111
     * @method getStickyFooterContainer
137
     * @method getStickyFooterContainer
112
     * @returns {HTMLElement}
138
     * @returns {HTMLElement}
Línea 117... Línea 143...
117
 
143
 
118
    /**
144
    /**
119
     * Enables the bulk action mode.
145
     * Enables the bulk action mode.
120
     *
146
     *
121
     * @method enableBulkActionsMode
147
     * @method enableBulkActionsMode
122
     * @returns {Promise}
148
     * @returns {Promise<void>}
123
     */
149
     */
124
    async enableBulkActionsMode() {
150
    async enableBulkActionsMode() {
125
        // Make sure that the sticky footer is enabled.
151
        // Make sure that the sticky footer is enabled.
126
        enableStickyFooter();
152
        enableStickyFooter();
Línea 135... Línea 161...
135
            bulkAction.setSelectedItems(this.selectedItems);
161
            bulkAction.setSelectedItems(this.selectedItems);
136
        });
162
        });
137
        // Register the click listener event for the cancel bulk mode button.
163
        // Register the click listener event for the cancel bulk mode button.
138
        bulkModeContainer.addEventListener('click', (e) => {
164
        bulkModeContainer.addEventListener('click', (e) => {
139
            if (e.target.closest(Selectors.cancelBulkActionModeElement)) {
165
            if (e.target.closest(Selectors.cancelBulkActionModeElement)) {
140
                // Uncheck all selected items.
166
                // Deselect all selected items.
141
                this.selectedItems.forEach((item) => {
167
                this.selectedItems.forEach((item) => {
142
                    item.checked = false;
168
                    this.deselectItem(item);
143
                });
169
                });
144
                // Disable the bulk action mode.
170
                // Disable the bulk action mode.
145
                this.disableBulkActionsMode();
171
                this.disableBulkActionsMode();
146
            }
172
            }
147
        });
173
        });
148
        this.isBulkActionsModeEnabled = true;
174
        this.isBulkActionsModeEnabled = true;
-
 
175
 
-
 
176
        // Calling `renderBulkActions()` already renders the item selection count.
-
 
177
        // Because of this, screen readers will not announce the item selection count on first load given that aria-live regions
-
 
178
        // must be present in the DOM and have their contents changed before screen readers can announce their content.
-
 
179
        // So, we call `updateBulkItemSelection()` after a short delay to ensure that screen readers announce the item count.
-
 
180
        setTimeout(async() => {
-
 
181
            await this.updateBulkItemSelection();
-
 
182
        }, 300);
149
    }
183
    }
Línea 150... Línea 184...
150
 
184
 
151
    /**
185
    /**
152
     * Disables the bulk action mode.
186
     * Disables the bulk action mode.
Línea 166... Línea 200...
166
 
200
 
167
    /**
201
    /**
168
     * Renders the bulk actions content.
202
     * Renders the bulk actions content.
169
     *
203
     *
170
     * @method renderBulkActions
204
     * @method renderBulkActions
171
     * @returns {Promise}
205
     * @returns {Promise<string>}
172
     */
206
     */
173
    async renderBulkActions() {
207
    async renderBulkActions() {
174
        let data = {
208
        const data = {
175
            'bulkselectioncount': this.selectedItems.length,
209
            bulkselectioncount: this.selectedItems.length,
-
 
210
            actions: [],
-
 
211
            moreactions: [],
176
            'actions': []
212
            hasmoreactions: false,
-
 
213
        };
-
 
214
        const bulkActions = this.getBulkActions();
-
 
215
        const showMoreButton = bulkActions.length > this.maxButtons;
177
        };
216
 
-
 
217
        // Get all bulk actions and render them in order.
178
        // Render the bulk actions trigger element for each available bulk action.
218
        const actions = await Promise.all(
-
 
219
            bulkActions.map((bulkAction, index) =>
-
 
220
                bulkAction.renderBulkActionTrigger(
-
 
221
                    showMoreButton && (index >= this.maxButtons - 1),
-
 
222
                    index
-
 
223
                )
-
 
224
            )
-
 
225
        );
-
 
226
 
-
 
227
        // Separate rendered actions into data.actions and data.moreactions in the correct order.
-
 
228
        actions.forEach((actionTrigger, index) => {
-
 
229
            if (showMoreButton && (index >= this.maxButtons - 1)) {
-
 
230
                data.moreactions.push({'actiontrigger': actionTrigger});
179
        await Promise.all(this.getBulkActions().map(async(bulkAction) => {
231
            } else {
-
 
232
                data.actions.push({'actiontrigger': actionTrigger});
180
            data.actions.push({'actiontrigger': await bulkAction.renderBulkActionTrigger()});
233
            }
-
 
234
        });
-
 
235
 
Línea 181... Línea 236...
181
        }));
236
        data.hasmoreactions = data.moreactions.length > 0;
182
 
237
 
Línea 183... Línea 238...
183
        return Templates.render('core/bulkactions/bulk_actions', data);
238
        return Templates.render('core/bulkactions/bulk_actions', data);