2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
|
|
|
* Single notification item widget for echo popup.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends mw.echo.ui.NotificationItemWidget
|
2024-04-30 14:21:54 +00:00
|
|
|
* @mixes OO.ui.mixin.PendingElement
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {mw.echo.Controller} controller Echo notifications controller
|
|
|
|
* @param {mw.echo.dm.NotificationItem} model Notification item model
|
|
|
|
* @param {Object} [config] Configuration object
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {jQuery} [config.$overlay] A jQuery element functioning as an overlay
|
2016-04-10 13:31:02 +00:00
|
|
|
* for popups.
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {boolean} [config.bundle=false] This notification is part of a bundle
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.SingleNotificationItemWidget = function MwEchoUiSingleNotificationItemWidget( controller, model, config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.SingleNotificationItemWidget.super.call( this, controller, model, config );
|
2016-04-10 13:31:02 +00:00
|
|
|
// Mixin constructors
|
|
|
|
OO.ui.mixin.PendingElement.call( this, config );
|
|
|
|
|
|
|
|
this.controller = controller;
|
|
|
|
this.model = model;
|
|
|
|
|
|
|
|
this.bundle = !!config.bundle;
|
|
|
|
this.$overlay = config.$overlay || this.$element;
|
|
|
|
|
|
|
|
// Toggle 'mark as read' functionality
|
2016-06-10 13:06:04 +00:00
|
|
|
this.toggleMarkAsReadButtons( !this.model.isRead() );
|
2016-04-10 13:31:02 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.model.connect( this, { update: 'updateDataFromModel' } );
|
|
|
|
|
|
|
|
// Update read and seen states from the model
|
|
|
|
this.updateDataFromModel();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.ui.SingleNotificationItemWidget, mw.echo.ui.NotificationItemWidget );
|
|
|
|
OO.mixinClass( mw.echo.ui.SingleNotificationItemWidget, OO.ui.mixin.PendingElement );
|
|
|
|
|
|
|
|
/* Methods */
|
2016-06-03 18:47:13 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
mw.echo.ui.SingleNotificationItemWidget.prototype.markRead = function ( isRead ) {
|
2016-07-04 14:00:59 +00:00
|
|
|
isRead = isRead !== undefined ? !!isRead : true;
|
2016-06-03 18:47:13 +00:00
|
|
|
|
2016-07-04 14:00:59 +00:00
|
|
|
if ( this.model.isForeign() ) {
|
|
|
|
this.controller.markCrossWikiItemsRead( this.model.getId(), this.model.getSource() );
|
|
|
|
} else {
|
|
|
|
this.controller.markItemsRead( this.model.getId(), this.model.getModelName(), isRead );
|
|
|
|
}
|
2016-06-03 18:47:13 +00:00
|
|
|
};
|
|
|
|
|
2016-04-10 13:31:02 +00:00
|
|
|
/**
|
2016-08-15 23:53:09 +00:00
|
|
|
* Extend 'toggleRead' to emit sortChange so the item can be sorted
|
|
|
|
* when its read state was updated
|
2016-04-10 13:31:02 +00:00
|
|
|
*
|
2016-11-18 21:16:43 +00:00
|
|
|
* @inheritdoc
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires OO.EventEmitter#sortChange
|
2016-04-10 13:31:02 +00:00
|
|
|
*/
|
2016-08-15 23:53:09 +00:00
|
|
|
mw.echo.ui.SingleNotificationItemWidget.prototype.toggleRead = function ( read ) {
|
2024-06-03 12:22:48 +00:00
|
|
|
const oldState = this.read;
|
2016-08-15 23:53:09 +00:00
|
|
|
|
2018-05-22 14:56:46 +00:00
|
|
|
// Parent method
|
|
|
|
mw.echo.ui.SingleNotificationItemWidget.super.prototype.toggleRead.call( this, read );
|
2016-08-15 23:53:09 +00:00
|
|
|
|
|
|
|
if ( oldState !== read ) {
|
|
|
|
this.emit( 'sortChange' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update item state when the item model changes.
|
|
|
|
*/
|
2016-04-10 13:31:02 +00:00
|
|
|
mw.echo.ui.SingleNotificationItemWidget.prototype.updateDataFromModel = function () {
|
|
|
|
this.toggleRead( this.model.isRead() );
|
|
|
|
this.toggleSeen( this.model.isSeen() );
|
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|