| Línea 23... | 
            Línea 23... | 
          
          
            | 23 | 
             * @copyright  2016 Ryan Wyllie <ryan@moodle.com>
  | 
            23 | 
             * @copyright  2016 Ryan Wyllie <ryan@moodle.com>
  | 
          
          
            | 24 | 
             * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
            24 | 
             * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
          
          
            | 25 | 
             */
  | 
            25 | 
             */
  | 
          
          
            | 26 | 
            define(['jquery', 'core/ajax', 'core/templates', 'core/str', 'core/url',
  | 
            26 | 
            define(['jquery', 'core/ajax', 'core/templates', 'core/str', 'core/url',
  | 
          
          
            | 27 | 
                        'core/notification', 'core/custom_interaction_events', 'core/popover_region_controller',
  | 
            27 | 
                        'core/notification', 'core/custom_interaction_events', 'core/popover_region_controller',
  | 
          
          
            | 28 | 
                        'message_popup/notification_repository', 'message_popup/notification_area_events'],
  | 
            28 | 
                        'message_popup/notification_repository', 'message_popup/notification_area_events',
  | 
          
          
            | - | 
               | 
            29 | 
                        'core/local/aria/focuslock',
  | 
          
          
            | - | 
               | 
            30 | 
                    ],
  | 
          
          
            | 29 | 
                    function($, Ajax, Templates, Str, URL, DebugNotification, CustomEvents,
  | 
            31 | 
                    function($, Ajax, Templates, Str, URL, DebugNotification, CustomEvents,
  | 
          
          
            | 30 | 
                        PopoverController, NotificationRepo, NotificationAreaEvents) {
  | 
            32 | 
                        PopoverController, NotificationRepo, NotificationAreaEvents, FocusLock) {
  | 
          
          
            | Línea 31... | 
            Línea 33... | 
          
          
            | 31 | 
             
  | 
            33 | 
             
  | 
          
          
            | 32 | 
                var SELECTORS = {
  | 
            34 | 
                var SELECTORS = {
  | 
          
          
            | 33 | 
                    MARK_ALL_READ_BUTTON: '[data-action="mark-all-read"]',
  | 
            35 | 
                    MARK_ALL_READ_BUTTON: '[data-action="mark-all-read"]',
  | 
          
          
            | 34 | 
                    ALL_NOTIFICATIONS_CONTAINER: '[data-region="all-notifications"]',
  | 
            36 | 
                    ALL_NOTIFICATIONS_CONTAINER: '[data-region="all-notifications"]',
  | 
          
          
            | 35 | 
                    NOTIFICATION: '[data-region="notification-content-item-container"]',
  | 
            37 | 
                    NOTIFICATION: '[data-region="notification-content-item-container"]',
  | 
          
          
            | 36 | 
                    UNREAD_NOTIFICATION: '[data-region="notification-content-item-container"].unread',
  | 
            38 | 
                    UNREAD_NOTIFICATION: '[data-region="notification-content-item-container"].unread',
  | 
          
          
            | 37 | 
                    NOTIFICATION_LINK: '[data-action="content-item-link"]',
  | 
            39 | 
                    NOTIFICATION_LINK: '[data-action="content-item-link"]',
  | 
          
          
            | 38 | 
                    EMPTY_MESSAGE: '[data-region="empty-message"]',
  | 
            40 | 
                    EMPTY_MESSAGE: '[data-region="empty-message"]',
  | 
          
          
            | - | 
               | 
            41 | 
                    COUNT_CONTAINER: '[data-region="count-container"]',
  | 
          
          
            | - | 
               | 
            42 | 
                    NOTIFICATION_READ_FEEDBACK: '[data-region="notification-read-feedback"]',
  | 
          
          
            | 39 | 
                    COUNT_CONTAINER: '[data-region="count-container"]',
  | 
            43 | 
                    CLOSE_NOTIFICATION_POPOVER: '[data-action="close-notification-popover"]',
  | 
          
          
            | Línea 40... | 
            Línea 44... | 
          
          
            | 40 | 
                };
  | 
            44 | 
                };
  | 
          
          
            | 41 | 
             
  | 
            45 | 
             
  | 
          
          
            | 42 | 
                /**
  | 
            46 | 
                /**
  | 
          
          
            | Línea 311... | 
            Línea 315... | 
          
          
            | 311 | 
             
  | 
            315 | 
             
  | 
          
          
            | 312 | 
                    return NotificationRepo.markAllAsRead(request)
  | 
            316 | 
                    return NotificationRepo.markAllAsRead(request)
  | 
          
          
            | 313 | 
                        .then(function() {
  | 
            317 | 
                        .then(function() {
  | 
          
          
            | 314 | 
                            this.unreadCount = 0;
  | 
            318 | 
                            this.unreadCount = 0;
  | 
          
          
            | - | 
               | 
            319 | 
                            this.root.find(SELECTORS.UNREAD_NOTIFICATION).removeClass('unread');
  | 
          
          
            | - | 
               | 
            320 | 
             
  | 
          
          
            | - | 
               | 
            321 | 
                            // Set the ARIA live region's contents with the feedback.
  | 
          
          
            | - | 
               | 
            322 | 
                            const readFeedback = this.root.get(0).querySelector(SELECTORS.NOTIFICATION_READ_FEEDBACK);
  | 
          
          
            | - | 
               | 
            323 | 
                            Str.get_string('notificationsmarkedasread', 'message').done((notificationsmarkedasread) => {
  | 
          
          
            | - | 
               | 
            324 | 
                                readFeedback.innerHTML = notificationsmarkedasread;
  | 
          
          
            | 315 | 
                            this.root.find(SELECTORS.UNREAD_NOTIFICATION).removeClass('unread');
  | 
            325 | 
                            });
  | 
          
          
            | 316 | 
                        }.bind(this))
  | 
            326 | 
                        }.bind(this))
  | 
          
          
            | 317 | 
                        .always(function() {
  | 
            327 | 
                        .always(function() {
  | 
          
          
            | 318 | 
                            this.markAllReadButton.removeClass('loading');
  | 
            328 | 
                            this.markAllReadButton.removeClass('loading');
  | 
          
          
            | 319 | 
                        }.bind(this));
  | 
            329 | 
                        }.bind(this));
  | 
          
          
            | Línea 329... | 
            Línea 339... | 
          
          
            | 329 | 
                        CustomEvents.events.activate,
  | 
            339 | 
                        CustomEvents.events.activate,
  | 
          
          
            | 330 | 
                    ]);
  | 
            340 | 
                    ]);
  | 
          
          
            | Línea 331... | 
            Línea 341... | 
          
          
            | 331 | 
             
  | 
            341 | 
             
  | 
          
          
            | 332 | 
                    // Mark all notifications read if the user activates the mark all as read button.
  | 
            342 | 
                    // Mark all notifications read if the user activates the mark all as read button.
  | 
          
          
            | - | 
               | 
            343 | 
                    this.root.on(CustomEvents.events.activate, SELECTORS.MARK_ALL_READ_BUTTON, function(e, data) {
  | 
          
          
            | 333 | 
                    this.root.on(CustomEvents.events.activate, SELECTORS.MARK_ALL_READ_BUTTON, function(e, data) {
  | 
            344 | 
                        if (this.unreadCount > 0) {
  | 
          
          
            | - | 
               | 
            345 | 
                            this.markAllAsRead();
  | 
          
          
            | - | 
               | 
            346 | 
                        }
  | 
          
          
            | 334 | 
                        this.markAllAsRead();
  | 
            347 | 
             
  | 
          
          
            | 335 | 
                        e.stopPropagation();
  | 
            348 | 
                        e.stopPropagation();
  | 
          
          
            | 336 | 
                        data.originalEvent.preventDefault();
  | 
            349 | 
                        data.originalEvent.preventDefault();
  | 
          
          
            | Línea 337... | 
            Línea 350... | 
          
          
            | 337 | 
                    }.bind(this));
  | 
            350 | 
                    }.bind(this));
  | 
          
          
            | Línea 346... | 
            Línea 359... | 
          
          
            | 346 | 
                        }
  | 
            359 | 
                        }
  | 
          
          
            | Línea 347... | 
            Línea 360... | 
          
          
            | 347 | 
             
  | 
            360 | 
             
  | 
          
          
            | 348 | 
                        e.stopPropagation();
  | 
            361 | 
                        e.stopPropagation();
  | 
          
          
            | Línea -... | 
            Línea 362... | 
          
          
            | - | 
               | 
            362 | 
                    }.bind(this));
  | 
          
          
            | - | 
               | 
            363 | 
             
  | 
          
          
            | - | 
               | 
            364 | 
                    this.root.on(CustomEvents.events.activate, SELECTORS.CLOSE_NOTIFICATION_POPOVER, function(e) {
  | 
          
          
            | - | 
               | 
            365 | 
                        e.preventDefault();
  | 
          
          
            | - | 
               | 
            366 | 
                        $(this.root).trigger(CustomEvents.events.escape);
  | 
          
          
            | - | 
               | 
            367 | 
                        e.stopPropagation();
  | 
          
          
            | 349 | 
                    }.bind(this));
  | 
            368 | 
                    }.bind(this));
  | 
          
          
            | 350 | 
             
  | 
            369 | 
             
  | 
          
          
            | 351 | 
                    // Update the notification information when the menu is opened.
  | 
            370 | 
                    // Update the notification information when the menu is opened.
  | 
          
          
            | 352 | 
                    this.root.on(this.events().menuOpened, function() {
  | 
            371 | 
                    this.root.on(this.events().menuOpened, function() {
  | 
          
          
            | Línea 353... | 
            Línea 372... | 
          
          
            | 353 | 
                        this.hideUnreadCount();
  | 
            372 | 
                        this.hideUnreadCount();
  | 
          
          
            | 354 | 
                        this.updateButtonAriaLabel();
  | 
            373 | 
                        this.updateButtonAriaLabel();
  | 
          
          
            | 355 | 
             
  | 
            374 | 
             
  | 
          
          
            | - | 
               | 
            375 | 
                        if (!this.hasDoneInitialLoad()) {
  | 
          
          
            | - | 
               | 
            376 | 
                            this.loadMoreNotifications();
  | 
          
          
            | - | 
               | 
            377 | 
                        }
  | 
          
          
            | - | 
               | 
            378 | 
             
  | 
          
          
            | - | 
               | 
            379 | 
                        // Lock focus to the popover when it is opened, it is the parent of the container.
  | 
          
          
            | 356 | 
                        if (!this.hasDoneInitialLoad()) {
  | 
            380 | 
                        const contentContainer = this.getContentContainer()[0].parentNode;
  | 
          
          
            | Línea 357... | 
            Línea 381... | 
          
          
            | 357 | 
                            this.loadMoreNotifications();
  | 
            381 | 
                        FocusLock.trapFocus(contentContainer);
  | 
          
          
            | 358 | 
                        }
  | 
            382 | 
             
  | 
          
          
            | 359 | 
                    }.bind(this));
  | 
            383 | 
                    }.bind(this));
  | 
          
          
            | 360 | 
             
  | 
            384 | 
             
  | 
          
          
            | - | 
               | 
            385 | 
                    // Update the unread notification count when the menu is closed.
  | 
          
          
            | - | 
               | 
            386 | 
                    this.root.on(this.events().menuClosed, function() {
  | 
          
          
            | 361 | 
                    // Update the unread notification count when the menu is closed.
  | 
            387 | 
                        this.renderUnreadCount();
  | 
          
          
            | Línea 362... | 
            Línea 388... | 
          
          
            | 362 | 
                    this.root.on(this.events().menuClosed, function() {
  | 
            388 | 
                        this.updateButtonAriaLabel();
  | 
          
          
            | 363 | 
                        this.renderUnreadCount();
  | 
            389 | 
                        // Lock focus to the popover when it is opened, it is the parent of the container.
  | 
          
          
            | 364 | 
                        this.updateButtonAriaLabel();
  | 
            390 | 
                        FocusLock.untrapFocus();
  |