Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 12... Línea 12...
12
//
12
//
13
// You should have received a copy of the GNU General Public License
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 15... Línea 15...
15
 
15
 
-
 
16
import $ from 'jquery';
16
import $ from 'jquery';
17
import Dropdown from 'theme_boost/bootstrap/dropdown';
17
import {debounce} from 'core/utils';
18
import {debounce} from 'core/utils';
-
 
19
import Pending from 'core/pending';
-
 
20
import {get_string as getString} from 'core/str';
Línea 18... Línea 21...
18
import Pending from 'core/pending';
21
 
19
 
22
 
20
/**
23
/**
21
 * The class that manages the state of the search within a combobox.
24
 * The class that manages the state of the search within a combobox.
Línea 27... Línea 30...
27
 
30
 
28
export default class {
31
export default class {
29
    // Define our standard lookups.
32
    // Define our standard lookups.
30
    selectors = {
33
    selectors = {
31
        component: this.componentSelector(),
34
        component: this.componentSelector(),
32
        toggle: '[data-toggle="dropdown"]',
35
        toggle: '[data-bs-toggle="dropdown"]',
33
        instance: '[data-region="instance"]',
36
        instance: '[data-region="instance"]',
34
        input: '[data-action="search"]',
37
        input: '[data-action="search"]',
35
        clearSearch: '[data-action="clearsearch"]',
38
        clearSearch: '[data-action="clearsearch"]',
36
        dropdown: this.dropdownSelector(),
39
        dropdown: this.dropdownSelector(),
Línea 258... Línea 261...
258
     *
261
     *
259
     * @param {Boolean} on Flag to toggle hiding or showing values.
262
     * @param {Boolean} on Flag to toggle hiding or showing values.
260
     */
263
     */
261
    toggleDropdown(on = false) {
264
    toggleDropdown(on = false) {
262
        if (on) {
265
        if (on) {
263
            $(this.toggle).dropdown('show');
266
            Dropdown.getOrCreateInstance(this.toggle).show();
264
        } else {
267
        } else {
265
            $(this.toggle).dropdown('hide');
268
            Dropdown.getOrCreateInstance(this.toggle).hide();
266
        }
269
        }
267
    }
270
    }
Línea 268... Línea 271...
268
 
271
 
269
    /**
272
    /**
Línea 328... Línea 331...
328
    async filterrenderpipe() {
331
    async filterrenderpipe() {
329
        this.updateNodes();
332
        this.updateNodes();
330
        this.setMatchedResults(await this.filterDataset(await this.getDataset()));
333
        this.setMatchedResults(await this.filterDataset(await this.getDataset()));
331
        this.filterMatchDataset();
334
        this.filterMatchDataset();
332
        await this.renderDropdown();
335
        await this.renderDropdown();
-
 
336
        await this.updateLiveRegion();
333
    }
337
    }
Línea 334... Línea 338...
334
 
338
 
335
    /**
339
    /**
336
     * A combo method to take the matching fields and render out the results.
340
     * A combo method to take the matching fields and render out the results.
Línea 343... Línea 347...
343
        await this.filterMatchDataset();
347
        await this.filterMatchDataset();
344
        // Replace the dropdown node contents and show the results.
348
        // Replace the dropdown node contents and show the results.
345
        await this.renderDropdown();
349
        await this.renderDropdown();
346
        // Set the dropdown to open.
350
        // Set the dropdown to open.
347
        this.toggleDropdown(true);
351
        this.toggleDropdown(true);
-
 
352
        await this.updateLiveRegion();
348
    }
353
    }
Línea 349... Línea 354...
349
 
354
 
350
    /**
355
    /**
351
     * The handler for when a user interacts with the component.
356
     * The handler for when a user interacts with the component.
Línea 378... Línea 383...
378
     */
383
     */
379
    // eslint-disable-next-line no-unused-vars
384
    // eslint-disable-next-line no-unused-vars
380
    changeHandler(e) {
385
    changeHandler(e) {
381
        // Components may override this method to do something.
386
        // Components may override this method to do something.
382
    }
387
    }
-
 
388
 
-
 
389
    /**
-
 
390
     * Updates the screen reader live region with the result count.
-
 
391
     */
-
 
392
    async updateLiveRegion() {
-
 
393
        if (!this.searchDropdown?.id) {
-
 
394
            return;
-
 
395
        }
-
 
396
 
-
 
397
        const idParts = this.searchDropdown.id.split('-');
-
 
398
 
-
 
399
        if (idParts.length < 3) {
-
 
400
            return;
-
 
401
        }
-
 
402
        const [, instanceId, id] = idParts; // E.g. dialog-12-34 only want the last two parts.
-
 
403
        const liveRegion = document.getElementById(`combobox-status-${instanceId}-${id}`);
-
 
404
 
-
 
405
        if (!liveRegion) {
-
 
406
            return;
-
 
407
        }
-
 
408
 
-
 
409
        const resultCount = this.getMatchedResults().length;
-
 
410
        let message;
-
 
411
        if (resultCount === 0) {
-
 
412
            message = await getString('noitemsfound', 'core');
-
 
413
        } else if (resultCount === 1) {
-
 
414
            message = await getString('oneitemfound', 'core');
-
 
415
        } else {
-
 
416
            message = await getString('multipleitemsfound', 'core', resultCount);
-
 
417
        }
-
 
418
 
-
 
419
        liveRegion.textContent = message;
-
 
420
 
-
 
421
        // Reset previous timeout if it exists.
-
 
422
        if (this.liveRegionTimeout) {
-
 
423
            clearTimeout(this.liveRegionTimeout);
-
 
424
        }
-
 
425
 
-
 
426
        // Clear the feedback message after 4 seconds. This is similar to the default timeout of toast messages
-
 
427
        // before disappearing from view. It is important to clear the message to prevent screen reader users from navigating
-
 
428
        // into this region and avoiding confusion.
-
 
429
        this.liveRegionTimeout = setTimeout(() => {
-
 
430
            liveRegion.textContent = '';
-
 
431
            this.liveRegionTimeout = null;
-
 
432
        }, 4000);
-
 
433
    }
-
 
434
 
383
}
435
}