Debian Codegraph @

extensions/Echo/modules/ui/mw.echo.ui.SingleNotificationItemWidget.js

raw symbols SCIP
1 ( function () {
2 /**
3 * Single notification item widget for echo popup.
4 *
5 * @class
6 * @extends mw.echo.ui.NotificationItemWidget
7 * @mixes OO.ui.mixin.PendingElement
8 *
9 * @constructor
10 * @param {mw.echo.Controller} controller Echo notifications controller
11 * @param {mw.echo.dm.NotificationItem} model Notification item model
12 * @param {Object} [config] Configuration object
13 * @param {jQuery} [config.$overlay] A jQuery element functioning as an overlay
14 * for popups.
15 * @param {boolean} [config.bundle=false] This notification is part of a bundle
16 */
17 mw.echo.ui.SingleNotificationItemWidget = function MwEchoUiSingleNotificationItemWidget( controller, model, config ) {
18 config = config || {};
19
20 // Parent constructor
21 mw.echo.ui.SingleNotificationItemWidget.super.call( this, controller, model, config );
22 // Mixin constructors
23 OO.ui.mixin.PendingElement.call( this, config );
24
25 this.controller = controller;
26 this.model = model;
27
28 this.bundle = !!config.bundle;
29 this.$overlay = config.$overlay || this.$element;
30
31 // Toggle 'mark as read' functionality
32 this.toggleMarkAsReadButtons( !this.model.isRead() );
33
34 // Events
35 this.model.connect( this, { update: 'updateDataFromModel' } );
36
37 // Update read and seen states from the model
38 this.updateDataFromModel();
39 };
40
41 /* Initialization */
42
43 OO.inheritClass( mw.echo.ui.SingleNotificationItemWidget, mw.echo.ui.NotificationItemWidget );
44 OO.mixinClass( mw.echo.ui.SingleNotificationItemWidget, OO.ui.mixin.PendingElement );
45
46 /* Methods */
47 /**
48 * @inheritdoc
49 */
50 mw.echo.ui.SingleNotificationItemWidget.prototype.markRead = function ( isRead ) {
51 isRead = isRead !== undefined ? !!isRead : true;
52
53 if ( this.model.isForeign() ) {
54 this.controller.markCrossWikiItemsRead( this.model.getId(), this.model.getSource() );
55 } else {
56 this.controller.markItemsRead( this.model.getId(), this.model.getModelName(), isRead );
57 }
58 };
59
60 /**
61 * Extend 'toggleRead' to emit sortChange so the item can be sorted
62 * when its read state was updated
63 *
64 * @inheritdoc
65 * @fires OO.EventEmitter#sortChange
66 */
67 mw.echo.ui.SingleNotificationItemWidget.prototype.toggleRead = function ( read ) {
68 const oldState = this.read;
69
70 // Parent method
71 mw.echo.ui.SingleNotificationItemWidget.super.prototype.toggleRead.call( this, read );
72
73 if ( oldState !== read ) {
74 this.emit( 'sortChange' );
75 }
76 };
77
78 /**
79 * Update item state when the item model changes.
80 */
81 mw.echo.ui.SingleNotificationItemWidget.prototype.updateDataFromModel = function () {
82 this.toggleRead( this.model.isRead() );
83 this.toggleSeen( this.model.isSeen() );
84 };
85 }() );